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 70, 43, 55, 10, 20, 53, 36 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 C

Building a heap makes 7 comparisons on 13, 3, 75, 97, 57, 43, the most of the four.

if you chose another

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

new numbersthe test page's numbers