mergesort-102-sp10

mergesort-102-sp10 - MergeSort Source: Gibbs & Tamassia...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
MergeSort Source: Gibbs & Tamassia
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 MergeSort MergeSort is a divide and conquer method of sorting
Background image of page 2
3 MergeSort Algorithm MergeSort is a recursive sorting procedure that uses at most O(n lg(n)) comparisons. To sort an array of n elements, we perform the following steps in sequence: If n < 2 then the array is already sorted. Otherwise, n > 1 , and we perform the following three steps in sequence: 1. Sort the left half of the the array using MergeSort. 2. Sort the right half of the the array using MergeSort. 3. Merge the sorted left and right halves.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 How to Merge Here are two lists to be merged: First: (12, 16, 17, 20, 21, 27) Second: (9, 10, 11, 12, 19) Compare 12 and 9 First: (12, 16, 17, 20, 21, 27) Second: (10, 11, 12, 19) New: (9) Compare 12 and 10 First: (12, 16, 17, 20, 21, 27) Second: (11, 12, 19)
Background image of page 4
5 Merge Example Compare 12 and 11 First: (12, 16, 17, 20, 21, 27) Second: (12, 19) New: (9, 10, 11) Compare 12 and 12 First: (16, 17, 20, 21, 27) Second: (12, 19) New: (9, 10, 11, 12)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Merge Example Compare 16 and 12 First: (16, 17, 20, 21, 27) Second: (19) New: (9, 10, 11, 12, 12) Compare 16 and 19 First: (17, 20, 21, 27) Second: (19) New: (9, 10, 11, 12, 12, 16)
Background image of page 6
7 Merge Example Compare 17 and 19 First: (20, 21, 27) Second: (19) New: (9, 10, 11, 12, 12, 16, 17) Compare 20 and 19 First: (20, 21, 27) Second: ( ) New: (9, 10, 11, 12, 12, 16, 17, 19)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Merge Example Checkout 20 and empty list First: ( ) Second: ( ) New: (9, 10, 11, 12, 12, 16, 17, 19, 20 , 21 , 27 )
Background image of page 8
9 MergeSort Original 24 13 26 1 12 27 38 15 Divide in 2 24 13 26 1 12 27 38 15 Divide in 4 24 13 26 1 12 27 38 15 Divide in 8 24 13 26 1 12 27 38 15 Merge 2 13 24 1 26 12 27 15 38 Merge 4 1 13 24 26 12 15 27 38 Merge 8 1 12 13 15 24 26 27 38
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Merge-Sort Tree
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/06/2010 for the course COMPUTER S 101 taught by Professor Sanaodeh during the Spring '08 term at NYU.

Page1 / 22

mergesort-102-sp10 - MergeSort Source: Gibbs & Tamassia...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online