DS-chapter5(Priority Queues)

# DS-chapter5(Priority Queues) - CHAPTER 5 PRIORITY...

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

CHAPTER 5 PRIORITY QUEUES (HEAPS) 5.1 ADT Model Objects : A finite ordered list with zero or more elements. Operations : PriorityQueue Initialize( int MaxElements ); void Insert( ElementType X, PriorityQueue H ); ElementType DeleteMin( PriorityQueue H ); ElementType FindMin( PriorityQueue H ); —— delete the element with the highest \ lowest priority

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

View Full Document
5.2 Simple Implementations Array : Insertion — add one item at the end ~ Θ ( 1 ) Deletion — find the largest \ smallest key ~ Θ ( n ) remove the item and shift array ~ O( n ) Linked List : Insertion — add to the front of the chain ~ Θ ( 1 ) Deletion — find the largest \ smallest key ~ Θ ( n ) remove the item ~ Θ ( 1 ) Ordered Array : Insertion — find the proper position ~ O( n ) shift array and add the item ~ O( n ) Deletion — remove the first \ last item ~ Θ ( 1 ) Ordered Linked List : Insertion — find the proper position ~ O( n ) add the item ~ Θ ( 1 ) Deletion — remove the first \ last item ~ Θ ( 1 ) Better since there are never more deletions than insertions
Binary Search Tree : Simple Implementations Ah! That’s a good idea! Both insertion and deletion will take O(log N ) only. Well, insertions are random, but deletions are NOT. We are supposed to delete The minimum element only. Oh, right, then we must always delete from the left subtrees…. Oh no… what’s wrong? I bet you have a better option? Now you begin to know me

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

View Full Document
5.3 Binary Heap 1. Structure Property: H Definition R A binary tree with n nodes and height h is complete iff its nodes correspond to the nodes numbered from 1 to n in the perfect binary tree of height h .
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/16/2011 for the course CS 135 taught by Professor Yuechen during the Fall '08 term at Zhejiang University.

### Page1 / 17

DS-chapter5(Priority Queues) - CHAPTER 5 PRIORITY...

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

View Full Document
Ask a homework question - tutors are online