Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

Inserting into a binary heap of n elements (array-based, sift-up) takes worst-case time:

  1. A. O(log n)
  2. B. O(1)
  3. C. O(n)
  4. D. O(n log n)

Correct answer: A. O(log n)

A new element is placed at the next free leaf and sifted up at most the height of the heap, which is O(log n).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic