Heaps

Steven J. Zeil

Old Dominion University, Dept. of Computer Science

Table of Contents

1. Recap: the std Priority Queue Interface
1.1. A Peek at the Implementation
1.2. Priority Queues via Binary Search Trees
2. Implementing Priority Queues - the Heap
2.1. Binary Heaps
2.2. Heaps are complete trees
2.3. Children's Values are Smaller than Their Parent's
2.4. Bubbling and Percolating
2.5. Inserting into a heap
2.6. Shape Change After Insert
2.7. Removing from Heaps
3. Analysis
3.1. Building a Heap
4. Implementing the Heap with Iterators
4.1. push_heap
4.2. pop_heap
4.3. percolateDown
4.4. make_heap

Problem: Given a collection of elements that carry a numeric "score", find and remove the element with the smallest [largest] score. New elements may be added at any time.

In an earlier lesson, we saw that this collection is called a priority queue. Now we will look at an efficient way of implementing it.


In the Forum:

(no threads at this time)