← Quiz: Heaps and Heap Sort Internals: all 15 questions
Quiz: Heaps and Heap Sort Internals · Question 9 of 15
To find the 10 largest values in a stream of a million numbers, the best heap approach is:
To find the 10 largest values in a stream of a million numbers, the best heap approach is:
- A.A max-heap of all one million numbers
- B.A min-heap that never holds more than 10 numbers
- C.A max-heap of size 10
- D.Sorting the numbers after they all arrive
Answer & explanation
Correct answer: A min-heap that never holds more than 10 numbers
The min-heap's root is the weakest of the current top 10, so each new number is compared with it: O(n log k) time and O(k) memory.
Can you get the rest right without peeking?
Take the timed Quiz: Heaps and Heap Sort Internals quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →