{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture_8_-_Priority_queue_and_Heap_-_single_slide

Lecture_8_-_Priority_queue_and_Heap_-_single_slide -...

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

View Full Document Right Arrow Icon
1 Priority Queue
Background 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 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
Background image of page 2
3 Readings box4 Required [Carrano and Prichard] ch11
Background image of page 3

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

View Full Document Right Arrow Icon
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 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
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.
Background image of page 6
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?
Background image of page 7

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

View Full Document Right Arrow Icon
8 Heap Heap is the most approriate data structure for realizing the ADT priority queue.
Background image of page 8
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
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
11 Compare heap with BST box4 Both are binary trees. box4 Difference square6 Heap maintains heap property .
Background image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}