Melding Priority Queues Ran Mendelson Robert E Tarjan
Melding Priority Queues Ran Mendelson Robert E. Tarjan Mikkel Thorup Uri Zwick SWAT 2004
Improved analysis of transformation Non-meldable Priority Queue pq(n) time per operation Meldable Priority Queue pq(n)+α(n) time per operation or pq(n)α(n, n/pq(n)) time per operation 2
Second transformation Meldable Priority Queue pq(n) time per operation pq(N) time per operation n – number of elements in priority queue Keys are is {1, 2, …, N} 3
Meldable Priority Queues Insert Delete Find-Min O(1) O(log n) O(1) Dec-Key O(1) Meld O(1) 10 25 7 17 4 13 2 1 38 5 Amortized [Fredman-Tarjan ’ 87] Worst case [Brodal ’ 96] Best possible comparison based results 4
RAM Priority Queues Keys are integers that fit into a single machine word. Standard arithmetical and logical operations take constant time Insert O(1) Delete O(log n) Find-Min O(1) Dec-Key O(1) Meld [Thorup ’ 03] O(1) NO 01001001 011010 using our transformation 5
Atomic heaps Insert Delete Find-Min O(1) Meld NO [Fredman-Willard ’ 94] 011010 000010 010011 At most O(log 2 n) elements! 6
Union Find makeset union find delete O(1) O(α(m, n)) O(1) a b c d e Amortized [Tarjan ’ 75 , Tarjan & van Leeuven ’ 84 ] 7
Ackermann’s function A 0(j) = j+1 Ai(j) = Ai-1(j+1)(j) Grows extremely FAST α(n) = min{ k : Ak(1) ≥ n } α(m, n) = min{ k : Ak(m/n) ≥ n } Grows extremely slow 8
Union Find Represent each set as a rooted tree Union by rank Path compression 9
Union by rank r+1 0 r 1 r 2 r r 10
Path Compression 11
Non-meldable priority queue + Union Find Meldable priority queue 12
Use the union-find data stricture to maintain the sets Place a non-meldable priority queue at each node of a union-find tree holding the minimal element in each one of its subtrees 9 1 3 19 19 2 2 2 5 4 7 4 1 8 5 4 8 6 6 13
Handling deletions using path compression The amortized delete cost is O(pq(n)α(n)) [MTZ’ 04] [van Emde Boaz, Kaas, Zijlstra ’ 77 ] 14
Flavor of improved analysis At most n/2 k nodes rank ≥ k size ≥ 2 k rank < k size < 2 k Choose k=2 loglog n. If f>n/log n, we are done. 15
More flavor of improved analysis rank ≥ k size ≥ 2 k rank < k size < 2 k 16
Conclusion Sorting Worst-case non-meldable priority queues Amortized meldable priority queues 17
- Slides: 17