Data Structures & AlgorithmsVery hardGATE CSE · Advanced

A max-heap is built from the ascending array 1, 2, ..., 15 in two ways: (a) inserting the elements one at a time with sift-up, (b) the bottom-up heapify (Floyd) method on the array. Counting every exchange of a parent with a child, how many more swaps does (a) make than (b)?

  1. A. 11
  2. B. 23
  3. C. 34
  4. D. 21

Correct answer: B. 23

Each inserted value i rises floor(log2 i) levels, totalling 34 swaps; bottom-up heapify needs only 11, so the difference is 23.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic