Data Structures & AlgorithmsHardGATE CS · ISRO Scientist
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 5, insert 5, insert 10. Here insert adds a value and delete-min removes the current smallest value. Among the values still stored, what is the 2-th smallest?
- A. 10
- B. 3
- C. 4
- D. 5
Correct answer: C. 4
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
- 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…
- An undirected connected graph on vertices 0 to 5 has these weighted edges: 0-1 (w=7), 0-4 (w=9), 0-5 (w=1), 1-2 (w=7), 1-3 (w=7), 2-3…
- An undirected connected graph on vertices 0 to 7 has these weighted edges: 0-1 (w=11), 0-3 (w=8), 0-4 (w=11), 0-7 (w=7), 1-2 (w=4), 1-3…