Tutorial 6

Priority Queues

Array Implementation

For a sorted list:

For an unsorted list:

Heaps

Heap Order

Last node

Insert into a Heap

  1. Insert at location z, the new last node
  2. Restore heap order (up heap)

RemoveMin for a heap

Array Based Heap implementation

Alt text

Heap sort

Heap construction

Given two heaps A and B,

  1. add a node kk as the root
  2. Downheap to restore heap order

Alt text