### PRIORITY QUEUES STUDY GUIDE

**Heaps**.
A max (min heap is an array representation of a binary tree such that every node is larger (smaller)
than all of its children. This definition
naturally applies recursively, i.e. a heap of height 5 is composed of two heaps of height 4 plus a parent.
Why do we leave the 0th position empty in the array?

**Running times of various PQ implementations**.
Know the running time of the three primary PQ operations for an unordered array, ordered array, and heap implementation.

**Heapsort**.
A max PQ provides an easy algorithm for putting items in ascending order. We simply insert everything into the PQ and then
delete the max until the PQ is empty. By using a binary heap, we can sort in place - this is somewhat subtle.

**Heapify**. Understand how the bottom up heapify process works. Know that it is linear time.

### Recommended Problems

Note: The reason I've given lots of problems here is not because this is
a more important topic, but because there are just so many interesting problems.
#### C level

- Textbook 2.4.2 (assume we'd also like to support delete operations)
- Textbook 2.4.4
- Textbook 2.4.11, 2.4.12
- Textbook 2.4.14
- Spring 2008 #5, Fall 2008 #4, Fall 2009 #3, etc.

#### B level

- Textbook 2.4.7
- Textbook 2.4.10
- Textbook 2.4.17, how could you use this technique to find the kth largest item?
What would be the runtime of this algorithm in terms of N and k?
- Textbook 2.4.21
- Textbook 2.4.27
- Textbook 2.4.32 (easier than it looks)
- Spring 2008 Midterm #4
- Fall 2012 Midterm #4
- Spring 2013 Midterm #5a and #5b

#### A level

- Prove that bottom up heapify runs in linear time.
- Textbook 2.4.29
- Textbook 2.4.30 (great problem!)
- Fall 2010 Midterm #7
- Spring 2012 Midterm #8