-2
$\begingroup$

i need to say : Where can be a maximum element in a min heap when all the elements are different?

$\endgroup$
2
$\begingroup$

The maximum is one of the heap’s leaves. You can’t know which one. You for optimizing your algorithm, you can scan only the leaves, which in case the heap is implemented with an array, requires scan of maximum of (n+1)/2 nodes (which is still O(n))

$\endgroup$
0
$\begingroup$

The best way to do this would be to iterate over all the items at the bottom of the heap.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.