Fibonacci Heaps

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

Fibonacci Heaps

Actual O(1) Amortized O(1) O(log n) O(1) O(log n) O(1)

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

Single Source All Destinations Shortest Paths


1

2 16 7

8
3

3 4 4
5

1 10 3
7

6
2

14

Greedy Single Source All Destinations


Known as Dijkstras 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).

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.

Prims 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.

Min Fibonacci Heap

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.

Fibonacci Heap Representation


2 4 4 9 1

6 5 5

8 9

Degree, Parent and ChildCut fields not shown.

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 from its doubly linked sibling list.

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

Update heap pointer if necessary

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.

Cascading Cut Example


1 3 2 F T 9 7 8 6

5 6

T 7

theNode
9 8

Decrease key by 2.

Cascading Cut Example


1 3 2 F T 9 6 8 7 8 6 9

5 6

T 7

Cascading Cut Example


1 3 2 F T 9 6 8 7 7 8 6 9

5 6

Cascading Cut Example


1 3 2 F 9 6 8 7 6 4 7 8 9

5 6

Cascading Cut Example


1 3 2 T 9 6 8 7 6 4 7 8 9

5 6

Actual complexity of cascading cut is O(h) = O(n).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy