An Optimal Cache-Oblivious Priority Queue and Its Applications in Graph Algorithms By Arge, Bender, Demaine, Holland-Minkley, Munro Presented by Adam Sheffer.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Order Statistics. order - 2 Lin / Devi Comp 122 Order Statistic i th order statistic: i th smallest element of a set of n elements.
Advertisements

Lecture 15. Graph Algorithms
I/O-Algorithms Lars Arge Spring 2012 April 17, 2012.
Planar point location -- example
COP 3502: Computer Science I (Note Set #21) Page 1 © Mark Llewellyn COP 3502: Computer Science I Spring 2004 – Note Set 21 – Balancing Binary Trees School.
Chapter 4: Trees Part II - AVL Tree
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
Practice Quiz Question
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 24 Sorting.
F00 pq 1 Priority Queues Review the abstract data type Priority Queues Review different implementation options.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
B-Trees. Motivation for B-Trees Index structures for large datasets cannot be stored in main memory Storing it on disk requires different approach to.
I/O-Algorithms Lars Arge Spring 2009 February 2, 2009.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Tirgul 9 Amortized analysis Graph representation.
I/O-Algorithms Lars Arge Aarhus University February 16, 2006.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
I/O-Algorithms Lars Arge Aarhus University April 16, 2008.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
CSC 2300 Data Structures & Algorithms March 20, 2007 Chapter 7. Sorting.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Advanced Topics in Algorithms and Data Structures 1 Two parallel list ranking algorithms An O (log n ) time and O ( n log n ) work list ranking algorithm.
Cache-Oblivious Dynamic Dictionaries with Update/Query Tradeoff Gerth Stølting Brodal Erik D. Demaine Jeremy T. Fineman John Iacono Stefan Langerman J.
ANALYSIS OF SOFT HEAP Varun Mishra April 16,2009.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
INTRODUCTION TO MULTIWAY TREES P INTRO - Binary Trees are useful for quick retrieval of items stored in the tree (using linked list) - often,
Data Structures Week 8 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
Lars Arge Presented by Or Ozery. I/O Model Previously defined: N = # of elements in input M = # of elements that fit into memory B = # of elements per.
CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 12: Multi-way Search Trees Java Software Structures: Designing.
Linked List by Chapter 5 Linked List by
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
Equivalence Between Priority Queues and Sorting in External Memory
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Internal and External Sorting External Searching
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 25 Sorting.
Funnel Sort*: Cache Efficiency and Parallelism
Week 15 – Friday.  What did we talk about last time?  Student questions  Review up to Exam 2  Recursion  Binary trees  Heaps  Tries  B-trees.
B-Trees Katherine Gurdziel 252a-ba. Outline What are b-trees? How does the algorithm work? –Insertion –Deletion Complexity What are b-trees used for?
8/3/2007CMSC 341 BTrees1 CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 23 Sorting.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Heaps, Heap Sort, and Priority Queues. Background: Binary Trees * Has a root at the topmost level * Each node has zero, one or two children * A node that.
Chapter 23 Sorting Jung Soo (Sue) Lim Cal State LA.
Design & Analysis of Algorithm Priority Queue
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Priority Queues Chuan-Ming Liu
Analysis and design of algorithm
Arrays and Linked Lists
Enumerating Distances Using Spanners of Bounded Degree
Priority Queue and Binary Heap Neil Tang 02/12/2008
B- Trees D. Frey with apologies to Tom Anastasio
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Lecture 2- Query Processing (continued)
B- Trees D. Frey with apologies to Tom Anastasio
CSE 373 Data Structures and Algorithms
Heaps & Multi-way Search Trees
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

An Optimal Cache-Oblivious Priority Queue and Its Applications in Graph Algorithms By Arge, Bender, Demaine, Holland-Minkley, Munro Presented by Adam Sheffer

Priority Queue – A Reminder Maintains a set of elements, each with a priority. Supports insert and delete-min operations. Priority Queue Insert(A,2) Insert(B,4) Insert(D,3) Insert(C,4) Delete-min Insert(E,7) Delete-min Insert(F,4) A D

Cache Oblivious Alg. – A Reminder and are defined as usual. The algorithm cannot use and An optimal paging strategy is assumed. The “tall-cache” assumption: The analysis can assume memory. Standard Notations:

“An Optimal Cache-Oblivious "Priority Queue In order to discuss optimality, a lower bound is required. In [Aggarwal & Vitter ’88], it was proved that the number of memory transfers required for sorting is If we can perform both insert and delete-min with only memory transfers, we can achieve a more efficient sorting.

An Optimal Solution? Why not just use a cache-oblivious B-tree? Inserting elements into a B-tree takes We are lacking a factor of:

The Optimal Priority Queue We want a queue which performs both insert and delete-min with memory transfers. For certain reasonable values: We need an amortized analysis. ?

Similar Work [Brodal and Fagerberg ‘02] presents the funnel heap. This is a cache oblivious priority queue, with exactly the same results. [Brodal et al. ‘04] presents a cache oblivious priority queue which also supports the update operation, with memory transfers. [Chowdhury and Ramachandran ’04] supports the decrease-key operation, with the same results.

The Main Data Structure Level holds cells. The last level holds at most cells.

The Inside of a Single Level The elements inside a buffer are not ordered. … Buffers

An Order Between Levels Elements in the last down-buffer of level have a smaller priority than elements in the first down- buffer of level. There is no order between up buffers.

The Space Complexity of the DS We verify that the size of the largest buffer is, by occasionally performing a global rebuilding (explained later on). We can store the buffers consecutively in a large array, with a size of

The Push Operation The operation pushes input elements into level. Works as follows: –First, the input elements are sorted. –By scanning through the down buffers, each input element is appended to the end of the appropriate buffer. –Input elements with a larger priority than the elements in the down buffer, are appended into the end of the up buffer.

An Illustrated Push

The Push Operation (cont.) When a down-buffer grows to a size of, it will be split into two buffers with a size of. If there are already down buffers, the last down-buffer is moved into the up-buffer. When the up-buffer is full, its elements are recursively pushed into level.

Another Illustrated Push … Buffers Push Too Much

Another Illustrated Push … Buffers Too Much Recursive push

The Pull Operation The operation pulls the elements with the lowest priority from level. –When there are not enough elements in the down buffers, a recursive pull is performed.

Finally, The Algorithm Two additional buffers, each with cells: –The insertion buffer holds the most recently inserted elements. –The deletion buffer holds the elements with the smallest priority (sorted). Both buffers are constantly maintained in the memory.

The Insert Operation An insert operation moves the new element into the end of the insertion buffer. When the buffer is full, its elements are pushed into the lowest level of the DS. Insertion buffer Insert(A,5) Push

The Delete-Min Operation A delete-min removes the first element of the deletion buffer. When the buffer is empty, we pull elements from the lowest level of the DS (and sort them). Deletion buffer delete-min() Pull

A Slight Correction What if an inserted element has a lower priority than the last element in the deletion buffer? The last element from the deletion buffer is moved into the insertion buffer. The new element is moved into the deletion buffer Deletion Insertion Insert

Amortized Analysis of a Push Inserting elements into level. Sorting the input elements. Scanning through the down buffers, and appending the appropriate elements to them. Appending the rest of the elements to the end of the up buffer. Splitting overfull down-buffers. Moving down-buffers to the end of the up-buffer. Recursive pushes. Ignore

Amortized Analysis of a Push Splitting one down-buffer with elements, into two with elements. In [Frigo et al. ’99], it was shown how to compute a median in Therefore, a split takes memory transfers. At least elements are inserted into a buffer before it splits. For each element that a push operation inserts into a block, it will pay. This can also pay for the moving of a down buffer into the up buffer.

Amortized Analysis of a Push Inserting elements into level. Sorting the input elements. Scanning through the down buffers, and appending the appropriate elements to them. Appending the rest of the elements to the end of the up buffer. Splitting overfull down-buffers. Moving down-buffers to the end of the up-buffer. Recursive pushes. Ignore

Amortized Analysis of a Push Scanning through the down buffers, and appending the appropriate elements to them: There are down buffers. Tall cache assumption – All levels of size can be constantly kept in memory. Therefore, we may assume that If then We are left with the case where Applies for a single level, with at most down buffers. A block from each buffer can permanently kept in memory.

Amortized Analysis of a Push Inserting elements into level. Sorting the input elements. Scanning through the down buffers, and appending the appropriate elements to them. Appending the rest of the elements to the end of the up buffer. Splitting overfull down-buffers. Moving down-buffers to the end of the up-buffer. Recursive pushes. Ignore

Amortized Analysis of a Push A push of elements into level can be performed in amortized number of memory transfers, not counting recursive push operations. A pull of elements from level, can be analyzed for the results.

Analysis of Insert Increases the size of the insertion buffer by one. Causes memory transfers if and only if the insertion buffer is full. We need the amortized number of memory transfers to be

A Potential Function Level - Push coin Level - Pull coin

Spreading the Coins? Each element in the insertion buffer has a push coin and a pull coin for every level of the DS. On level, each element in the first half of a down buffer has a pull coin for every level On level, each element in the second half of a down buffer, or in the up buffer, has a push coin for every level, and a pull coin for all levels.

Amortized Cost of an Insert An insert operation adds a single element to the insertion buffer. This element needs a push coin and a pull coin for every level in the DS. The cost of an insert is:

Paying for a Push Operation Pushing the elements of the up buffer of level into level. Before the push, each element had a push coin for every level and a pull coin for every level. After the push, in the worst case, each element needs a push coin for every level and a pull coin for every level. We get at least spare coins, each worth These pay for the memory transfers of the push.

Splitting a Buffer

Moving Up a Down Buffer When moving a down buffer into an up buffer, we will need additional push coins for each level, and additional pull coins for each level. This is exactly the number of coins which were released due to the split.

Summing Up the Analysis A similar analysis shows that the coins pay for the pull operations. An insert operation costs amortized memory transfers. A delete-min operation is free, since it does not add any coins.

Global Rebuilding In order to maintain, we rebuild the DS after every operations. At each rebuild, we define Level holds an empty up buffer, and down buffers, each with elements. Level has at most down buffers with elements, and a single buffer with fewer elements. The global rebuilding can be done by sorting and scanning, using memory transfers.

Global Rebuilding (cont.) After the rebuilding, every element is in the first half of a down buffer, so there are no push coins. We bound the cost of all the pull coins, by assuming that they are all in level

Global Rebuilding (cont.) The cost of the global rebuilding is We will split it between the operations that occurred since the last rebuilding. This means that both insert and delete-min take (amortized memory transfers)

The Delete Operation It is possible to support a delete operation, which takes amortized memory transfers. The input for the operation is the id of the element and its priority.

The Delete Operation (cont.) Elements with the same priority are ordered according to their id. When a delete operation occurs, a special delete element is inserted, with the priority and id of the input.

The Delete Operation (cont.) A delete-min operation checks if the two first elements in the deletion buffer have the same id. If so, it throws them away and starts over. - {9,G} {6,E} {2,D} Deletion buffer Delete-min()

The Delete Operation (cont.) A delete-min operation will check if the two first elements in the deletion buffer have the same id. If so, it will throw them away and start over. - {9,G} {6,E} Deletion buffer Delete-min() - - E

The Delete Operation (cont.) In a global rebuilding, every element pair with the same id will be removed before choosing 5,E5,F5,E3,J5,K7,A 9,B 5,E5,F5,E3,J5,K7,A 9,B

Application for the Priority Queue.

List Ranking We are given a linked list with weights on the edges (or an array, with each of its cells containing the position of the next). We need to rank each node according to its weighted distance from the end of the list.

List Ranking We are given a linked list with weights on the edges (or an array, with each of its cells containing the position of the next) We need to rank each node according to its weighted distance from the end of the list.

High-Level Algorithm Find an independent set of size Bridge-out the nodes from the set.

High-Level Algorithm Find an independent set of size Bridge-out the nodes from the set. Remove nodes from list and solve recursively.

High-Level Algorithm Find an independent set of size Bridge-out the nodes from the set. Remove nodes from list and solve recursively. Reinsert the nodes and fix the list.

High-Level Algorithm Find an independent set of size Bridge-out the nodes from the set. Remove nodes from list and solve recursively. Reinsert the nodes and fix the list

Bridging Out Create a second copy of the list and sort it by successor position. ABCDEFGH EABGCHFD

Bridging Out (cont) Traverse both lists simultaneously. For each node which precedes a marked cell, add the position of the marked node’s successor. ABCDEFGH EABGCHFD

Removing Marked Elements Scan the list again, and move the unmarked nodes into a new list. During the scan, maintain another list of old and new node positions. Sort the first list by successor position. Scan the two lists simultaneously to fix the successors positions.

Reinserting Marked Elements Reinsert the nodes from the independent set, and update the ranks. This can be done by using a few scans and sorts, as in the bridge-out phase

List Ranking Analysis Assuming that the independent set can be found in memory transfers, we achieve the following recurrence relation:

Independent Set We will show how to compute a 3-coloring of the list. We can choose the most common color to be the independent set. ABCDEFGH

3-Coloring Split the list into forward running sub-lists and backward running sub-lists. ABCDEFGH Each node is a member of a single list, unless it is the head of one list and the tail of another.

Coloring a Forward List In a forward list, we color the first node in grey, and then alternate between red and grey. ACFH

Coloring a Backward List BEGH In a backward list, we color the first node in orange, and then alternate between red and orange.

3-Coloring (cont.) A node which gets a color as a head and a different color as a tail, is colored with the color of the head. ABCDEFGH

Cache Oblivious 3-Coloring We show how to cache-obliviously color the forward lists: –Find all the head nodes. (Can be achieved by making a duplicated list, sorting it by successor position, and performing a simultaneous scan on both lists). –Color the head nodes in grey. –Create a priority queue. For each head node, insert a red element with the position of the node’s successor as its priority. –While the queue is not empty, remove the minimum node, color it, and if its successor is in a higher position in the list, enter it into the queue (with the other color).

Summing Up We can find a 3-coloring with (amortized) memory transfers. We can find an independent set with (amortized) memory transfers. We can perform a list ranking with (amortized) memory transfers.