Merge sort

Imagine a shuffled pile of number cards. Put them in order by merging small sorted piles into larger ones.

Start with one card per pile. The first pass makes pairs, the second makes groups of four.

Compare the front cards. Copy the smaller one into the buffer. On a tie take the left card to preserve the original order.

Each pass copies all n cards. Sorting takes O(n log n) time and O(n) extra space.