Skip to content

Glossary: Data Structures and Algorithms in JavaScript

Top-k

Also written: top k, topK, the top few

Finding the k best items by keeping a min-heap of size k and popping whenever it grows too big. It costs O(n log k), better than sorting everything when k is small.

Where the book teaches it

Related terms

HeapPriority queue