170 likes | 322 Views
Melding Priority Queues. Ran Mendelson Robert E. Tarjan Mikkel Thorup Uri Zwick. SWAT 2004. Improved analysis of transformation. Meldable Priority Queue. Non-meldable Priority Queue. pq(n)+ α (n) time per operation. pq(n) time per operation. or.
E N D
Melding Priority Queues Ran Mendelson Robert E. Tarjan Mikkel Thorup Uri Zwick SWAT 2004
Improved analysisof transformation MeldablePriority Queue Non-meldablePriority Queue pq(n)+α(n) timeper operation pq(n) timeper operation or pq(n)α(n,n/pq(n)) timeper operation
Second transformation MeldablePriority Queue pq(n) timeper operation pq(N) timeper operation n – number of elements in priority queue Keys are is {1,2,…,N}
Meldable Priority Queues Insert Delete Find-Min O(1) O(log n) O(1) O(1) 10 25 4 7 2 13 17 1 O(1) Dec-Key 5 38 Meld Amortized[Fredman-Tarjan ’87] Worst case[Brodal ’96] Best possible comparison based results
RAM Priority Queues Keys are integers that fit into a single machine word.Standard arithmetical and logical operations take constant time Insert Delete Find-Min O(1) O(log log n) O(1) O(1) 010010 001001 011010 Dec-Key using our transformation Meld O(1) NO [Thorup ’03]
Atomic heaps Insert Delete Find-Min O(1) O(1) O(1) 011010 000010 010011 At most O(log2n) elements! Meld NO [Fredman-Willard ’94]
Union Find makeset union find delete O(1) O(1) O(α(m,n)) O(1) a b c d e Amortized [Tarjan ’75 , Tarjan & van Leeuven ’84 ]
Ackermann’s function A0(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 extremelyslow
Union Find Represent each set as a rooted tree Union by rank Path compression
Union by rank r+1 r r2 r r1 0
Non-meldable priority queue+Union Find Meldable priority queue
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 5 1 2 4 5 3 19 2 7 4 8 6 19 2 4 8 6
Handling deletions using path compression The amortized delete cost is O(pq(n)α(n)) [MTZ’04] [van Emde Boaz, Kaas, Zijlstra ’77 ]
Flavor of improved analysis rank ≥ k At mostn/2k nodes size ≥ 2k rank < k size < 2k Choose k=2loglog n. If f>n/log n, we are done.
More flavor of improved analysis rank ≥ k size ≥ 2k rank < k size ≥ 2k rank < k size < 2k
Conclusion Sorting Worst-case non-meldable priority queues Amortized meldablepriority queues