{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture_8_-_Priority_Queue_and_Heap_-_3in1_with_notes

# Lecture_8_-_Priority_Queue_and_Heap_-_3in1_with_notes -...

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

1 Priority Queue 2 Outline box4 What is the ADT priority queue? box4 What are the operations supported? box4 heap (max-heap, min-heap) square6 heapInsert (O(log N)) square6 heapDelete (O(log N)) square6 heapRebuild (O(log N)) square6 heapify (O(N)) box4 heapSort (O(N log N)) box4 STL priority queue 3 Readings box4 Required [Carrano and Prichard] ch11

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

View Full Document
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. Normal queue is first-in- first-out. In priority queue, dequeue will remove the item with the highest priority. 5 Examples box4 A “to-do” list with priorities box4 Scheduling jobs in OS box4 Queue at A&E of the hospital box4 Go to Takashimaya (1) box4 Play tennis (5) box4 Prepare CS1102C lecture slides (6) box4 Go to department tea (3) box4 We have a set of items with priority and want to remove item with the highest priority every time. 6 Priority queue operations box4 Create an empty priority queue box4 Insert an item with a given key box4 Remove the item with maximum key box4 Determine whether a priority queue is empty. Notice that we are talking about the same set of three operations throughout the course.
7 Unsorted list implementation box4 Insertion : add the element to end of a list O(1) box4 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? With Sorted list: Insertion is O(n) and deletion is O(1) 8 Heap Heap is the most approriate data structure for realizing the ADT priority queue. Heap is a data structure that implements the priority queue ADT efficiently and conveniently. 9 Definition box4 A (binary) heap is a complete binary tree satisfies the heap property : square6 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 A heap is not a binary search tree. That is, the keys on the right subtree could be smaller than the key on the left subtree.

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

View Full Document
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 box4 Both are binary trees.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

Lecture_8_-_Priority_Queue_and_Heap_-_3in1_with_notes -...

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

View Full Document
Ask a homework question - tutors are online