Lecture 10 - Priority Queue and Heap - 4 slides per page

Lecture 10- - Outline Priority Queue What is the ADT priority queue What are the operations supported heap(max-heap min-heap heapInsert(O(log N

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

View Full Document Right Arrow Icon
1 1 Priority Queue 2 Outline b What is the ADT priority queue? b What are the operations supported? b heap (max-heap, min-heap) s heapInsert (O(log N)) s heapDelete (O(log N)) s heapRebuild (O(log N)) s heapify (O(N)) b heapSort (O(N log N)) b STL priority queue 3 Readings b Required [Carrano and Prichard] ch11 4 What is a Priority Queue? A Special form of queue from which items are removed according to their designated priority and not the order in which they entered.
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 5 Examples b A “to-do” list with priorities b Scheduling jobs in OS b Queue at A&E of the hospital b Go to Takashimaya (1) b Play tennis (5) b Prepare CS1102C lecture slides (6) b Go to department tea (3) b 6 Priority queue operations b Create an empty priority queue b Insert an item with a given key b Remove the item with maximum key b Determine whether a priority queue is empty. 7 Unsorted list implementation b Insertion : add the element to end of a list O(1) b Deletion : traverse the list to find the element of maximum key and remove it O(n) What are the running times if we use sorted list? 8 Heap Heap is the most approriate data structure for realizing the ADT priority queue.
Background image of page 2
3 9 Definition b A (binary) heap is a complete binary tree satisfies the heap property : s for every node v , the search key in v is greater than or equal to those in the children of v. 7 1 3 2 9 10 Negative examples 12 8 9 4 3 6 7 2 1 5 12 8 7 4 3 5 9 2 1 not complete fail heap property 11 Compare heap with BST b Both are binary trees. b Difference s Heap maintains heap property . b It is not a search tree s BST maintains BST property . b It is a search tree 12 Representation using arrays 12 8 9 4 3 5 7 2 1 12 8 9 4 3 5 7 2 1 0 1 2 3 4 5 6 7 8 left(i) = 2*i+1 right(i) = 2*i+2 parent(i) = floor((i-1)/2)
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 13 Insert an item
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 08/02/2009 for the course ECE CS1102C taught by Professor Dr.tansuntuck during the Spring '07 term at National University of Singapore.

Page1 / 12

Lecture 10- - Outline Priority Queue What is the ADT priority queue What are the operations supported heap(max-heap min-heap heapInsert(O(log N

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