Data Structures & Algorithms Lecture Notes

17 November 2010 • Heaps and Priority Queues


Outline

Array-Based Trees

Storing Trees In Arrays

Binary Tree Indexing

Tree-Array Space Requirements

Heaps

Heap Characteristics

Heap ADT

Other Heap Operations

Heap ADT Implementation

Heap Add

i = count++
d[i] = e
while i ≠ 0
  p = (i - 1)/2
  if d[p] ≥ d[i], break
  swap(d[p], d[i])
  i = p

  1. Bubble up the new element until it has a larger parent.
    • Or it becomes the root.

Example Heap Add

Heap Remove

Example Heap Remove

Heap Remove

Priority Queues

Heaps as Priority Queues

Summary


This page last modified on 16 November 2010.

Creative
    Commons License