Answer
(If an odd number of files occurs at any stage of this process, we need merely to set the odd one aside and pair it with one of the larger files in the next stage.
Work Step by Step
The idea is to first divide the file to be stored into many separate files containing
one record each. Next, group the one-record files into pairs, and
apply the merge algorithm to each pair.
- This results in half as many files, each with two records. Furthermore, each of these two-record files is sorted.
We can group them into pairs and again apply the merge algorithm to the pairs.
Again we find ourselves with fewer but larger files, each of which is sorted. Continuing in this fashion, we are ultimately left with only one file that consists of all the original records but in sorted order.
(If an odd number of files occurs at any stage of this process, we need merely to set the odd one aside and pair it with one of the larger files in the next stage.)