
This lesson is part of the Merge Sort series. The earlier polyphase lesson described rotating input and output tapes. Here is a small schedule showing the idea with three tapes.

Follow the animation step by step
The labels r1 through r8 represent sorted runs, not individual values. The animation is a role-rotation sketch showing how three tapes can reuse one output tape.
- Set up the tapes: A holds runs r1–r5, B holds r6–r8, and C is empty and ready for output.
- Merge one run from each input: combine r1 and r6 into the first longer run on C. A and B each advance to their next run.
- Repeat: merge r2 with r7, then r3 with r8. Each output run on C represents the sorted merge of its two input runs.
- An input runs out: B has no more runs while A still has r4 and r5. The tape roles rotate so an exhausted tape can become the next output.
- Continue until one run remains: later passes combine the remaining real and merged runs. A production schedule must specify dummy runs and exact run counts; this animation illustrates the role change rather than every bookkeeping detail.

Runs and dummy runs
A run is a sorted block of records. Polyphase merging begins by distributing runs unevenly across input tapes so that one tape can serve as output until an input is exhausted. Some schedules use dummy runs, which represent empty runs and do not contain records. They help make the run counts fit the merge pattern.
For a three-tape two-way merge, one Fibonacci-style distribution with five real runs is:
T1: A B C (3 runs)
T2: D E (2 runs)
T3: output (0 runs)The letters represent sorted runs, not individual records. Merge one run from each input into one output run:
Pass 1: T1(A,B,C) + T2(D,E) → T3(AD, BE)After two merges, T2 is empty. Rotate roles: T2 becomes the output, and T1 and T3 become inputs. One more merge gives:
Pass 2: T1(C) + T3(AD, BE) → T2(CAD, BE)This notation needs care: a merge combines corresponding runs in schedule order, and an exhausted input may leave unmatched runs to be carried according to the chosen distribution. A valid polyphase schedule tracks exact run counts at each tape after every operation. For this five-run illustration, the sequence above is only a role-rotation sketch, not a complete executable schedule; a production schedule must include its dummy-run positions explicitly.
Build a valid schedule
To create a correct schedule, start with a target number of real runs and choose a supported polyphase distribution. Add dummy runs where the distribution requires them. At every phase, record which tape is output, how many runs each input has, and which run pair is merged. Stop when only one real output run remains.
The benefit is reduced redistribution between phases when only a few sequential storage devices are available. The trade-off is more complex bookkeeping. Always test the schedule with explicit run labels and verify that each real run appears exactly once in the final merge.
Polyphase merging is mainly useful as an external sorting strategy under limited stream or drive constraints. For ordinary files on modern storage, balanced multiway merging is often easier to schedule. The storage system and access pattern determine which approach is appropriate.


