External merge sort

How do you sort a file that cannot fit in memory? Read it two records at a time.

A page holds two records. Three memory pages read input runs, and a fourth collects the output.

Compare the first unread values from runs A, B and C. Fill the output page with the smallest values and write it to disk.

Each pass reads and writes the file once. Initial runs have two records, and each merge pass triples their length. Memory holds four pages.