In a binary min heap containing n elements, the largest element can be found in __________ time.

Category: QuestionsIn a binary min heap containing n elements, the largest element can be found in __________ time.
Editor">Editor Staff asked 1 month ago

In a binary min heap containing n elements, the largest element can be found in __________ time.
 
(a) O(n)
 
(b) O(nlogn)
 
(c) O(logn)
 
(d) O(1)
 
The doubt is from Heap in portion Heap of Data Structures & Algorithms I
 
The question was asked in an online interview.

1 Answers
Editor">Editor Staff answered 1 month ago

Right answer is (a) O(n)
 
The best I can explain: In min heap the smallest is located at the root and the largest elements are located at the leaf nodes. So, all leaf nodes need to be checked to find the largest element. Thus, worst case time will be O (n).