CS341 Lecture 2: 02-reduction-recurrence

38 views3 pages

Document Summary

Example: three sum well. asymptotical improvement first, before worrying about the coefficients. (note: in assig(cid:374)(cid:373)e(cid:374)ts a(cid:374)d e(cid:454)a(cid:373)s, (cid:455)ou"ll ha(cid:448)e to (cid:449)rite pseudo (cid:272)ode i(cid:374)stead of this (cid:271)rief des(cid:272)riptio(cid:374)). Two nested for loops to check each pair of i and j. (cid:4666)(cid:1866)(cid:2870)(cid:4667) Then for each (cid:1861), binary search for (cid:1865) [(cid:1861)]. (cid:4666)(cid:1866)log(cid:1866)(cid:4667) O (cid:455)ou"ll see (cid:373)ajor i(cid:373)pro(cid:448)e(cid:373)e(cid:374)t for larger (cid:1866), say, (cid:883)(cid:882)6. The coefficient does not matter as much now. In fact, one can change 0 to (cid:1865). But you can verify that our algorithm can be easily adjusted to do it as. Three nested loops to check each triplet (i, j, k). (cid:4666)(cid:1866)(cid:2871)(cid:4667) For each (cid:1863), use two sum to find [(cid:1861)]+[(cid:1862)]= [(cid:1863)]. (cid:4666)(cid:1866)(cid:2870)log(cid:1866)(cid:4667). Pre-sort to avoid sorting it for each (cid:1863). (cid:4666)(cid:1866)(cid:2870)log(cid:1866)(cid:4667) Use a better two sum algorithm on sorted array . (cid:4666)(cid:1866)(cid:2870)(cid:4667) Else if [(cid:1861)]+[(cid:1862)]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents