Download presentation
Presentation is loading. Please wait.
1
Lecture 29 CSE 331 Nov 11, 2009
2
To be strictly enforced For the rest of the semester on Fridays SUBMIT your HOMEWORKS by 1:10 PM
3
Extra Q sessions next week Monday and Tuesday 4-6pm CSE 242
4
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) )
5
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) ) 151100192834 51119100 11951100 2843 2348 1234 81951100
6
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
7
Today’s agenda Show that Mergesort runs in O(n log n) time Solve recurrences
8
To be strictly enforced For the rest of the semester on Fridays SUBMIT your HOMEWORKS by 1:10 PM
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.