Pick the fix
A service receives events all day and must always show the 10 largest so far. What fits best?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A min-heap of size 10
Right: each event costs O(log 10), and the ten largest are always in the heap.
Streaming input with a small k is the case where a bounded heap clearly wins.
Why not the others?
- B Sort all events after each arrival. Cost grows with every event.
- C Quickselect after each arrival. It reprocesses all n events each time.