11-heaps

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

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

Priority Queues (Heaps) CS216: Program and Data Representation University of Virginia Computer Science Spring 2009 Aaron Bloomfield

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

View Full Document
2 Topics • Priority queue ADT – Motivation – Model – Simple Implementations – Binary Heap • Applications of priority queues – Huffman encoding
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

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

View Full Document
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
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)

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

View Full Document
Binary Heap An implementation of priority queues
7 Binary Heap Properties 1. Structure Property 2. Ordering Property

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

View Full Document
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
Full Binary Tree • A binary tree in which each node has exactly zero or two children . – Also known as a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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
Ask a homework question - tutors are online