Heap
A binary heap is an almost complete binary tree in which each parent obeys an ordering property relative to its children, allowing efficient access to a minimum or maximum element.
Advanced Algorithms and Data Structures
A binary heap is a complete binary-tree-based priority queue in which each node has priority at least as high as every node in its subtree.
- How it is used
- Implements a priority queue for processing tasks or other elements by priority.
- How deep it goes
- Develops array invariants, index formulas, repair operations, bottom-up construction, and time–space costs.
- Examples
- Uses prioritized tasks, tree-to-array diagrams, heapification steps, the k-largest-elements problem, and shortest paths.
- What you can do after
- Build it from scratch with array indexing, heap-property repair, and bottom-up heapify; evaluate lookup and branching-factor trade-offs.
Read how Advanced Algorithms and Data Structures explains heap →
Grokking Data Structures
A binary heap is a heap represented as a binary, almost complete tree in which each node satisfies the heap ordering property relative to its children.
- How it is used
- Implements a priority queue that removes the highest-priority item rather than the earliest inserted item.
- How deep it goes
- Works through tree properties, array storage, insertion, removal, and bottom-up heap construction, without a formal height proof.
- Examples
- Uses a bug queue and the insertion of a high-priority broken-login report to illustrate bubble-up.
- What you can do after
- Build it from scratch with a Python list, including insert, top, and linear-time heapify.
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
A binary heap is a tree-shaped priority-queue implementation that maintains an ordering relationship between parents and children.
- How it is used
- Uses a priority queue to select the next A* frontier state by lowest estimated total cost.
- How deep it goes
- Defines heap-backed priority queues and operation costs but defers the heap's internal implementation.
- Examples
- Demonstrates heap-backed ordering through Swift A* maze searches using node cost and Manhattan distance.
- What you can do after
- Apply it via SwiftPriorityQueue when implementing A* frontier selection.
The Coder Cafe
A binary heap is a complete binary tree that maintains a heap-order property for efficiently retrieving a minimum or maximum element.
- How it is used
- Supports priority queues and other workloads requiring quick access to the minimum or maximum element.
- How deep it goes
- Defines tree and array representations, explains heapify operations, and gives operation and construction complexities.
- Examples
- Uses a max-heap containing 39 at array index 1 to demonstrate child and parent calculations.
- What you can do after
- Build it from scratch by choosing min- or max-order, storing elements in an array, and implementing core heap operations.
Also covered in
- Python Concurrency with asyncio
- 100 SQL Server Mistakes and How to Avoid Them
- Machine Learning Algorithms in Depth
- Learn Rust in a Month of Lunches
- Grokking Algorithms, Second Edition
What to know first
- priority queueA priority queue is an abstract data type that retrieves or removes elements according to assigned priority rather than insertion order.
- queueA queue is an ordered collection that holds items for retrieval or processing, commonly in first-in, first-out order.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- logarithmic time complexityAn algorithmic running-time growth rate proportional to the logarithm of the input size, commonly expressed as O(log n).
Related concepts
- min-heapincludes · A min-heap is a heap-ordered tree in which each parent has a value or priority no greater than its children, placing a minimum element at the root.
- priority queueimplements · A priority queue is an abstract data type that retrieves or removes elements according to assigned priority rather than insertion order.
- max heapincludes · A max heap is a heap-ordered data structure in which each parent is no smaller than its children, making a maximum element available at the root.
- binary treekind of · A binary tree is a tree data structure in which each node has at most two children.
- arrayuses · An array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- heapifyproduced by · Heapify is the process of rearranging an unordered collection to satisfy the invariant of a valid heap.
Questions about heap
What is heap?
A binary heap is an almost complete binary tree in which each parent obeys an ordering property relative to its children, allowing efficient access to a minimum or maximum element.
Which Manning books explain heap?
Advanced Algorithms and Data Structures, Grokking Data Structures, Classic Computer Science Problems in Swift: Essential techniques for practicing programmers and The Coder Cafe.
What should I know before learning heap?
Manning books that teach heap usually introduce priority queue, queue, array and logarithmic time complexity first.
What kinds of heap are there?
Kinds of heap include min-heap and max heap.
What is heap a kind of?
Heap is a kind of binary tree. A binary tree is a tree data structure in which each node has at most two children.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



