Data Structures & AlgorithmsModerateGATE CSE · Heaps
Keys 14, 8, 11, 5, 9, 3, 12 are inserted one at a time into an initially empty binary min-heap kept in an array. What does the array hold afterwards (index 0 first)?
- A. 3 5 11 8 9 14 12
- B. 3 5 8 9 11 12 14
- C. 3 8 5 14 9 11 12
- D. 3 8 5 9 14 11 12
Correct answer: C. 3 8 5 14 9 11 12
After 14, 8, 11 -> [8,14,11]; 5 climbs to the root -> [5,8,11,14]; 9 stays; 3 climbs two levels -> [3,8,5,14,9,11]; 12 stays.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected graph has edges A-B, A-C, B-D, B-E, C-E, C-F, D-G, E-G, F-G. Neighbours are always visited in alphabetical order. What is…
- A binary tree has inorder traversal D B E A F C and postorder traversal D E B F C A. What is its preorder traversal?
- How many structurally different binary search trees can be built from 5 distinct keys?
- A DAG has edges A->C, A->D, B->D, C->E, D->E, D->F, E->G, F->G. Using Kahn's algorithm and always removing the alphabetically smallest…
- In the directed graph with edges S->A (4), S->B (1), B->A (2), A->C (5), B->C (8), B->D (10), C->D (2), C->T (6), D->T (3), what is the…
- A connected undirected graph has 9 vertices and 14 edges. What is the minimum number of edges that must be removed to turn it into a…