Lecture 31 CSE 331 Nov 12, 2010
HW 8 due today I will not take any HW after 1:15pm Q1 in one pile and Q 2 in another I will not take any HW after 1:15pm
Graded HW 7 Individual pickups Atri: Fri office hours Jeff: Recitations and Wed office hours Alex: Tuesday and Thursday office hours
HW 9 Posted on the webpage/blog
Mergesort algorithm Input: a1, a2, …, an Output: Numbers in sorted order MergeSort( a, n ) If n = 1 return the order a1 aL = a1,…, a[n/2] aR = a[n/2]+1,…, an return MERGE ( MergeSort(aL, [n/2]), MergeSort(aR, n-[n/2]) ) If n = 2 return the order min(a1,a2); max(a1,a2)
Inductive step follows from correctness of MERGE Input: a1, a2, …, an Output: Numbers in sorted order By induction on n MergeSort( a, n ) If n = 2 return the order min(a1,a2); max(a1,a2) aL = a1,…, an/2 aR = an/2+1,…, an return MERGE ( MergeSort(aL, n/2), MergeSort(aR, n/2) ) Inductive step follows from correctness of MERGE
Today’s agenda Show that Mergesort runs in O(n log n) time Solve recurrences
HW 8 due today I will not take any HW after 1:15pm Q1 in one pile and Q 2 in another I will not take any HW after 1:15pm