Lecture 15

# Introduction to Algorithms, Second Edition

• Notes
• davidvictor
• 4

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

The University of Texas at Austin Lecture 15 Department of Computer Sciences Professor Vijaya Ramachandran Priority Queue; Heapsort CS357: ALGORITHMS, Spring 2006 1 Data Structures Sets manipulated by algorithms often grow, shrink or change over time, so we call these dynamic sets . To represent such dynamic sets and to manipulate them efficiently, we need to design good data structures . Over the next several classes we will look at several important data structures. We start with priority queue . 2 Priority Queue A priority queue maintains a dynamic set S of elements from a totally ordered set, so that the following operations can be performed efficiently: Insert ( S,x ): inserts element x , whose key value is given. Minimum ( S ): returns a pointer to an element in S with minimum key. Extract-min ( S ): returns an element with minimum key in S , and deletes that ele- ment from the priority queue. We often use an augmented priority queue that supports the following two operations, in addition to the three operations listed above. Decrease-key ( S,x,k ): given a pointer to element x in S , updates the key value of element x to min( key ( x ) ,k ). Delete ( S,x ): given a pointer to element x in S , removes x from S . (One can also define a ‘max-priority-queue’ in which the ‘Minimum’ and ‘min’ in the above operations are replaced by ‘Maximum’ and ‘max’.)

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

2.1 Binary Heap A heap structure on n elements is an ordered binary tree on n nodes that is as complete as possible; if the lowest level is not full, then it is filled in completely from the left end. For a node v in this binary tree, we denote its left child by left ( v ), its right child by right ( v ), and its parent by parent ( v ) or p ( v ). We use NIL to denote that a field is empty.
This is the end of the preview. Sign up to access the rest of the document.
• Spring '06
• Ramachandran

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern