Data Structures19 sections · 729 units
Open in Course

Lessons from Merge K Lists

Frontier tracking

What did you learn?

1.1. Heaps track "frontiers" efficiently. The heap contains one candidate from each source.

2.2. The heap size is bounded by kk, not nn. Bounded size gives you O(nlogk)O(n \log k) instead of O(nlogn)O(n \log n).

3.3. Store enough metadata in heap entries to know where the next element comes from. This pattern applies to merging any kk sorted streams: files, arrays, iterators.