Equivalence Between Priority Queues and Sorting in External Memory

Slides:



Advertisements
Similar presentations
Dynamic Graph Algorithms - I
Advertisements

Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
On RAM PRIORITY QUEUES MIKKEL THORUP. Objective Sorting is a basic technique for a lot of algorithms. e.g. find the minimum edge of the graph, scheduling,
Hierarchy-conscious Data Structures for String Analysis Carlo Fantozzi PhD Student (XVI ciclo) Bioinformatics Course - June 25, 2002.
I/O-Efficient Batched Union-Find and Its Applications to Terrain Analysis Pankaj K. Agarwal, Lars Arge, Ke Yi Duke University University of Aarhus.
I/O-Algorithms Lars Arge University of Aarhus February 21, 2005.
I/O-Algorithms Lars Arge Aarhus University February 27, 2007.
Micha Streppel TU Eindhoven  NCIM-Groep, the Netherlands and Ke Yi AT&T Labs, USA  HKUST, Hong Kong.
I/O-Algorithms Lars Arge Spring 2011 March 8, 2011.
I/O Efficient Algorithms. Problem Data is often too massive to fit in the internal memory The I/O communication between internal memory (fast) and external.
I/O-Algorithms Lars Arge Aarhus University February 13, 2007.
I/O-Algorithms Lars Arge Spring 2009 February 2, 2009.
Cache-Oblivious Priority Queue and Graph Algorithm Applications Presented by: Raz Berman and Dan Mor.
I/O-Algorithms Lars Arge Spring 2009 January 27, 2009.
I/O-Algorithms Lars Arge Spring 2007 January 30, 2007.
I/O-Algorithms Lars Arge Aarhus University February 16, 2006.
I/O-Algorithms Lars Arge Aarhus University February 7, 2005.
I/O-Algorithms Lars Arge University of Aarhus February 13, 2005.
I/O-Algorithms Lars Arge University of Aarhus March 1, 2005.
I/O-Algorithms Lars Arge Spring 2009 March 3, 2009.
FALL 2006CENG 351 Data Management and File Structures1 External Sorting.
I/O-Algorithms Lars Arge Aarhus University February 6, 2007.
I/O-Algorithms Lars Arge Spring 2006 February 2, 2006.
I/O-Algorithms Lars Arge Aarhus University March 5, 2008.
I/O-Efficient Structures for Orthogonal Range Max and Stabbing Max Queries Second Year Project Presentation Ke Yi Advisor: Lars Arge Committee: Pankaj.
I/O-Algorithms Lars Arge Aarhus University February 14, 2008.
Comparison Based Dictionaries: Fault Tolerance versus I/O Efficiency Gerth Stølting Brodal Allan Grønlund Jørgensen Thomas Mølhave University of Aarhus.
I/O-Efficient Batched Union-Find and Its Applications to Terrain Analysis Pankaj K. Agarwal, Lars Arge, and Ke Yi Duke University University of Aarhus.
I/O-Algorithms Lars Arge University of Aarhus March 7, 2005.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
Cache Oblivious Search Trees via Binary Trees of Small Height
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
5.9 Heaps of optimal complexity
I/O-Algorithms Lars Arge Spring 2008 January 31, 2008.
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.
Problems and MotivationsOur ResultsTechnical Contributions Membership: Maintain a set S in the universe U with |S| ≤ n. Given an x in U, answer whether.
Bin Yao Spring 2014 (Slides were made available by Feifei Li) Advanced Topics in Data Management.
An Optimal Cache-Oblivious Priority Queue and Its Applications in Graph Algorithms By Arge, Bender, Demaine, Holland-Minkley, Munro Presented by Adam Sheffer.
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.
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
I/O-Efficient Batched Union-Find and Its Applications to Terrain Analysis Pankaj K. Agarwal, Lars Arge, Ke Yi Duke University University of Aarhus.
A priority queue for small integers. 1st Step: Prove this Priority queue capacity: n (w / logn loglogn)-bit keys insert, find-min, delete-min: constant.
Review for Exam 2 Topics covered (since exam 1): –Splay Tree –K-D Trees –RB Tree –Priority Queue and Binary Heap –B-Tree For each of these data structures.
Depth First Search Maedeh Mehravaran Big data 1394.
15-853: Algorithms in the Real World Locality I: Cache-aware algorithms – Introduction – Sorting – List ranking – B-trees – Buffer trees.
External Memory Geometric Data Structures Lars Arge Duke University June 27, 2002 Summer School on Massive Datasets.
Intro. to Data Structures Chapter 6 Priority Queue (Heap) Veera Muangsin, Dept. of Computer Engineering, Chulalongkorn University 1 Priority Queue.
Internal and External Sorting External Searching
FALL 2005CENG 351 Data Management and File Structures1 External Sorting Reference: Chapter 8.
Exam 3 Review Data structures covered: –Hashing and Extensible hashing –Priority queues and binary heaps –Skip lists –B-Tree –Disjoint sets For each of.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
COMP 5704 Project Presentation Parallel Buffer Trees and Searching Cory Fraser School of Computer Science Carleton University, Ottawa, Canada
1 Cache-Oblivious Query Processing Bingsheng He, Qiong Luo {saven, Department of Computer Science & Engineering Hong Kong University of.
Internal Memory Pointer MachineRandom Access MachineStatic Setting Data resides in records (nodes) that can be accessed via pointers (links). The priority.
(A Survey on) Priority Queues IanFest, University of Waterloo, Waterloo, Ontario, Canada, August 14-15, 2013 Gerth Stølting Brodal Aarhus Universty.
CENG 3511 External Sorting. CENG 3512 Outline Introduction Heapsort Multi-way Merging Multi-step merging Replacement Selection in heap-sort.
X1x1 x2x2 top-k y 3-sided x1x1 x2x2 External Memory Three-Sided Range Reporting and Top-k Queries with Sublogarithmic Updates Gerth Stølting Brodal Aarhus.
arxiv.org/abs/ y 3-sided x1 x2 x1 x2 top-k
Source: Muangsin / Weiss
STACS arxiv.org/abs/ y 3-sided x1 x2 x1 x2 top-k
Improve Run Generation
Strict Fibonacci Heaps
Dynamic Sets (III, Introduction)
8th Workshop on Massive Data Algorithms, August 23, 2016
CENG 351 Data Management and File Structures
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
CS 6310 Advanced Data Structure Wei-Shian Wang
Presentation transcript:

Equivalence Between Priority Queues and Sorting in External Memory Zhewei Wei Renmin University of China MADALGO, Aarhus University Ke Yi The Hong Kong University of Science and Technology h

Priority Queue Maintain a set of keys Support insertions, deletions and findmin (deletemin) Fundamental data structure Used as subroutines in greedy algorithms Dijkstra’s single source shortest path algorithm Prim’s minimum spanning tree algorithm

Sorting to Priority Queue Priority queue can do sorting Given N unsorted keys Insert the keys to the priority queue Perform N deletemin operations (find minimum and delete it) If a priority queue can support insertion, deletion, findmin in S(N) time, then the sorting algorithm runs in O(NS(N)) time.

Priority Queue to Sorting Thorup [2007]: sorting can do priority queue! A sorting algorithm sorts N keys in N*S(N) time in RAM model A priority queue support all operations in O(S(N)) time Use sorting algorithm as a black box O(Nloglog N) sorting -> O(loglog N) priority queue O(N loglog N ) sorting -> O( loglog N ) priority queue

The I/O Model [Aggarwal and Vitter 1988] Size: M Unlimited size Size: B Disk Memory CPU Block Complexity: # of block transfers (I/Os) CPU computations and memory accesses are free

Cache-Oblivious Model Size: ? Unlimited size Size: ? Memory Block Disk CPU Optimal without knowledge of M and B Optimal for all M and B

Sorting in the I/O Model Sorting bound: Upper bound: external merge sort Lower bound: holds for comparison model or indivisibility assumption Conjecture: lower bound holds for B not too small, even without indivisibility assumption Sort(N)= Θ(N/B * logM/BN ) I/Os Treat keys as atoms N/B is the # of I/Os to make one pass of scanning, # of passes needed

Priority Queue in External Memory I/O model Buffer tree [Arge 1995] M/B-ary heaps [Fadel et. al. 1999] Array heaps[Brodal and Katajainen 1998] O(1/B*logM/BN ) amortized cost Tree-based: do not give any priority queue-to-sorting reduction

Priority Queue in External Memory Cache-oblivious priority queue [Arge et.al. 2002] Keys are moving around in loglog N levels M>B2 O(1/B*logM/BN) with tall cache assumption Reduction: Given an external sorting algorithm that sorts N keys in NS(N)/B I/Os, there is an external priority queue that support all operations in O(S(N)loglog N/B) amortized I/Os

Our Results S(N)/B for S(N) = Ω(2log*N), or M = Ω(B*log(c)N) A sorting algorithm sorts N keys in N*S(N)/B time in the I/O model Use sorting algorithm as a black box S(N) + S(B*log N) + S(B*loglog N)) + … A priority queue support all operations in 1/B*Σi≥0S(Blog(i)(N/B)) amortized I/Os S(N)/B for S(N) = Ω(2log*N), or M = Ω(B*log(c)N) Other wise O((S(N) log*N) /B) No new bounds for external priority queue External priority queue lower bound -> external sorting lower bound

