Apply merge sort algorithm (#737)

Apply merge sort algorithm (#737)

Divide, sort recursively, then merge sorted halves.