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.

Level: intermediateTopic: Data structures algorithms

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.