Outline How Thorup did it (on a high level) How we extend it in external memory (on a high level) Open problems

Thorup’s Reduction Word RAM model: each word consists of w ≥ log N bits constant number of registers, each with capacity for one word Atomic heap [Han 2004]: support insertions, deletions, and predecessor queries in set of O(log2 N) size in constant time So it serves as a priority queue that supports all operations in constant time

Thorup’s Reduction – O(S(N)*log N) O(log N) levels N keys N/2 keys c keys 2c keys N/4 keys Invariant: Keys in higher level are larger than keys in Lower level … First I will present a S(N)*log N reduction. Result-wise it does make any sense to consider such a reduction, since even if we can sort in linear time, this reduction only gives us a priority queue with cost log N, no better than binary tree Keys in higher levels are larger than keys in lower levels When a level gets unbalanced, that is, it expand or shrink by a constant factor Rebalance it by taking its neighbouring levels, sort and merge them, and redistribute keys Keep min in the head

Thorup’s Reduction – O(S(N)*log N) N keys N/2 keys c keys 2c keys N/4 keys O(log N) levels Rebalance cost for level 2j: 2j*S(N) # of sorts in N updates: N/2j Amortized cost in level 2j: S(N) log N levels … Cost: O(S(N)*logN)

O(S(N)) Amortized cost Thorup’s Reduction N/log N base sets N/2log N 1 base sets 2 base sets N/4log N Base sets log N O(log N) levels Split/merge base sets: S(N) amortized Rebalancing level 2j: 2jS(N)/log N # of rebalance in N updates: N/2j Amortized cost for level 2j: S(N)/log N … The base sets are sorted relative to each other, but we don’t sort keys inside a base set. We use the maximum key in a base set to represent it. O(S(N)) Amortized cost

