Merge exchange sort:归并交换排序
Animation
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 lists. Finally all the elements are sorted and merged.
Merge sort animation. The sorted elements are represented by dots.
A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down).
Complexity
Class | Sorting algorithm |
---|---|
Data structure | Array |
Worst case performance | O(nlogn) |
Best case performance | O(nlogn) typical, O(n) natural variant |
Average case performance | O(nlogn) |
Worst case space complexity | О(n) total, O(n) auxiliary |
Algorithm M
Algorithm M (Merge exchange). Records R1,...,RN are rearranged in place;
after sorting is complete their keys will be in order, K1<=...<=KN . We assume
that N>=2