Heap [mp]
Micro pattern¶
Description¶
Maintain efficient access to the highest- or lowest-priority active candidate.
Problems¶
Heap implementation¶
Represent a complete binary tree in an array and restore its order by sifting.
- Heap (DSA)
Maintain the best k values¶
Keep a size-\(k\) heap whose root is the weakest retained candidate.
- 215. Kth Largest Element in an Array (Top Medium)
- 347. Top K Frequent Elements (Top Medium)
K-way merge¶
Keep one current smallest item from each sorted source.
- 23. Merge k Sorted Lists (Top Hard)
Balanced halves¶
Maintain one heap for each half of an ordered data stream.
- 295. Find Median from Data Stream (Top Hard)
Active sweep candidates¶
Prioritize active candidates as sweep coordinates advance.
- 218. The Skyline Problem (Top Hard)
Heap-based sorting¶
Move the root into the sorted suffix and restore the reduced heap.
- Heap sort (DSA)