Data Structures & AlgorithmsVery hardGATE CS · ISRO Scientist
A min-heap starts empty. The operations, in order, are: insert 17, insert 4, insert 12, delete-min, insert 8, insert 17, insert 19, insert 19. 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. 19
- B. 17
- C. 8
- D. 12
Correct answer: D. 12
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 2, insert 20, insert 6, insert 15, insert 12, delete-min, insert 17, insert…
- A min-heap starts empty. The operations, in order, are: insert 13, insert 20, insert 11, insert 10, insert 3, insert 19, delete-min…
- A min-heap starts empty. The operations, in order, are: insert 2, insert 14, delete-min, delete-min, insert 15, insert 20, delete-min…
- A min-heap starts empty. The operations, in order, are: insert 7, delete-min, insert 14, insert 15, delete-min, insert 3, insert 3, insert…
- A min-heap starts empty. The operations, in order, are: insert 2, delete-min, insert 20, insert 2, insert 4, delete-min, insert 7, insert…
- A min-heap starts empty. The operations, in order, are: insert 1, insert 15, insert 15, insert 19, delete-min, insert 16, delete-min…