In "Introduction to Algorithms" the merge sort algorithm is implemented with a helper function called MERGE(A, p, q, r)
- that is merging two previously sorted sequences .
This function introduces two additional arrays L
and R
.
MERGE(A, p, q, r)
1 n1 ← q − p + 1
2 n2 ←r − q
3 create arrays L[1 . . n1 + 1] and R[1 . . n2 + 1]
.....
By "create arrays L[1 . . n1 + 1] and R[1 . . n2 + 1]"
I understand to allocate additional memory for both of them .
Is it possible to re-write this function, so that I won't need the additional memory, and to operate directly to A ?