GATE Computer ScienceHardGATE CSE · ISRO
A max-heap is stored in the array [90, 70, 80, 40, 50, 60, 75, 20, 10] (index 0 is the root). After one delete-max operation (the last element is moved to the root and sifted down), what is the array?
- A. 80, 70, 75, 40, 50, 60, 10, 20
- B. 80, 70, 75, 40, 50, 60, 20, 10
- C. 80, 75, 70, 40, 50, 60, 10, 20
- D. 70, 50, 80, 40, 10, 60, 75, 20
Correct answer: A. 80, 70, 75, 40, 50, 60, 10, 20
Move 10 to the root and sift down: swap with 80, then with 75. Result: 80, 70, 75, 40, 50, 60, 10, 20.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- To find both the largest and the second-largest among 16 distinct numbers, a knockout tournament is played and then the second-largest is…
- Twelve keys 15, 22, 5, 31, 10, 27, 12, 40, 3, 18, 20, 25 are inserted in this order into a hash table of 5 slots with separate chaining…
- Keys 40, 20, 60, 10, 30, 50, 70, 25, 35, 45, 65 are inserted into an empty BST. The root 40 is then deleted, replacing it by its inorder…
- Integers 1, 2, 3, 4, 5, 6 are pushed onto a stack in this order, with pops allowed at any time. How many distinct complete output…
- A binary tree has preorder 8 3 1 6 4 7 10 14 13 and inorder 1 3 4 6 7 8 10 13 14. What is its postorder traversal?
- int c = 0; for (int i = 1; i < 100; i = 2) for (int j = 0; j < i; j++) c++; What is the final value of c?