+1 vote
in Data Structures & Algorithms I by (88.2k points)
An array consists of n elements. We want to create a heap using the elements. The time complexity of building a heap will be in order of

(a) O(n*n*logn)

(b) O(n*logn)

(c) O(n*n)

(d) O(n *logn *logn)

The doubt is from Heap in chapter Heap of Data Structures & Algorithms I

I got this question in a national level competition.

1 Answer

+1 vote
by (672k points)
selected by
Best answer
The correct choice is (b) O(n*logn)

Best explanation: The total time taken will be N times the complexity of adding a single element to the heap. And adding a single element takes logN time, so That is equal to N*logN.

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.