### 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

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

#### B level

1. Textbook 2.4.7
2. Textbook 2.4.10
3. 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?
4. Textbook 2.4.21
5. Textbook 2.4.27
6. Textbook 2.4.32 (easier than it looks)
7. Spring 2008 Midterm #4
8. Fall 2012 Midterm #4
9. Spring 2013 Midterm #5a and #5b

#### A level

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