DS-chapter5(Priority Queues)

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

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) 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
5.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 in the perfect binary tree of height h . 4 8 9 5 10 11 6 12 13 7 14 15 2 3 1 A complete binary tree of height h has between and nodes.
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.

Page1 / 17

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

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