Data Structures19 sections · 729 units
Open in Course

Section Recap

What we learned

You now have heap proficiency:

1.1. Heap basics: O(1)O(1) peek, O(logn)O(\log n) insert and extract. Stored as arrays.

2.2. K-th element pattern: use a bounded heap of size kk. For k-th largest, use a min-heap.

3.3. K-way merge: heap tracks the frontier of kk candidates. O(nlogk)O(n \log k) to merge.

4.4. Two heaps: partition data around median. O(logn)O(\log n) insertion, O(1)O(1) median query.

5.5. Combining structures: heaps often pair with hash maps (top k frequent) or other structures.

Heaps are your tool when you need efficient, repeated access to extrema. Learn these patterns and a whole class of problems becomes routine. Practice these patterns until they become automatic.