Lunes, Pebrero 20, 2012

Merge sort

Merge sort is an O(n log n) comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945.[1] A detailed description and analysis of bottom-up mergesort appeared in a report by Goldstine and Neumann as early as 1948.[2]Merge-sort-example-300px.gif
An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent list. Finally all the elements are sorted and merged.
Class Sorting algorithm
Data structure Array
Worst case performance O(n log n)
Best case performance O(n log n) typical,
O(n) natural variant
Average case performance O(n log n)
Worst case space complexity O(n) auxiliary

Walang komento:

Mag-post ng isang Komento