Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2015 (Set 3) | Question 65

  • Last Updated : 28 Jun, 2021

Consider the following array of elements. 〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〉. The minimum number of interchanges needed to convert it into a max-heap is
(A) 4
(B) 5
(C) 2
(D) 3


Answer: (D)

Explanation: 〈89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100〉


           89
      /         \
     19          50
    /  \        /  \  
  17    12     15    2
 /  \   / \   /  \
5   7  11  6  9  100

Minimum number of swaps required to convert above tree 
to Max heap is 3. Below are 3 swap operations.
Swap 100 with 15
Swap 100 with 50
Swap 100 with 89 

           100
      /         \
     19          89
    /  \        /  \  
  17    12     50    5 
 /  \   / \   /  \
7   11  6  9  2   15


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 :