Overview
A heap stores values in a tree-shaped structure where each parent has priority at least as high as its children. Binary heaps usually store that tree in an array.
Maintains a partial order so the minimum or maximum item can be found quickly.
Compact metadata for implementation and discovery.
A heap stores values in a tree-shaped structure where each parent has priority at least as high as its children. Binary heaps usually store that tree in an array.
Quick facts
Runtime and memory behavior at a glance.
Best
O(1)
Average
O(log n)
Worst
O(log n)
Space
O(n)
Show the same heap as a tree and as an array.
A heap gives quick access to the next priority item, not a sorted sequence.
What each reference supports for this entry.
Algorithms textbook support for Heap's invariant, correctness argument, and asymptotic analysis.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Data Structures · Core
Fibonacci heaps are heap variants that support meldable priority queues with amortized decrease-key efficiency.
Compare with thisData Structures · Core
A leftist heap is a pointer-based priority queue with heap order.
Compare with thisData Structures · Core
Min-max heaps are heap variants that maintain alternating min and max levels for double-ended priority queues.
Compare with thisData Structures · Core
Pairing heaps are heap variants that represent meldable priority queues with self-adjusting tree linking.
Compare with thisHeap Sort uses heap ordering to repeatedly extract extremal values.
Priority queues are commonly implemented with heaps.