O(S(N)) Amortized cost Thorup’s Reduction O(1) cost N/log N base sets N/2log N 1 base sets 2 base sets N/4log N Base sets log N Split/merge base sets: S(N) amortized Rebalancing level 2j: 2jS(N)/log N # of rebalance in N updates: N/2j Amortized cost for level 2j: S(N)/log N … The base sets are sorted relative to each other, but we don’t sort keys inside a base set. We use the maximum key in a base set to represent it. Atomic heap of size log N O(S(N)) Amortized cost

Thorup’s Reduction O(S(N)) Amortized cost … Atomic Buffer size: N/log N Buffer size: N/2log N Buffer size: N/4log N N/log N base sets N/2log N base sets O(S(N)) Amortized cost N/4log N Base sets … Atomic heap of size log N Amortized Cost: O(S(N)) O(1) cost 2 base sets Atomic heap of size log N 1 base sets

Externalize Thorup’s Reduction Where does B come in? How to replace atomic heap? How to handle deletions in external memory?

Where does B come in? B*log N … Buffer of size B*log N Buffer size: N/log N Buffer size: N/2log N Buffer size: N/4log N N/Blog N base sets N/2Blog N 1 base sets 2 base sets N/4Blog N Base sets B*log N … Buffer of size B*log N

I/O-efficient Flush Operation Buffer size |R| k substructures Sort keys in buffer: O(R*S(R)/B) Distribute keys to k substructures: O(R/B+k) Total I/O cost: O(RS(N)/B + k) If k =O(R/B), total flush cost is O(RS(N)/B), amortized cost is O(S(N)/B)

