+1 vote
in Data Structures & Algorithms I by (88.2k points)
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 Answer

+1 vote
by (672k points)
selected by
 
Best answer
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).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.

Categories

...