1
1/27/09 CS 3343 Analysis of Algorithms 1
CS 3343 -- Spring 2009
Merge Sort
Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk
1/27/09 CS 3343 Analysis of Algorithms 2
Merge sort
MERGE-SORT A[1 . . n]
- 1. If n = 1, done.
- 2. Recursively sort A[ 1 . . n/2 ]
and A[ n/2+1 . . n ] .
- 3. “Merge” the 2 sorted lists.
Key subroutine: MERGE
1/27/09 CS 3343 Analysis of Algorithms 3
Merging two sorted arrays
20 13 7 2 12 11 9 1
1/27/09 CS 3343 Analysis of Algorithms 4