Skip to content

Heap sort

ordering

Level 3 of 3

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 heap sort's own run on the numbers shown.

choose one

question 1

Heap sort starts on 15, 44, 33, 47, 23. What is the row once the heap is built, before the first swap of the top?

1544334723115244333447523
the answer, and why

the answer is C

Each place with children, from the last to the top, sifts its number down, swapping it with its bigger child while that child is bigger: 47, 44, 33, 15, 23.

if you chose another

  • That stops the sift of 15 one round early. 44 is bigger, so 15 goes down again.
  • That is the end of the sort.
  • That is the start. 15 is smaller than its child 44.

new numbersthe test page's numbers

question 2

How many comparisons does heap sort make on 46, 46, 46, 46, 46, 46?

464646464646146246346446546646
the answer, and why

the answer is D

Building compares each child once, 5. Sorting compares the tops' children, 2 each for heaps of 5, 4 and 3, then 1. That is 5 + 7 = 12.

if you chose another

  • That is the building only.
  • That is the sorting only.
  • That is 3 times 6, but the formula takes 6 away.

new numbersthe test page's numbers

question 3

On which row does heap sort make the fewest comparisons?

the answer, and why

the answer is A

Heap sort makes 14 comparisons on 9, 7, 2, 7, 9, 8, the fewest of the four.

if you chose another

  • Heap sort makes 15 comparisons on this row, more than 14.
  • Heap sort makes 17 comparisons on this row, more than 14.
  • Heap sort makes 15 comparisons on this row, more than 14.

new numbersthe test page's numbers