Sunday, September 5, 2010

Merge Sort

Merge sort is a divide and conquer sorting algorithm that uses recursion to reattach the individual elements into the proper order. It starts off by separating the starting array into two halves and then calls itself until there are n arrays that contain only 1 element. Next, the algorithm looks at the first (and smallest) element of the last 2 arrays that were split and picks the smaller value first and repeats until both arrays are empty. Then because of recursion the parent array is recombined in a smallest to largest order and so on until the entire array is sorted.
The advantages of merge sort is that it has a worst-case scenario of Θ(n ln n) and is useful for online sorting because it does not need to receive data all at once,

1 comment:

  1. Good Job!

    Can you write the merge sort algorithm in terms of function calls and steps.
    See: http://en.wikipedia.org/wiki/Merge_sort

    -Aviral

    ReplyDelete