17
Melding Priority Queues Ran Mendelson Robert E. Tarjan Mikkel Thorup Uri Zwick SWAT 2004

Melding Priority Queues

  • Upload
    hubert

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Melding Priority Queues

Melding Priority Queues

Ran MendelsonRobert E. TarjanMikkel Thorup

Uri Zwick

SWAT 2004

Page 2: Melding Priority Queues

2

Non-meldablePriority Queue

MeldablePriority Queue

pq(n) timeper operation

pq(n)+α(n) timeper operation

pq(n)α(n,n/pq(n)) timeper operation

or

Improved analysisof transformation

Page 3: Melding Priority Queues

3

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}

Page 4: Melding Priority Queues

4

Priority Queues

Insert

Delete

Find-Min

10

7

25

13

4

17

38

15Dec-Key

Meld

Meldable

O(1)

O(log n)

O(1)

O(1)

Amortized [Fredman-Tarjan ’87]

Worst case [Brodal ’96]

Best possible comparison based results

2

O(1)

Page 5: Melding Priority Queues

5

RAM Priority Queues

Insert

Delete

Find-Min

Dec-Key

O(1)

O(log log n)

O(1)

O(1)

[Thorup ’03]

Keys are integers that fit into a single machine word.Standard arithmetical and logical operations take constant time

010010

011010

001001

Meld O(1)NO using our transformation

Page 6: Melding Priority Queues

6

Atomic heaps

Insert

Delete

Find-Min

O(1)

O(1)

O(1)

[Fredman-Willard ’94]

011010

010011

000010

Meld NO At most O(log2n)

elements!

Page 7: Melding Priority Queues

7

Union Find

makeset

union

find

delete

a

c

b

d e

O(1)

O(1)

O(α(m,n))

O(1)

[Tarjan ’75 , Tarjan & van Leeuven ’84 ]

Amortized

Page 8: Melding Priority Queues

8

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 extremely

slow

Page 9: Melding Priority Queues

9

Union FindRepresent each set as a rooted tree

Union by rank Path compression

Page 10: Melding Priority Queues

10

Union by rank

0 r1

r2 r r

r+1

Page 11: Melding Priority Queues

11

Path Compression

Page 12: Melding Priority Queues

12

Non-meldable priority queue+

Union Find

Meldable priority queue

Page 13: Melding Priority Queues

13

Place a non-meldable priority queue at each node of a union-find tree

holding the minimal element in each one of its subtrees

3 7

1 5

9

19 2 4 8 6

4 8 619 2

2 4

1 5

Use the union-find data stricture to maintain the sets

Page 14: Melding Priority Queues

14

Handling deletions using path compression

The amortized delete cost is O(pq(n)α(n))

[MTZ’04]

[van Emde Boaz, Kaas, Zijlstra ’77 ]

Page 15: Melding Priority Queues

15

Flavor of improved analysis

rank ≥ k

rank < k

size ≥ 2k

size < 2k

( , )2 2k k

n nf

( , )f n n

At mostn/2k nodes

Choose k=2loglog n. If f>n/log n, we are done.

Page 16: Melding Priority Queues

16

More flavor of improved analysis

rank ≥ ksize ≥ 2k

rank < ksize ≥ 2k

rank < ksize < 2k

Page 17: Melding Priority Queues

17

Conclusion

Sorting

Worst-case non-meldable priority queues

Amortized meldable priority queues