
Divide the problem into a number of subproblems that are smaller instances of the same problem
Conquer the subproblems by solving them recursively. If the subproblem sizes are small enough, however, just solve the subproblems in a straightforward manner.
Combine the solutions to the subproblems into the solution for the original problem
Divide the -element sequence to be sorted into two subsequences of /2 elements each
Sort the two subsequences recursively using merge sort
Merge the two sorted subsequences to produce the sorted answer

is an array and and are indices into the array such that
The subarrays and are in sorted order
It merges the two subarrays to form a single sorted subarray that replaces the current subarray
This procedure takes time , where is the total number of elements being merged
is sentinel value, so that whenever a value with is exposed, it cannot be the smaller value unless both subarrays have their sentinel value exposed
The operation of lines 10-7 in the call MERGE


Loop invariant
At the start of each iteration of the for loop of lines 12-17, the subarray contatins the smallest elements of and , in sorted order. Moreover, and are the smallest elements of their arrays that have not been copied back into .
Prior to the first iteration of the loop, we have , so that the subarray is empty. This empty subarray contains the smallest elements of and , and since , both and are the smallest elements of their arrays that have not been copied back into A.
Let it first suppose that . Then is the smallest element not yet copied back into . Because contains the smallest elements, after line 14 copies into , the subarray will contain the smallest elements. Incrementing and reestablishes the loop invariant for the next iteration. If instead , then lines 16-17 perform the appropriate action to maintain the loop invariant.
At termination, . By the loop invariant, the subarray , which is , contains the smallest elements of and , in sorted order. The arrays and together contain elements. All but the two largest have been copied back into A, and these two largest elements are the sentinels.

