Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional

Array [7, 21, 6, 3, 10, 17, 8] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element at index i down (swap with its smaller child while a child is smaller). What is the resulting array?

  1. A. [3, 7, 6, 21, 10, 17, 8]
  2. B. [6, 21, 7, 3, 10, 17, 8]
  3. C. [3, 6, 7, 8, 10, 17, 21]
  4. D. [3, 6, 7, 21, 10, 17, 8]

Correct answer: A. [3, 7, 6, 21, 10, 17, 8]

Bottom-up heapify on [7, 21, 6, 3, 10, 17, 8] produces [3, 7, 6, 21, 10, 17, 8]. Inserting one element at a time gives a different heap, and a single sift-down from the root does not fix the internal nodes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic