Adaptable Priority Queues

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of.
Advertisements

Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Data Structures Lecture 7 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
The Priority Queue Abstract Data Type. Heaps. Adaptable Priority Queue. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich,
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
© 2004 Goodrich, Tamassia Priority Queues1 Heaps: Tree-based Implementation of a Priority Queue.
© 2004 Goodrich, Tamassia Priority Queues1. © 2004 Goodrich, Tamassia Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection.
Chapter 8: Priority Queues
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Priority Queue Sorting (§ 8.1.4) We can use a priority queue to sort a set.
Priority Queues1 Part-D1 Priority Queues. Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is.
Chapter 8: Priority Queues and Heaps Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided.
© 2004 Goodrich, Tamassia Priority Queues1. © 2004 Goodrich, Tamassia Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection.
Heaps and Priority Queues Priority Queue ADT (§ 2.4.1) A priority queue stores a collection of items An item is a pair (key, element) Main.
Adaptable Priority Queues1 3 a 5 g 4 e © 2010 Goodrich, Tamassia.
Priority Queues & Heaps Chapter 9. Iterable Collection Abstract Collection Queue List Abstract Queue Priority Queue Array List Abstract List Vector Stack.
Priority Queues and Heaps. Outline and Reading PriorityQueue ADT (§8.1) Total order relation (§8.1.1) Comparator ADT (§8.1.2) Sorting with a Priority.
Chapter 2.4: Priority Queues and Heaps PriorityQueue ADT (§2.4.1) Total order relation (§2.4.1) Comparator ADT (§2.4.1) Sorting with a priority queue (§2.4.2)
CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
1 Heaps A heap is a binary tree. A heap is best implemented in sequential representation (using an array). Two important uses of heaps are: –(i) efficient.
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Priority Queues Last Update: Oct 23, 2014 EECS2011: Priority Queues1.
Adaptable Priority Queues1 3 a 5 g 4 e © 2013 Goodrich, Tamassia, Goldwasser.
1 COMP9024: Data Structures and Algorithms Week Seven: Priority Queues Hui Wu Session 1, 2016
Adaptable Priority Queues1 3 a 5 g 4 e © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java,
Sorting With Priority Queue In-place Extra O(N) space
Priority Queues 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Priority Queues Chuan-Ming Liu
COMP9024: Data Structures and Algorithms
09 Priority Queues Hongfei Yan Apr. 27, 2016.
Part-D1 Priority Queues
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Bohyung Han CSE, POSTECH
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Priority Queues © 2014 Goodrich, Tamassia, Goldwasser Priority Queues
Heaps and Priority Queues
Priority Queues and Heaps
Part-D1 Priority Queues
Heaps and Priority Queues
Priority Queues 4/6/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Heaps 11/27/ :05 PM Heaps Heaps.
Locators 3 a 1 g 4 e 12/1/2018 4:40 AM Locators Locators
B-Tree Insertions, Intro to Heaps
Tree Representation Heap.
Heaps A heap is a binary tree.
Heaps and Priority Queues
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Ch. 8 Priority Queues And Heaps
Priority Queues Sell 100 IBM $ $120 Buy 500 $ $118
Doubly Linked Lists or Two-way Linked Lists
Locators 3 a 1 g 4 e 12/29/2018 7:56 AM Locators Locators
Heaps and Priority Queues
Priority Queues Sell 100 IBM $ $120 Buy 500 $ $118
© 2013 Goodrich, Tamassia, Goldwasser
Heaps II Implementation HeapSort Bottom-Up Heap Construction Locators.
CH 9 : Maps And Dictionary
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Lecture 9 CS2013.
Heaps and Priority Queues
Priority Queues © 2010 Goodrich, Tamassia Priority Queues
1 Lecture 10 CS2013.
CS210- Lecture 15 July 7, 2005 Agenda Median Heaps Adaptable PQ
CS210- Lecture 14 July 5, 2005 Agenda Inserting into Heap
Heaps 9/29/2019 5:43 PM Heaps Heaps.
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Data Structures & Programming
Presentation transcript:

Adaptable Priority Queues Locators 2/23/2019 1:31 PM 3 a 5 g 4 e Adaptable Priority Queues © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Items and Priority Queues Locators 2/23/2019 1:31 PM Items and Priority Queues An item stores a (key, value) pair Item fields: _key: the key associated with this item _value: the value paired with the key associated with this item Priority Queue ADT: add(k, x) inserts an item with key k and value x remove_min() removes and returns the item with smallest key min() returns, but does not remove, an item with smallest key len(P), is_empty() © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

standby airline passenger application A standby passenger with a pessimistic attitude may become tired of waiting and decide to leave ahead of the boarding time Another standby passenger finds her gold frequent-flyer card and shows it to the agent © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Methods of the Adaptable Priority Queue ADT remove(loc): Remove from P and return item e for locator loc. update(loc,k,v): Replace the key-value pair for locator, loc, with (k,v). © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Adaptable Priority Queues Locators 2/23/2019 1:31 PM Locators A locator-aware item identifies and tracks the location of its (key, value) object within a data structure Intuitive notion: Coat claim check Valet claim ticket Reservation number Main idea: Since items are created and returned from the data structure itself, it can return location-aware items, thereby making future updates easier © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Adaptable Priority Queues List Implementation A location-aware list item is an object storing key value position (or rank) of the item in the list In turn, the position (or array cell) stores the entry Back pointers (or ranks) are updated during swaps trailer header nodes/positions 2 c 4 c 5 c 8 c items © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Adaptable Priority Queues Heap Implementation A location-aware heap item is an object storing key value position of the item in the underlying heap In turn, each heap position stores an item Back pointers are updated during item swaps 2 d 4 a 6 b 8 g 5 e 9 c © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues

Adaptable Priority Queues Performance Improved times thanks to location-aware items are highlighted in red Method Unsorted List Sorted List Heap len, is_empty O(1) O(1) O(1) add O(1) O(n) O(log n) min O(n) O(1) O(1) remove_min O(n) O(1) O(log n) remove O(1) O(1) O(log n) update O(1) O(n) O(log n) © 2013 Goodrich, Tamassia, Goldwasser Adaptable Priority Queues