Data Structures & AlgorithmsVery hardGATE CS · ICPC regional · Product Company SDE
A max-heap is built by inserting 23, 22, 90, 96, 49, 39, 36 one by one. After a single extract-max (move last element to root, sift-down), what is the array?
- A. [90, 49, 39, 22, 36, 23]
- B. [90, 49, 39, 22, 23, 36]
- C. [36, 90, 39, 22, 49, 23]
- D. [90, 39, 22, 49, 23, 36]
Correct answer: A. [90, 49, 39, 22, 36, 23]
Heap before = [96, 90, 39, 22, 49, 23, 36]. Remove 96, put 36 at the root and sift down: [90, 49, 39, 22, 36, 23].
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:3, A–C:21, A–D:19, A–E:17, D–F:13, D–B:29, C–B:27, C–E:2. What is the weight of its…
- In the undirected graph with edges A–B:1, B–C:8, C–D:10, A–E:11, C–F:11, A–C:5, E–F:6, F–B:6, what is the shortest-path distance from A to…
- An undirected graph has adjacency lists A:BCDEF B:AC C:AB D:AEG E:ADG F:A G:DE. Neighbours are always explored in alphabetical order…
- Keys 75, 97, 65, 30, 69, 78, 44, 25, 18 are inserted one by one into an empty binary search tree. What is the pre-order traversal?
- Keys 56, 66, 31, 58, 79, 72, 35, 77 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- Keys 17, 90, 39, 58, 63, 18, 37, 95 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is…