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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern