Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE

Keys 36, 91, 14, 43, 11, 56, 93 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is the final array?

  1. A. [56, 14, 11, 36, 91, 43, 93]
  2. B. [93, 43, 91, 36, 11, 14, 56]
  3. C. [93, 91, 56, 43, 36, 14, 11]
  4. D. [93, 91, 56, 43, 11, 36, 14]

Correct answer: B. [93, 43, 91, 36, 11, 14, 56]

Insert each key at the end and swap with its parent while larger. Result [93, 43, 91, 36, 11, 14, 56]. Building by Floyd's bottom-up method may give a different (also valid) heap.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic