1 / 8

Adaptable Priority Queues

a. 3. g. e. 5. 4. Adaptable 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

colemichael
Download Presentation

Adaptable Priority Queues

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. a 3 g e 5 4 Adaptable Priority Queues Adaptable Priority Queues

  2. 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() Items and Priority Queues Adaptable Priority Queues

  3. 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 Adaptable Priority Queues

  4. 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). Adaptable Priority Queues

  5. 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 Adaptable Priority Queues

  6. 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 nodes/positions header c c 5 8 c c 2 4 items Adaptable Priority Queues

  7. Heap Implementation d 2 • 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 a b 4 6 g e c 8 5 9 Adaptable Priority Queues

  8. Performance • Improved times thanks to location-aware items are highlighted in red Method Unsorted List Sorted List Heap len, is_emptyO(1) O(1) O(1) addO(1) O(n) O(log n) minO(n) O(1) O(1) remove_minO(n) O(1) O(log n) removeO(1)O(1)O(logn) updateO(1)O(n) O(logn) Adaptable Priority Queues

More Related