AI engineering glossary · Data structures algorithms
What is Top-K problem?
Top-K problem (also called k largest elements): Finding the k largest or smallest items from a collection without fully sorting it. A heap of size k does this in O(n log k) time, which is far cheaper than sorting when k is small.
Top-K problem: an example
To list the 10 highest-selling products from 5 lakh, keep a min-heap of 10 items and replace its smallest whenever a bigger sale appears.
Related terms
More Data structures algorithms terms
- Topological sort
- Traveling salesman problem
- Tree
- Tree traversal
- Trie
- Two pointers
- Union-find
- Weighted graph
Where you learn it
Top-K problem is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.