complexityheapssorting
When is a heap better than sorting?
Anonymous
Keep a min-heap of size k while scanning. A new value replaces the root only when it's larger. This keeps just k candidates; sorting the whole input is simpler when the full order matters.
0