Data Structures & AlgorithmsHardGATE CS · ISRO Scientist
A min-heap starts empty. The operations, in order, are: insert 7, insert 11, insert 15, insert 17, delete-min, insert 16, insert 14, insert 20, delete-min, delete-min. Here insert adds a value and delete-min removes the current smallest value. Among the values still stored, what is the 3-th smallest?
- A. 17
- B. 20
- C. 14
- D. 16
Correct answer: A. 17
The stored multiset is what remains after the delete-mins, so the answer is the k-th smallest of that multiset. Heap positions are not sorted, and the values removed by delete-min must not be counted.
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 min-heap starts empty. The operations, in order, are: insert 19, insert 19, insert 6, delete-min, insert 9, insert 2, insert 3, insert…
- A min-heap starts empty. The operations, in order, are: insert 4, insert 3, insert 10, delete-min, delete-min, insert 4, insert 1, insert…
- An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=9), 0-2 (w=6), 0-4 (w=10), 1-2 (w=2), 1-3 (w=3), 1-4…
- An undirected connected graph on vertices 0 to 6 has these weighted edges: 0-1 (w=11), 0-2 (w=11), 0-4 (w=2), 0-5 (w=6), 1-2 (w=7), 1-3…
- An undirected connected graph on vertices 0 to 6 has these weighted edges: 0-1 (w=11), 0-5 (w=4), 1-2 (w=2), 1-3 (w=1), 1-6 (w=2), 2-4…
- An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=10), 0-2 (w=2), 1-2 (w=1), 1-3 (w=7), 2-3 (w=8), 3-4…