merge sort :Merge the two sorted subsequences to produce the sorted sequence recursively to the original problem.
Merge (A, p, q, r)
n1 = q-p+1
n2 = r-q
let L[1..n1+1] and R[1..n2+1] be new array
for i=1 to n1
L[i] = A[p+i-1]
for i=1 to n2
R[i] = A[q+i]
L[n1+1] = R[n2+1] = INF
i = 1
j = 1
for k=p to r
if L[i] <= R[j]
A[k] = L[i]
i = i+1
else A[k] = R[j]
j = j+1
Merge-Sort (A, p, r)
if p<r
q = [(p+r)/2] // floor
Merge-Sort (A, p, q)
Merge-Sort (A, q+1, r)
Merge (A, p, q, r)
The merge sort takes running time of Θ(nlgn) , It is stable but not in place
Some of above content refere to “Introduction to Algorithm”.