Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
A min-heap is built by inserting 69, 20, 19, 35, 32, 87, 52, 58 one by one (sift-up on each insert). After one extract-min (move the last element to the root, then sift down), what is the array?
- A. [19, 32, 20, 58, 35, 87, 52, 69]
- B. [20, 32, 52, 58, 35, 87, 69]
- C. [32, 58, 20, 69, 35, 87, 52]
- D. [69, 32, 20, 58, 35, 87, 52]
Correct answer: B. [20, 32, 52, 58, 35, 87, 69]
Heap after all inserts: [19, 32, 20, 58, 35, 87, 52, 69]. Remove the root (19), move the last element (69) to the root and sift it down to restore the min-heap property, giving [20, 32, 52, 58, 35, 87, 69].
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
- A directed weighted graph has edges A→B:3, A→C:5, B→D:5, D→E:9, A→D:5, C→E:-2 (some weights are negative, but there is no negative-weight…
- In the undirected graph with edges A–B:12, A–C:9, C–D:12, D–E:10, C–F:15, E–G:12, E–F:6, A–D:15, what is the shortest-path distance from A…
- Keys 82, 68, 95, 70, 94, 13, 69, 23, 56 are inserted in this order into an empty BST. How many leaf nodes does the resulting tree have?
- An undirected graph has adjacency lists A:BCF B:ADF C:AE D:B E:CF F:ABE. Neighbours are always explored in alphabetical order. Which is…
- In the undirected graph with edges A–B:12, B–C:8, B–D:12, A–E:9, D–F:10, B–F:14, A–C:12, what is the shortest-path distance from A to E?
- Keys 81, 18, 92, 48, 71, 55, 44, 41 are inserted in this order into an empty BST. What is the postorder traversal?