Data Structures & AlgorithmsHardProduct-company MCQ pattern

How many of these statements are correct? (i) Building a heap from n elements by bottom-up sift-down takes O(n) time. (ii) Inserting n elements one by one into an initially empty heap takes O(n log n) in the worst case. (iii) Finding the maximum in a min-heap takes O(log n). (iv) Heap sort is stable.

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: B. Only two

(i) and (ii) are true: most nodes are near the bottom and sift down only a little, so bottom-up building sums to O(n). (iii) is false: the maximum is among the ~n/2 leaves, so it takes O(n). (iv) is false: heap sort can reorder equal keys.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic