DIVIDE_AND_CONQUER_ADD(A,low,high)
- if low > high
- return 0
- else if low = high
- return A[low]
- else
- mid ← (high+low)/2
- return DIVIDE_AND_CONQUER_ADD(A, low,mid) + DIVIDE_AND_CONQUER_ADD(A, mid+1, high)
MERGESORT(A[0... n-1])
- if n > 1
- B ← A[0 ... n/2-1]
- C ← A[n/2 ... n-1]
- MERGESORT(B)
- MERGESORT(C)
- MERGE(B,C,A)
MERGE(B[0 .. p-1],C[0 .. q-1], A[0 .. n-1])
- i ←0; j←0, k←0
- while i <p and j < q do
- ifB[i] ≤C[j]
- A[k] ← B[i]; i←i+1
- else
- A[k] ← C[j]; j←j+1
- k ← k + 1
- if i == p
- copy(C[j .. q-1] to A[k .. n-1]
- else
- copy(B[i .. p-1] to A[k .. n-1]