Skip to content

Merge sort

ordering

Level 2 of 3

Also called Bottom-up merge sort.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from merge sort's own run on the numbers shown.

choose one

question 1

Merge sort works on 6, 3, 8, 1, 5, 2. What is the row just after its fourth merge?

638152
the answer, and why

the answer is D

Round 1 merges three pairs. Merge 4 joins 3, 6 with 1, 8, while 2, 5 waits.

the row: 6, 3, 8, 1, 5, 2111111start222round 142round 26round 32a run, its length insideno partner, carried downthe first runall in one runa merge in round 2, its numbers36181368goes straight in, the other run used up
Merge 4, the only merge of round 2.

if you chose another

  • That is after merge 3, the end of round 1.
  • That is the end, after merge 5.
  • Round 1 merges the last pair too, so 5, 2 becomes 2, 5.

new numbers

question 2

How many comparisons does merge sort make on 7, 7, 7, 7, 7, 7?

777777
the answer, and why

the answer is B

On a tie the left goes first, so each merge compares its whole left run, 3 in round 1, then 2, then 4.

the row: 7, 7, 7, 7, 7, 7111111start222round 142round 26round 32a run, its length insideno partner, carried downthe first runall in one runa merge in round 3, its numbers777777777777goes straight in, the other run used up
Round 3 compares the left four; the right two follow free.

if you chose another

  • That sends the right run first, as back to front.
  • Equal numbers are still compared, to find the tie.
  • That is a dearest row's count, 16 placed less 5 merges.

new numbers

question 3

Merge sort works on each of these rows of 1 to 7. On which does it make the most comparisons?

the answer, and why

the answer is C

In each merge the two largest stand in different runs, so it compares all but its last number, 20 placed less 6 merges, 14.

the row: 3, 7, 1, 5, 2, 6, 41111111start2221round 143round 27round 32a run, its length insideno partner, carried downthe first runall in one runa merge in round 3, its numbers13572461234567goes straight in, the other run used up
Round 3 merges 1, 3, 5, 7 with 2, 4, 6.

if you chose another

  • In order costs 11, each merge comparing only its left run.
  • Back to front costs 9, the fewest.
  • That costs 13, as its last merge holds the 6 and the 7 in one run.

new numbers