pairing heaps
play

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


  1. Pairing Heaps CS 261 Oregon State University

  2. Heaps • Heap is a great data structure • Any chance to make it even better?

  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!

  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

  5. Pairing heap (Fredman, Sedgewick, Sleator, Tarjan 1986) Maintain • Maintain root and a list of subheaps Root List of subheaps Instead of: 2 3 9 12 14 10 16 11 5 7 8

  6. Pairing heap: O(1) insertion • Merge 2 heaps operation: Root List of subheaps Root List of subheaps 2 3 9 Insert 2 12 3 9 6 14 12 14 10 16 11 10 16 11 5 7 8 5 7 8 6

  7. Pairing heap: O(1) insertion Root List of subheaps 3 9 Root List of subheaps 1 Insert 12 2 2 3 9 1 14 12 10 16 14 11 10 16 11 5 7 8 5 7 8

  8. Pairing heap: O(1) merging 3 9 12 14 List of subheaps List of subheaps 10 16 2 2 6 17 11 3 9 10 12 Merge 13 14 5 7 15 8 10 16 9 11 6 17 10 5 7 Subheap pointer 13 8 15 9

  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

  10. Pairing heaps: deletion (step 1) 3 9 9 3 12 12 14 14 16 10 11 10 16 2 11 5 7 5 7 8 8 6 17 6 17 10 10 13 13 15 15 9 9

  11. Pairing heaps: deletion (step 2) 3 9 3 9 12 12 14 14 16 16 10 10 11 11 5 7 5 7 8 8 17 6 6 17 10 10 13 13 15 15 9 9

  12. Pairing heaps: deletion (step 3) 3 9 12 3 9 14 12 16 10 14 11 16 10 11 5 7 5 7 8 8 17 6 17 6 10 10 13 13 15 15 9 9

  13. Pairing heaps: formal deletion algorithm

  14. Pairing heaps: merging sequence

  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!

  16. Many more heaps • https://en.wikipedia.org/wiki/Fibonacci_heap

  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!

Recommend


More recommend