Amortized I/O cost for flushing level buffers: O(S(N)/B) Where does B come in? Base sets: 2j/(Blog N) Buffer size: 2j/log N B*log N … Amortized I/O cost for flushing level buffers: O(S(N)/B) If a level holds 2j keys Largest buffer size: 2j/log N Largest # of base sets: 2j/Blog N Smallest base set (head) size: B*log N

Replacing Atomic Heap R = B*log N k = log N … Buffer of size B*log N

Replacing Atomic Heap Amortized I/O cost: O(S(N)/B) … Recursively build the structure in the head … Buffer of size B*log N Head of size O(Blog N)

Recursively Build Layers O(log* N) Layers N keys B*log (N/B) keys cB keys 2^c*B keys B*loglog(N/B) keys Levels rebalancing - Move base sets around - Redistribute buffer - S(N)/(Blog N) for one level - S(N)/B for one layer - S(N)log* N/B amortized I/O cost … # of logs to take on N/B before it gets to constant,

Recursively Build Layers O(log* N) Layers N keys B*log (N/B) keys cB keys 2^c*B keys B*loglog(N/B) keys … Layers Rebalancing - Rebuild the first (last) level - S(N)/B for one layer - S (N)log* N/B amortized I/O cost

Recursively Build Layers N keys B*log (N/B) keys cB keys 2^c*B keys B*loglog(N/B) keys O(log* N) Layers …

Recursively Build Layers R = B k = log* N N keys B*log (N/B) keys B*loglog(N/B) keys … Memory buffer of size O(B) 2^c*B keys cB keys

Recursively Build Layers Amortized cost: log* N/B N keys B*log (N/B) keys B*loglog(N/B) keys … I/O cost per update: O(S(N)log* N/B) Memory buffer of size O(B) 2^c*B keys cB keys

Delete x -> Insert (-, x) Handle Deletions Follow a pointer to perform deletion takes 1 I/O per deletion Deleting signals: Delete x -> Insert (-, x) Perform actual deletion afterwards Unlike buffer tree, we don’t have access to the “leaves”(base sets) Invariant: Only process deleting signals in the head

Schedule Avoid repeated sorting If head or memory buffer unbalanced: Flush stage: flush all overflowed buffers and rebalance all unbalanced base sets Push stage: rebalance all overflowed layers and levels (expand) Pull stage: deal with delete signals and rebalance all underflowed layers and levels (shrink)

Open problems Optimal reduction? Priority queue that support insertions/deletions in O(1/B) I/O cost for set of size O(B*log(c) N) New reduction framework Better (than loglog N) reduction in Cache-oblivious model? Hard to do I/O-efficient flushing and rebalancing without knowing B

Thank You!