Open In App
Related Articles

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

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads