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

49 views14 pages

Document Summary

Solving recurrences: method 1: recursion trees, method 2: master theorem. Prove a general theorem covering a wide variety of recurrences. Apply the theorem in cookbook fashion: method 3: guessing and checking method. // base case: 1 element is always sorted if (l = r) then return; m := (l + r)/2; // we need to sort both subsequences lm, m+1r merge_sort(l, m); merge_sort(m + 1, r); // finally: merge the two sorted sequences merge(l, m, r); In the previous code we used a merge function: A[k] := l[i]; i := i + 1; k := k + 1; else. A[k] := r[j]; j := j + 1; k := k + 1; 1 we display the computation in the form of a tree (one node for each time the function is invoked). Label each node in the tree with the combine time cost incurred at that node. Leaves are labeled with base case cost t(0).

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions