The '''merge sort''' is a recursive sort of order <big> n*log(n). </big>
It is notable for having a worst case and average complexity of <big> ''O(n*log(n))'', </big> and a best case complexity of <big> ''O(n)'' </big> (for pre-sorted input).
The basic idea is to split the collection into smaller groups by halving it until the groups only have one element or no elements (which are both entirely sorted groups).
* the Wikipedia entry: [[wp:Merge_sort| merge sort]]
Note: better performance can be expected if, rather than recursing until <big> length(m) ≤ 1, </big> an insertion sort is used for <big> length(m) </big> smaller than some threshold larger than '''1'''. However, this complicates the example code, so it is not shown here.