Algorithms

Top-k problem

Finding the k largest elements of a list of n. With a min-heap of size k it costs O(n log k).

Example

The 10 most-read news stories out of 1 million: with a heap of 10, about 3.3 million steps instead of sorting everything.

Test yourself: Top-k problem

The k largest

Which of these is a top-k problem?

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.