Top Banner
Fibonacci Heaps
31

Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Oct 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Page 2: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

                              Fibonacci            Binary       insert                         O(1)               O(log(n))    find                            O(1)                   N/A        union                         O(1)                   N/A        minimum                   O(1)                  O(1)        decrease key              O(1)               O(log(n))   delete                      O(log(n)            O(log(n))   delete minimum     O(log(n))               N/A       

Page 3: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Binomial Tree:   A binomial tree of order 0 is a single node   A binomial tree of order k has a root of degree k and its children    are roots of binomial trees of orders k­1, k­2, ..., 2, 1, 0 (in order).   A binomial tree of order k has 2k nodes

Page 4: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Data Structures:   Circular doubly linked list of siblings (           )   All nodes have pointers to their parents    One pointer to a child

Page 5: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Forest of binomial trees ­ key of node is less than keys of children

Page 6: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Forest of binomial trees ­ key of node is less than keys of children

Node with minimum key is a root of one of the trees

Page 7: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Forest of binomial trees ­ key of node is less than keys of children

Node with minimum key is a root of one of the trees

A node may have degree greater 2 but no larger than O(log(n))

Page 8: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Forest of binomial trees ­ key of node is less than keys of children

Node with minimum key is a root of one of the trees

A node may have degree greater 2 but no larger than O(log(n))

Size of a subtree rooted in node of degree k is Fk+2

 where Fk

is the kth Fibonacci number 

Page 9: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Forest of binomial trees ­ key of node is less than keys of children

Node with minimum key is a root of one of the trees

A node may have degree greater 2 but no larger than O(log(n))

Size of a subtree rooted in node of degree k is Fk+2

 where Fk

is the kth Fibonacci number 

6 2

5 3 4 7 8 9

1Minimum Node

Page 10: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Find Minimum   Simple lookup using Min Node pointer ­ O(1)

6 2

5 3 4 7 8 9

1Minimum Node

Page 11: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Union of two heaps   Attach higher numbered node to smaller   Remove former root from linked list   Add former root to children linked list ­ O(1)

6 2

5 3 4 7 8 9

1Minimum Node

Page 12: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Union of two heaps   Attach higher numbered node to smaller   Remove former root from linked list   Add former root to children linked list ­ O(1)

6 2

5 3 4 7 8 9

1Minimum Node

Page 13: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Insert   Add new node as a heap   Attach to the root linked list ­ O(1)

6 2

5 3 4 7 8 9

1Minimum Node

10

Page 14: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum      

6 2

5 3 4 7 8 9

1Minimum Node

Page 15: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum   Remove minimum node and make children roots   

6 2

5 3 4 7 8 9

Minimum Node

Page 16: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum   Remove minimum node and make children roots   Union roots of same degree until all roots have different degree   

6 2

5 3 4 7 8 9

Minimum Node

Page 17: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum   Remove minimum node and make children roots   Union roots of same degree until all roots have different degree   

6 2

53 4 7 8 9

Minimum Node

Page 18: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum   Remove minimum node and make children roots   Union roots of same degree until all roots have different degree   

6 2

53 4 7 8 9

Minimum Node

Page 19: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete Minimum   Remove minimum node and make children roots   Union roots of same degree until all roots have different degree    Reset Minimum Node pointer  

6 2

53 4 7 8 9

Minimum Node

Page 20: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key      

6 2

5 3 4 7 8 9

1Minimum Node

Page 21: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key   Marked nodes are those having had exactly one child promoted   to a root previously      

6 2

5 3 4 7 8 9

1Minimum Node

Page 22: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key   Decrease the key       ­ if violation, cut from the tree,       ­ promote it to a root       ­ mark its parent if it is unmarked       ­ if the parent had been marked cut it from its tree,        and promote it to a root, and unmark it.   

6 2

5 3 4 7 8 0

1Minimum Node

Page 23: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key   Decrease the key       ­ if violation, cut from the tree,       ­ promote it to a root       ­ mark its parent if it is unmarked       ­ if the parent had been marked cut it from its tree,        and promote it to a root, and unmark it.   

6 2

5 3 4 7 8 0

1Minimum Node

Page 24: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key   Decrease the key       ­ if violation, cut from the tree,       ­ promote it to a root       ­ mark its parent if it is unmarked       ­ if the parent had been marked cut it from its tree,        and promote it to a root, and unmark it.  ­ O(1) !!!   

6 2

5 3 4 7 8 0

1Minimum Node

Page 25: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Decrease Key   Decrease the key       ­ Change the Minimum Node pointer

6 2

5 3 4 7 8 0

1Minimum Node

Page 26: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete   Key of node to be deleted changed to minus infinity   (decrease key operation)   Followed by simple delete minimum       

6 2

5 3 4 7 8 9

1Minimum Node

Page 27: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete   Key of node to be deleted changed to minus infinity   (decrease key operation)   Followed by simple delete minimum       

6 2

5 3 4 7 8 ­∞

1Minimum Node

Page 28: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete   Key of node to be deleted changed to minus infinity   (decrease key operation)   Followed by simple delete minimum       

­∞ 2

5 3 4 7 86

1Minimum Node

Page 29: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete   Key of node to be deleted changed to minus infinity   (decrease key operation)   Followed by simple delete minimum       

2

5 3 4 7 86

1Minimum Node

Page 30: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Operation: Delete   Key of node to be deleted changed to minus infinity   (decrease key operation)   Followed by simple delete minimum ­ O(log(n))      

2

5 3 4 7 86

1Minimum Node

Page 31: Fibonacci Heaps - University of Cincinnatigauss.ececs.uc.edu/Courses/C228/lectures/FibonacciHeaps/fibheap.… · Fibonacci Heaps Forest of binomial trees key of node is less than

Fibonacci Heaps

Result:   Complexity of algorithms using priority queues is reduced!   Example: Shortest Path – O((m+n)log(n))  with binary heap                                             O(m +nlog(n)) with Fibonacci heap