Merge Sort
Merge sort is based on the divide-and-conquer paradigm. Its worst-case running time
has a lower order of growth than insertion sort. Since we are dealing with subproblems, we state each subproblem as sorting
a subarray A[p .. r]. Initially, p = 1 and
r = n, but these values change as we recurse through subproblems.
To sort A[p .. r]:
1. Divide Step
If a given array A has zero or one element, simply return; it
is already sorted. Otherwise, split A[p .. r] into two subarrays
A[p .. q] and A[q + 1 .. r],
each containing about half of the elements of A[p .. r]. That is,
q is the halfway point of A[p .. r].
2. Conquer Step
Conquer by recursively sorting the two subarrays A[p ..
q] and A[q + 1 .. r].
3. Combine Step
Combine the elements back in A[p .. r] by merging the two sorted subarrays
A[p .. q] and A[q + 1 .. r]
into a sorted sequence. To accomplish this step, we will
define a procedure MERGE (A, p, q, r).
Note that the recursion bottoms out when the subarray has just
one element, so that it is
trivially sorted.
By:
sutha
On 10:26 PM