{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture_8_-_Priority_queue_and_Heap_-_single_slide

# Lecture_8_-_Priority_queue_and_Heap_-_single_slide -...

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

1 Priority Queue

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

View Full Document
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.
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

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

View Full Document
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.
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?

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

View Full Document
8 Heap Heap is the most approriate data structure for realizing the ADT priority queue.
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

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. box4 Difference square6 Heap maintains heap property .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}