Data Structures & AlgorithmsHardICPC regional · algorithm theory

Problem: Which statement about building a binary heap from n given elements is correct?

  1. A. It always needs O(n log n) time
  2. B. Floyd's bottom-up heapify builds the heap in O(n) time
  3. C. It needs O(n^2) time because each insert is linear
  4. D. It is impossible without sorting first

Correct answer: B. Floyd's bottom-up heapify builds the heap in O(n) time

Sifting down from the last internal node costs a sum that converges to O(n).

More Coding Interview Problems questions

Exams that ask this topic