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

Category: QuestionsAn 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
Editor">Editor Staff asked 1 month ago

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 Answers
Editor">Editor Staff answered 1 month ago

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.