Overview

Published

2023-08-06

This week we’ll introduce the binary heap and some variations and applications (specifically priority queue). Binary heap is different from heap memory so don’t be confused. Binary heap is a tree-based data structure with additional properties—the heap order property and the structure (or shape) property.

The heap order property has two definitions, depending on whether or not we have a max heap (maximum value at the root) or a min heap (minimum value at the root). These are:

Obviously, only one of these properties can hold for a given heap. The important thing is that these place a constraint on the values in the tree.

The other property is the structure property—that the binary tree must be complete—that is each level must be fully populated with the exception of the last, which if not full, must be populated from left to right. The videos will explain this in more detail.

We will also cover priority queues—a common and important application of binary heaps—and d-heaps, which are a variant form of heap.

We’ll also take a peek at sorting (to be covered in more detail over the following two weeks), and we’ll see our first sorting algorithm: bubble sort.

If you haven’t completed last week’s material and taken Quiz 05, please do so before proceeding. Have fun!

Learning Objectives

By the end of this module, you will be able to:

  • use a binary heap to implement a priority queue, and
  • implement the bubble sort algorithm.

To achieve this module’s objectives, complete the following:

Read: Essential Algorithms, pp. 127–128, 131–144 (Chapter 6)

Read / view the following content and complete any comprehension checks:

  • Binary heaps
  • Priority queue
  • d-heaps
  • Introduction to sorting

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.