Recursive Mergesort
A[1..n] is to be sorted;
B[1..n] is an auxiliary array;
Mergesort(i,j) {sorts the subarray A[i..j] }
if i < j then
k := (i+j)/2;
Mergesort(i,k);
Mergesort(k+1,j);
Merge A[i..k] with A[k+1..j] into B[i..j];
Copy B[i..j] into A[i..j];
Previous slide
Next slide
Back to first slide
View graphic version