Skip to content

Building a heap

storing

Level 2 of 3

Also called Heapify, Floyd's method and Bottom-up heap construction.

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

choose one

question 1

On which of these rows does building a heap make no swap at all?

the answer, and why

the answer is B

On 79, 78, 66, 35, 10, 53, 60 every parent is at least as big as its children, so every sift stops at once and building makes no swap.

if you chose another

  • Building a heap makes 1 swap on this row: a parent there is smaller than a child.
  • Building a heap makes 1 swap on this row: a parent there is smaller than a child.
  • Building a heap makes 1 swap on this row: a parent there is smaller than a child.

new numbersthe test page's numbers

question 2

Each row holds the same six numbers. On which does building a heap make the most comparisons?

the answer, and why

the answer is A

Building a heap makes 6 comparisons on 19, 59, 66, 81, 49, 92, the most of the four.

if you chose another

  • Building a heap makes 5 comparisons on this row, fewer than 6.
  • Building a heap makes 5 comparisons on this row, fewer than 6.
  • Building a heap makes 5 comparisons on this row, fewer than 6.

new numbersthe test page's numbers