Top k
O(n log k)Keep a min-heap of size k. Push each item, and when the heap grows past k, pop the smallest. What is left is the k largest.
Reach for it when you want the best k of many and k is much smaller than n.Go deeper: How a heap always knows the smallest