Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Array [12, 23, 8, 18, 15, 14, 26, 13] 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. [8, 23, 12, 18, 15, 14, 26, 13]
  2. B. [8, 12, 13, 14, 15, 18, 23, 26]
  3. C. [8, 13, 12, 18, 15, 14, 26, 23]
  4. D. [8, 13, 12, 15, 18, 14, 26, 23]

Correct answer: C. [8, 13, 12, 18, 15, 14, 26, 23]

Bottom-up heapify on [12, 23, 8, 18, 15, 14, 26, 13] produces [8, 13, 12, 18, 15, 14, 26, 23]. 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