0

My opinion: In a min heap, the largest element is always on the leaves. The number of leaves is between lg(n+1)/2 and lg(n+1). By linear searching among the leaves I can always find the largest element in the heap with O(lgn) time. Deleting that item costs constant time. Linear searching the Leaves can give us the second largest element in the heap in O(lgn) time.

However, the professors in MIT say we can't do that. Quiz solution in MIT 6.006

I wonder what's wrong with my solution.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753

1 Answers1

0

Maximum number of nodes in a binary tree is enter image description here

Out of them you will have 2^k leaves. So basically almost one half of all the leaves O(n), which is not even close to your log estimate. Your algorithm will run most probably in O(n log n)

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753