The Weak-Heap Family of Priority Queues in Theory and Praxis Stefan - - PowerPoint PPT Presentation

the weak heap family of priority queues in theory and
SMART_READER_LITE
LIVE PREVIEW

The Weak-Heap Family of Priority Queues in Theory and Praxis Stefan - - PowerPoint PPT Presentation

The Weak-Heap Family of Priority Queues in Theory and Praxis Stefan Edelkamp 1) and Amr Elmasry 2) Jyrki Katajainen 2) 1) University of Bremen 2) University of Copenhagen These slides are available at http://www.cphstl.dk c Performance


slide-1
SLIDE 1

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (1)

The Weak-Heap Family of Priority Queues in Theory and Praxis

Stefan Edelkamp1) and Amr Elmasry2) Jyrki Katajainen2)

1) University of Bremen 2) University of Copenhagen

These slides are available at http://www.cphstl.dk

slide-2
SLIDE 2

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (2)

Our research program

Provide the best bounds on the comparison complexity of priority- queue operations (n the current size of the data structure):

find-min: no element comparisons delete,delete-min: ∼β lg n element comparisons

Other operations: ∼κ element comparisons where β and κ are constants. worst case per operation Full operation repertoire: insert, borrow, decrease, meld

slide-3
SLIDE 3

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (3)

New game

Application = Request sequence (Think graph applications) What is the best bound when handling a request sequence consisting of n insert, n

delete-min, and m decrease operations?

worst case per sequence

slide-4
SLIDE 4

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (4)

Our result

Rank-relaxed weak heaps are better than Fibonacci heaps! Data structure # element comparisons Fibonacci heap 2m + 2.89n lg n Rank-relaxed weak heap 2m + 1.5n lg n But they are not simpler! Data structure Lines of code Binary heap 205 Fibonacci heap 296 Rank-relaxed weak heap 883

slide-5
SLIDE 5

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (5)

Weak heap

  • A binary tree
  • The root only has a right child if any
  • Elements obey the weak-heap ordering:

for element x, every element in the right subtree is ≥ x

  • With the exception of the root, the nodes

that have at most one child are at the last two levels only

minimum leaf registry

Our representation pointer-based!

slide-6
SLIDE 6

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (6)

Rank-relaxed weak heap

  • λ ≤ ⌊lg n⌋ − 1 nodes marked; they may

violate the weak-heap ordering

insert: Insert a leaf, mark it, apply λ-reducing

transformations as long as possible.

decrease: Decrease the value in the given node,

mark it, apply λ-reducing transformations as long as possible.

delete-min: Find the minimum (at the root or

  • ne of the marked nodes), borrow a leaf,

fix the structure of the subtree that lost its root, mark the root of the fixed subtree, apply λ-reducing transformations as long as possible.

mark registry minimum

Improvement in delete-min: If the mark registry is more than half full before the minimum finding, empty it.

slide-7
SLIDE 7

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (7)

Normal referee comments

  • Element comparisons are not relevant in practice!
  • Pairing heaps are much faster in practice!
  • No one would ever implement Fibonacci heaps since they are so

complicated. This is you guys! Thank you! You pushed us to do some practical experiments!

slide-8
SLIDE 8

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (8)

Our play with Dijkstra’s algorithm

  • scanned

labelled unlabelled source priority queue minimum

a factor of two speed-up With your search engine, you will find many experimental studies on Dijkstra’s algorithm. Be critical when you read the results.

  • Which algorithm
  • Which graph representation
  • Which priority queue
  • Which tuning level
slide-9
SLIDE 9

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (9)

Graph representation

CPH STL

  • adjacency arrays
  • simple
  • static
  • 16m + 16n + O(1) bytes for

a graph with m edges and n vertices LEDA

  • adjacency lists
  • nice interface
  • fully dynamic
  • parameterized

weights doubles

  • 52m + 60n + O(1)

bytes [LEDA Book, § 6.14]

vertex edge end points weight tentative distance state edge pointer ...

a factor of two speed-up

slide-10
SLIDE 10

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (10)

Interaction

  • priority queue

tentative distance graph minimum

Combine the graph vertex and the priority- queue node [Knuth 1994] → improves cache behaviour a factor of two speed-up

slide-11
SLIDE 11

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (11)

Tuning

Running time per n [µs]

Structure Operation CPH STL Fibonacci heap LEDA 6.2 Fibonacci heap

insert

n: 10 000 0.10 0.18 n: 100 000 0.09 0.15 n: 1 000 000 0.09 0.15

decrease

n: 10 000 0.03 0.06 n: 100 000 0.05 0.22 n: 1 000 000 0.06 0.31

delete-min

n: 10 000 0.7 1.2 n: 100 000 1.4 2.7 n: 1 000 000 2.8 4.5

Element comparisons per n

Structure Operation CPH STL Fibonacci heap LEDA 6.2 Fibonacci heap

insert

n: 10 000 1 n: 100 000 1 n: 1 000 000 1

decrease

n: 10 000 2 n: 100 000 2 n: 1 000 000 2

delete-min

n: 10 000 16.2 29.9 n: 100 000 21.2 38.3 n: 1 000 000 26.2 46.5

On my computer (Ubuntu, gcc, with -O3) a factor of two speed-up

slide-12
SLIDE 12

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (12)

Parameterized design

weak heap element type comparator type node type weak−heap node, combined weak−heap node & graph node, ... std::less, std::greater, ... int, double, ... modifier type relaxed heap modifier, ... level−registry type mark−registry type leaf registry, ... naive mark registry, eager mark registry, lazy mark registry, ...

  • comparators shared
  • nodes shared
  • transformations shared
  • level registries shared
  • mark registries shared

a factor of two less code

slide-13
SLIDE 13

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (13)

What is the best?

Our reference sequence Theory: rank-relaxed weak heap Dijkstra—time: binary heap [Williams 1964] Dijkstra—comps: weak heap [Dutton 1993] Worst case per operation

insert—time: Fibonacci heap

[Fredman & Tarjan 1987]

insert—comps: Fibonacci heap decrease—time: Fibonacci heap decrease—comps: Fibonacci heap delete-min—time: weak queue

[Vuillemin 1978]

delete-min—comps: weak heap

slide-14
SLIDE 14

c

Performance Engineering Laboratory

18th CATS, Melbourne, 2 Feb. 2012 (14)

Conclusions

Earlier conjectures—see my SWAT-2010 slides Katajainen’s third conjecture: Our reference sequence can be han- dled with 2m + n lg n + o(n) element comparisons in O(m + n lg n) time. Cache effects: We have neglected the cache behaviour of priority queues for too long. Source code: Our programs are available via the CPH STL website.