Monday, April 6, 2009

Merge Sort
Definition:
An 0(n log n) comparison-based sorting algorithms.
In most implementations it is stable, meaning that it preserves the input order of equal elements in the sorted output.
It is an example of the divide and conquer algorithmic paradigm.
It was invented by John von Neumann in 1945.
Run-time Complexity Analysis:
♥ Efficient and effective

Code:
function merge_sort(m)
var list left, right, result
if length(m) ≤ 1
return m

// This calculation is for 1-based arrays.
For 0-based, use length(m)/2 - 1.
var middle = length(m) / 2
for each x in m up to middle
add x to left
for each x in m after middle
add x to right
left = merge_sort(left)
right = merge_sort(right)
result = merge(left, right)
return result

Application:
♥ Merging a bundle of something like sticks and other.

Reference:
en.wikipedia.org/wiki/Merge_sort
http://en.wikipedia.org/wiki/Sorting_algorithm#Merge_sort

No comments:

Post a Comment