-1

What is the best algorithm(in terms of time complexity) to find the minimum element in max heap?

  • 1
    Hello and welcome to Stackoverflow! You may want to provide some parameters for use as part of evaluating "best" since it is very subjective and there are different ways one algorithm could be better than another. If time or amount of resources required are what you are interested in using to evaluate "best" please specify which you are interested in using. – Brandon Haugen Nov 23 '18 at 20:36

1 Answers1

0

The minimum element in a max-heap is guaranteed to be in the last (n/2 + 1) items, where n is the number of items in the heap. So the best way to find it is to do a sequential scan of the last n/2 items. Consider, for example, a heap with 5 items:

    5
  4   1
 3 2

The smallest item will never have children, so it must be either on the bottom row of the heap, or on the next row up.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351