Regarding in-place merge in an array

This seems to indicate that it is possible to do in O(lg^2 n) space. I cannot see how to prove that it is impossible to merge in constant space, but I cannot see how to do it either.

Edit:
Chasing references, Knuth Vol 3 – Exercise 5.5.3 says “A considerably more complicated algorithm of L. Trabb-Pardo provides the best possible answer to this problem: It is possible to do stable merging in O(n) time and stable sorting in O(n lg n) time, using only O(lg n) bits of auxiliary memory for a fixed number of index variables.

More references that I have not read. Thanks for an interesting problem.

Further edit:
This article claims that the article by Huang and Langston have an algorithm that merges two lists of size m and n in time O(m + n), so the answer to your question would seem to be yes. Unfortunately I do not have access to the article, so I must trust the second hand information. I’m not sure how to reconcile this with Knuth’s pronouncement that the Trabb-Pardo algorithm is optimal. If my life depended on it, I’d go with Knuth.

I now see that this had been asked as and earlier Stack Overflow question a number of times. I don’t have the heart to flag it as a duplicate.

Huang B.-C. and Langston M. A., Practical in-place merging, Comm. ACM 31 (1988) 348-352

Leave a Comment