Download presentation
Presentation is loading. Please wait.
Published byCaroline Gibbs Modified over 6 years ago
1
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
2
Single Source All Destinations Shortest Paths
1 2 3 4 5 6 7 16 8 10 14
3
Greedy Single Source All Destinations
Known as Dijkstra’s algorithm. Let d(i) be the length of a shortest one edge extension of an already generated shortest path, the one edge extension ends at vertex i. The next shortest path is to an as yet unreached vertex for which the d() value is least. After the next shortest path is generated, some d() values are updated (decreased).
4
Operations On d() Remove min. Decrease d(). Array. Min heap.
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.
5
Prim’s Min-Cost Spanning Tree Algorithm
Array. O(n2) overall complexity. Min heap. O(nlog n + elog n) overall complexity. Fibonacci heap. O(nlog n + e) overall complexity.
6
Min Fibonacci Heap Collection of min trees.
The min trees need not be Binomial trees.
7
Node Structure Degree, Child, Data Left and Right Sibling Parent
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. Doubly linked list … remove arbitrary uses external pointers to nodes. So, we cannot copy an element from the next node as is done in the delete of an arbitrary node from a singularly linked circular list. Further, there is a parent pointer to a node. If you move an element you must change the parent pointer from its children. This would take O(children) time. Parent field needed for decreaseKey and cascading cut.
8
Fibonacci Heap Representation
6 4 9 5 8 7 3 1 2 A Try to remove 4. If you copy the 5 over, there is an external pointer to 5’s former node And also a parent pointer from 9 to 5. Parent and ChildCut fields not shown.
9
Delete(theNode) theNode points to the Fibonacci heap node that contains the element that is to be deleted. theNode points to min element => do a delete min. In this case, complexity is the same as that for delete min.
10
Delete(theNode) theNode
8 7 3 1 6 5 9 2 4 10 theNode Remove theNode from its doubly linked sibling list.
11
Delete(theNode) Combine top-level list and children of theNode. 1 3 7
8 7 3 1 6 5 9 2 4 10 Must make parent pointers in theNode’s children equal to null. Combine top-level list and children of theNode.
12
Delete(theNode) 10 1 6 5 5 3 7 9 9 2 8 4 9 5 6 7 6 No pairwise combining of equal-degree trees. Child pointer from parent (if any) needs to be changed. Heap pointer is unchanged. Parent pointers of theNode’s children need to be set to null. Actual complexity is degree of theNode. 8
13
DecreaseKey(theNode, theAmount)
8 7 3 1 6 5 9 2 4 10 theNode DecreaseKey(theNode,4). Possible update of min element pointer. Parent pointer set to null and child pointer from parent may need to be reset. Actual complexity is O(1). 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.
14
DecreaseKey(theNode, theAmount)
8 7 3 1 6 5 9 2 4 6 5 10 5 9 9
15
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.
16
Cascading Cut Example 8 7 3 1 6 5 9 2 4 theNode T F Decrease key by 2.
17
Cascading Cut Example 1 6 3 F 7 2 9 8 8 4 T 9 5 9 6 T 7 6
18
Cascading Cut Example 1 6 7 3 F 7 2 9 8 8 4 T 9 5 9 6 6
19
Cascading Cut Example 1 6 7 4 3 F 7 2 9 8 6 8 9 5 9 6
20
Cascading Cut Example 8 7 3 1 6 5 9 2 4 T Actual complexity of cascading cut is O(n), because now the tree height may be O(n). Do ops to create a B2 (height = 3). Now do a decrease key to get a chain of height (length) 3 and a B0. Do 2 inserts, a remove min, and a decrease key to get a chain of height 4 and B0. We can increase height by 1 each time we do 2 inserts, a remove min, and a decrease key. So, height is O(n), where n is number of operations (or number of elements in tree). Actual complexity of cascading cut is O(h) = O(n).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.