Heaps

Learn heap construction and implementation before practising selection, merging and priority-queue interview applications.

23 online
Overall Progress
PLUS – Videos, editorials, planner all in one place – Videos, editorials, personalised planner & TUFY all in one place to save your time.

Planly

Know more

Striver’s Heaps Sheet contains 20 coding questions. Four source exercises have been restored alongside the retained 16-question selection: building a heap from an array, implementing Min Heap, implementing Max Heap, and checking whether an array is a min heap. The practice then moves into selection, merging and priority-based applications.

Striver’s Heap Sheet contains 16 problems covering heap repair, ranking, top-k selection, merging sorted sources, running answers and scheduling. The questions move from a single heap property to designs that maintain several conditions, such as balancing two halves of a stream or separating a task’s priority from the time it becomes available.

Describe what the root means before deciding between a min heap and a max heap. It might be the smallest next output, the weakest retained large value or the earliest available event. The internal array is only partially ordered, so a correct root does not mean every entry is already in sorted order.

Topics covered in this practice sheet

The foundation questions cover parent-child positions in an array, the heap-order rule and the updates needed to maintain it. The application questions use a heap or priority queue to keep track of a next candidate, a limited set of values or the next item to merge. A min heap and a max heap answer different immediate-access needs.

  • Heap construction, heap-order checking and Min/Max Heap implementations.
  • Selection and maintaining a limited collection of candidates.
  • Merging, k-sorted data and priority-queue applications.

Beginner lessons and prerequisites

Start with the existing heap theory lesson. Know array positions, tree relationships, comparisons and loops before implementing heap operations. Understand which element the heap exposes first and which order the rest of the stored values are not required to follow.

Know min-heap and max-heap order, insertion, root extraction and bottom-up construction. A binary heap containing a given number of candidates supports logarithmic repair after an insertion or extraction, while reading the root is constant time. Finding an arbitrary stored value is not automatically logarithmic, because heap order does not select a unique search subtree.

Be comfortable comparing compound entries, counting frequencies and advancing through sorted arrays or linked nodes. Define the meaning of ties. Two equal values from separate sources may be separate required occurrences, while the same pair state discovered through different paths may need duplicate prevention. Those are different reasons for keeping or removing repeated-looking entries.