I want to write the most efficient algorithm to find minimum element in Max-Heap.
Important facts: The heap is represented as array (each element in index i has 2 children - left and right - indices 2i and 2i+1), all elements are different.
This is what I thought about:
Without additional space: the minimum will be only in the leaves - there are about n/2 leaves so we have to check each one of them - Runtime: O(n/2)=O(n).
With additional space: to build a min-heap, additionally to the max-heap. In this heap we'll have only the leaves, so to get the minimal element (minimal leaf) is only O(1) - Extract min from min-heap. The main drawback is that we have to change all the other methods - Add, Delete etc, because we need to update the min-heap.
a. What do you think about my algorithms? b. I'll be glad to get improvements from you. Are there more efficient algorithms from O(n) while we are not using additional space?
I want to find the most effcient algorithm with and without additional space (2 solutions).
Thank you!