// Outline for external mergesort phases
// 1) Run formation: read M items, sort in-memory, write back (n/M runs)
// 2) Multiway merge: merge up to k ≈ M/B runs using a min-heap of size k
function multiwayMerge(runs, readBlock, writeBlock) {
// runs: array of run descriptors; readBlock(run) yields next block array; writeBlock outputs block
// Use a min-heap of current heads across runs; refill when a block is exhausted
}
- I/O complexity: Θ(Sort(n)).
- Tricks: replacement selection to make longer initial runs; double-buffering to overlap I/O and CPU.