Top k
Also written: heap for top k
A pattern for "the k largest" or "k busiest" questions. A heap holding only k items costs O(n log k), which beats sorting when k is small.
Also written: heap for top k
A pattern for "the k largest" or "k busiest" questions. A heap holding only k items costs O(n log k), which beats sorting when k is small.