Heap (Priority Queue)
A specialized tree-based data structure which is essentially a complete binary tree that satisfies the heap property. In a max heap, for any given node I, the value of I is greater than or equal to the values of its children.
Heap (Max-Heap)
Max-Heap Structure
Ready to perform heap operations
What does it cost?
Sort each binary-heap operation by its time complexity.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
O(1)
Drop items hereO(log n)
Drop items hereO(n)
Drop items hereTest your knowledge
Where is the maximum element always located in a Max Heap?
The short version
Think of an emergency room triage. Patients are not treated in order of arrival (FIFO), but by severity. The most critical case (highest priority) is always handled next, regardless of wait time.
In more depth
The Priority Struct
A Heap is a specialized Tree-based data structure that satisfies the Heap Property. It is the most efficient way to repeatedly access the Highest or Lowest priority element.
Array Representation:
Heaps are typically implemented as arrays!
When to reach for this
- Find the **Top K** elements
- Find the **Median** of a stream
- Schedule tasks by Priority
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required