Docsity

Merge Sort: A Detailed Analysis of the Merge Sort Algorithm, Slides of Data Structures and Algorithms

Partial preview of the text

Download Merge Sort: A Detailed Analysis of the Merge Sort Algorithm and more Slides Data Structures and Algorithms in PDF only on Docsity!

Merge Sort

In the Beginning…

John von Neumann (1903-1957)

  • Stored program
  • Developed merge sort for EDVAC in 1945

Merging (cont.)

  • The merge Algorithm: From The Art of Computer Programming vol2: Sorting and Searching by Donald E. Knuth (page 160).

Merging (cont.)

X: 3 10 23 54 Y: 1 5 25 75

Result:

Merging (cont.)

X: Y:

Result:

Merging (cont.)

X: Y:

Result:

Merging (cont.)

X: Y:

Result:

Merging (cont.)

X: Y:

Result:

Merging (cont.)

X: Y:

Result:

Divide And Conquer

  • Merging a two lists of one element each is the same as sorting them.
  • Merge sort divides up an unsorted list until the above condition is met and then sorts the divided parts back together in pairs.
  • Specifically this can be done by recursively dividing the unsorted list in half, merge sorting the right side then the left side and then merging the right and left back together.

Merge Sort Example

Merge Sort Example

Merge Sort Example

Merge Sort Example