Apply-merge: Lift a binary, increasing function onto ordered lists and produce ordered output

…whether you’ve seen this idea before…

I’m not aware of a name for this algorithm, but after some searching I found it described on the X + Y sorting Wikipedia page. It also resembles Dijkstra’s algorithm to an extent.

…and O(√n) auxiliary space…

While this is true, it does not include the space occupied by the lists. If the lists are generated lazily, more space may be required overall because the implementation has to hold on to the lists. As a simple example, take n (applyMerge const [1 :: Int ..] [1 :: Int ..]) requires O(n) space. Just something to be aware of.

1 Like