Fibonacci Heaps
Fibonacci Heaps
Fibonacci Heaps
Insert
Remove min (or max) O(n) Meld Remove Decrease key (or increase) O(1) O(n) O(n)
Analysis
FibonacciAnalysis.ppt Video
http://www.cise.ufl.edu/academics/courses/prev iew/cop5536sahni Same as: www.cise.ufl.edu/~sahni/cop5536; Internet Lectures; not registered COP5536_FHA.rm
2 16 7
8
3
3 4 4
5
1 10 3
7
6
2
14
Operations On d()
Remove min.
Done O(n) times, where n is the number of vertices in the graph.
Decrease d().
Done O(e) times, where e is the number of edges in the graph.
Array.
O(n2) overall complexity.
Min heap.
O(nlog n + elog n) overall complexity.
Fibonacci heap.
O(nlog n + e) overall complexity.
Min heap.
O(nlog n + elog n) overall complexity.
Fibonacci heap.
O(nlog n + e) overall complexity.
Collection of min trees. The min trees need not be Binomial trees.
Node Structure
Degree, Child, Data Left and Right Sibling
Used for circular doubly linked list of siblings.
Parent
Pointer to parent node.
ChildCut
True if node has lost a child since it became a child of its current parent. Set to false by remove min, which is the only operation that makes one node a child of another. Undefined for a root node.
6 5 5
8 9
Remove(theNode)
theNode points to the Fibonacci heap node that contains the element that is to be removed. theNode points to min element => do a remove min.
In this case, complexity is the same as that for remove min.
Remove(theNode)
1 6 5
theNode
2
10
Remove(theNode)
1 6 5
10
Combine top-level list and children of theNode setting parent pointers of the children of theNode to null.
Remove(theNode)
10 5 1 6 5
DecreaseKey(theNode, theAmount)
1 6 5
theNode
2
10
If theNode is not a root and new key < parent key, remove subtree rooted at theNode from its doubly linked sibling list. Insert into top-level list.
DecreaseKey(theNode, theAmount)
0 1 6 5 10
9 4 5
Cascading Cut
When theNode is cut out of its sibling list in a remove or decrease key operation, follow path from parent of theNode to the root. Encountered nodes (other than root) with ChildCut = true are cut from their sibling lists and inserted into top-level list. Stop at first node with ChildCut = false. For this node, set ChildCut = true.
5 6
T 7
theNode
9 8
Decrease key by 2.
5 6
T 7
5 6
5 6
5 6