Asked about Trees, graphs and the rest

How do you find the top k elements efficiently?

An answer that works

Keep a heap of size k rather than sorting everything. That is n log k rather than n log n, and it works on a stream where you cannot hold all the data at once.

Reading an answer is not being able to give one. The section that teaches this is Trees, graphs and the rest, 16 hours of Data structures & algorithms.

Learn this properly