CS341 Lecture Notes - Merge Sort, Quicksort, Binary Search Algorithm

54 views8 pages

Document Summary

We are given a list of n elements. Split list into two lists each of length n/2: more precisely, one with length: the other: . n. Sort each list using merge sort (recursive call). Merge the sorted lists to get the final result. n. Let t(n) = number of comparisons to sort n items in the worst case. This is fine for our purposes, but in other settings it might not be (e. g. when writing a formal proof for publication). Solving recurrences: method 1: recursion trees, method 2: master theorem, method 3: guessing and checking method, we will study these in the next unit. For now, we solve the recurrence in an ad-hoc fashion. Simple merge sort analysis: a simple analysis gives us a good guess: T(n) < cn + 2t(n/2) < cn + 2{cn/2 + 2t(n/4)} < kcn + n t(1) (continuing) (in general) (when i is finally k) O(n log n) (since k = log n).

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

Related Questions