Lecture 29 CSE 331 Nov 11, 2009
To be strictly enforced For the rest of the semester on Fridays SUBMIT your HOMEWORKS by 1:10 PM
Extra Q sessions next week Monday and Tuesday 4-6pm CSE 242
Mergesort algorithm Input: a 1, a 2, …, a n Output: Numbers in sorted order MergeSort( a, n ) If n = 2 return the order min(a 1,a 2 ); max(a 1,a 2 ) a L = a 1,…, a n/2 a R = a n/2+1,…, a n return MERGE ( MergeSort(a L, n/2), MergeSort(a R, n/2) )
An example run MergeSort( a, n ) If n = 2 return the order min(a 1,a 2 ); max(a 1,a 2 ) a L = a 1,…, a n/2 a R = a n/2+1,…, a n return MERGE ( MergeSort(a L, n/2), MergeSort(a R, n/2) )
Correctness Input: a 1, a 2, …, a n Output: Numbers in sorted order MergeSort( a, n ) If n = 2 return the order min(a 1,a 2 ); max(a 1,a 2 ) a L = a 1,…, a n/2 a R = a n/2+1,…, a n return MERGE ( MergeSort(a L, n/2), MergeSort(a R, n/2) ) By induction on n Inductive step follows from correctness of MERGE
Today’s agenda Show that Mergesort runs in O(n log n) time Solve recurrences
To be strictly enforced For the rest of the semester on Fridays SUBMIT your HOMEWORKS by 1:10 PM