11-heaps

11-heaps - Spring 2009 CS216: Program and Data...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Priority Queues (Heaps) CS216: Program and Data Representation University of Virginia Computer Science Spring 2009 Aaron Bloomfield
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Topics • Priority queue ADT – Motivation – Model – Simple Implementations – Binary Heap • Applications of priority queues – Huffman encoding
Background image of page 2
3 Motivation • Multiuser environment – Operating system must choose which process to run on CPU • Management of limited resources – Bandwidth on network router • Limited bandwidth, but want to give best possible performance • Send traffic from highest priority queue first – VoIP
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Priority Queue ADT - Model • operations: – insert – deleteMin • finds, returns, and removes minimum element insert deleteMin 6 2 15 23 12 18 45 3 7
Background image of page 4
5 Implementations of Priority Queue ADT insert deleteMin Unsorted list (Array) Unsorted list (Linked-List) Sorted list (Array) Sorted list (Linked-List) BST AVL tree Hash Table Θ (1) Θ (N) Θ (1) Θ (N) Θ (N) Θ (N) Θ (N) Θ (1) worst: linear; avg: log Θ (log N) Θ (log N) often constant Θ (N) Would like: insert worst case O(log N), average case O(1) deleteMin worst and average case O(log N)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Binary Heap An implementation of priority queues
Background image of page 6
7 Binary Heap Properties 1. Structure Property 2. Ordering Property
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Some Definitions A Perfect (or Complete ) binary tree – A binary tree with all leaf nodes at the same depth. All internal nodes have 2 children. 25 9 2 21 5 11 30 7 10 1 3 16 13 19 22 height h 2 h+1 – 1 nodes 2 h – 1 non-leaves 2 h leaves NOTE: This example is not a heap, but a complete binary tree
Background image of page 8
Full Binary Tree • A binary tree in which each node has exactly zero or two children . – Also known as a
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 34

11-heaps - Spring 2009 CS216: Program and Data...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online