1 / 8

Lecture 29

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.

maitland
Download Presentation

Lecture 29

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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: a1, a2, …, an Output: Numbers in sorted order 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) )

  5. An example run 1 51 51 1 19 100 100 19 2 2 8 8 4 3 3 4 1 8 1 2 19 19 3 2 4 51 51 3 100 4 8 100 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) )

  6. Correctness 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

  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

More Related