Pairing Heaps CS 261 Oregon State University Heaps Heap is a - - PowerPoint PPT Presentation

pairing heaps
SMART_READER_LITE
LIVE PREVIEW

Pairing Heaps CS 261 Oregon State University Heaps Heap is a - - PowerPoint PPT Presentation

Pairing Heaps CS 261 Oregon State University Heaps Heap is a great data structure Any chance to make it even better? Seeking an O(1) addition How do we obtain O(1) addition? Answer: only change the location of the root How to


slide-1
SLIDE 1

Pairing Heaps

CS 261 Oregon State University

slide-2
SLIDE 2

Heaps

  • Heap is a great data structure
  • Any chance to make it even better?
slide-3
SLIDE 3

Seeking an O(1) addition

  • How do we obtain O(1) addition?
  • Answer: only change the location of the root
  • How to maintain heap structure?
  • Heap is partial order!
slide-4
SLIDE 4

Robert Tarjan

  • Professor of Princeton
  • Probably the most influential DS researcher in the 1980s
  • Many algorithms/advanced DS
  • Splay trees
  • Pairing heaps
  • Fibonacci heaps
  • Goldberg-Tarjan push-relabel max-flow
  • Hopcroft-Tarjan Planarity-testing
  • Turing Award in 1986
slide-5
SLIDE 5

Pairing heap (Fredman, Sedgewick, Sleator, Tarjan 1986)

  • Maintain root and a list of subheaps

Instead of: Maintain

2 List of subheaps Root 3

9 12 14 10 16 11 5 7 8

slide-6
SLIDE 6

Pairing heap: O(1) insertion

  • Merge 2 heaps operation:

2 List of subheaps 6 Insert 2 Root Root List of subheaps 3

9 12 14 10 16 11 5 7 8

3

9 12 14 10 16 11 5 7 8

6

slide-7
SLIDE 7

Pairing heap: O(1) insertion

2 List of subheaps 1 Insert List of subheaps Root Root 1 2 3

9 12 14 10 16 11 5 7 8

3

9 12 14 10 16 11 5 7 8

slide-8
SLIDE 8

Pairing heap: O(1) merging

2 List of subheaps 6

17 10 13 15 9

List of subheaps

Merge

2

17 10 13 15 9

6

Subheap pointer

3

9 12 14 10 16 11 5 7 8

3

9 12 14 10 16 11 5 7 8

slide-9
SLIDE 9

Pairing heap: Deletion of root

  • Am I cheating?
  • What if I just inserted many elements?
  • Deletion is going to be very difficult!
  • No and yes
slide-10
SLIDE 10

Pairing heaps: deletion (step 1)

2

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

slide-11
SLIDE 11

Pairing heaps: deletion (step 2)

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

slide-12
SLIDE 12

Pairing heaps: deletion (step 3)

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

17 10 13 15 9

6 3

9 12 14 10 16 11 5 7 8

slide-13
SLIDE 13

Pairing heaps: formal deletion algorithm

slide-14
SLIDE 14

Pairing heaps: merging sequence

slide-15
SLIDE 15

Pairing heaps: deletion time

  • Amortized log-n time:
  • O((log n)+)
  • Analysis too complicated here
  • Basic point is that each deletion makes the heap more “binary” which makes

subsequent ones faster

  • Why would pairing heaps work?
  • Utilize multi-way trees
  • Data structures can get more complicated than class!
slide-16
SLIDE 16

Many more heaps

  • https://en.wikipedia.org/wiki/Fibonacci_heap
slide-17
SLIDE 17

Practical Performance

  • A Back-to-Basics Empirical Study of Priority Queues
  • http://arxiv.org/pdf/1403.0252.pdf
  • Pairing heap is the most efficient in practice!