Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
A max-heap is built by inserting 61, 86, 95, 83, 45, 47, 46 one by one. After a single extract-max (move last element to root, sift-down), what is the array?
- A. [83, 86, 61, 45, 47, 46]
- B. [46, 83, 86, 61, 45, 47]
- C. [86, 83, 61, 46, 45, 47]
- D. [86, 83, 47, 61, 45, 46]
Correct answer: D. [86, 83, 47, 61, 45, 46]
Heap before = [95, 83, 86, 61, 45, 47, 46]. Remove 95, put 46 at the root and sift down: [86, 83, 47, 61, 45, 46].
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 (u–v: weight) A–B:30, A–C:9, A–D:11, D–E:14, A–E:25. What is the weight of its minimum spanning tree?
- Directed edges: A→B (6), A→C (6), C→B (-2), B→D (3). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 8, 91, 32, 54, 14, 31, 17, 21, 26 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain) into…
- Keys 56, 62, 60, 92, 46, 65, 74, 38, 72 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree…
- A binary tree has preorder traversal [7, 75, 8, 32, 9, 18, 91, 86] and inorder traversal [7, 8, 9, 18, 32, 75, 86, 91]. Reconstructing the…
- Keys 43, 53, 63 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…