Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-IT-2004 | Question 53

  • Last Updated : 28 Jun, 2021

An array of integers of size n can be converted into a heap by adjusting the heaps rooted at each internal node of the complete binary tree starting at the node ⌊(n – 1) /2⌋, and doing this adjustment up to the root node (root node is at index 0) in the order ⌊(n – 1)/2⌋, ⌊(n – 3)/ 2⌋, ….., 0. The time required to construct a heap in this manner is
(A) O(log n)
(B) O(n)
(C) O (n log log n)
(D) O(n log n)

Answer: (B)

Explanation: The above statement is actually algorithm for building a Heap of an input array A.

    heapsize := size(A); 
    for i := floor(heapsize/2) downto 1 
        do HEAPIFY(A, i); 
    end for 

Upper bound of time complexity is O(n) for above algo



Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :