DS06_Ch05 - CHAPTER 5 PRIORITY QUEUES (HEAPS) delete the...

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

View Full Document Right Arrow Icon
CHAPTER 5 PRIORITY QUEUES (HEAPS) §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 1/15
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 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 2/15
Background image of page 2
Binary Search Tree : §2 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…. But hey, what if we keep a balanced tree? Hey you are getting smarter! Yes a balanced tree such as AVL tree is not a bad idea since only a constant factor will be added to the run time. However… Oh no… what’s wrong? There are many operations related to AVL tree that we don’t really need for a priority queue. Besides, pointers are always dangerous. I bet you have a better option? Now you begin to know me 3/15
Background image of page 3

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

View Full DocumentRight Arrow Icon
§3 Binary Heap 1. Structure Property: Definition 【 A binary tree with n nodes and height h is complete iff its nodes correspond to the nodes numbered from 1 to n
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/20/2011 for the course COMPUTER S 10586 taught by Professor Jilinwang during the Spring '09 term at Zhejiang University.

Page1 / 15

DS06_Ch05 - CHAPTER 5 PRIORITY QUEUES (HEAPS) delete the...

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

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