Introduction to the Fibonacci heap
The heaps (Fibnacci heap) has two uses: First, a series of operations that form the so-called consolidated heap. Second, some of its operations can be done in constant time , making this data structure ideal for applications that require frequent calls to these operations.
The Mergeable heap supports the following five operations: Make-heap (), Insert (H, X), Minmun (h), Extract-min (h), Union (H1, H2). In fact, it is the heap that has a fast merge operation (heap).
Fibonacci Heaps also supports two additional operations: Decrease-key (H, X, K), Delete (H, X).
Fibonacci Stack Structure
A Fibonacci heaps is a set of root trees with the smallest number of stacks, each of which follows the minimum heap nature.
Heap Properties:
Each node x contains a pointer to its parent node x.parent and a pointer to one of its children x.child,x all form a two-way ring linked list, called X's child linked list. Each child node Y contains pointers Y.left and y.right points to the sibling node. The order in which the siblings appear in the child's list is arbitrary.
There are two properties for each node. The number of children in the child linked list of node x is stored in X.degree, and the Boolean attribute X.mark indicates if the node x has been a child since the last time the child became another node. The new node is unmarked, and when node X becomes the child of another node, it becomes an unmarked node.
A given Fibonacci H is accessed by pointer H.min, pointing to the minimum root node of the heap. If the heap is empty, then h.min points to null. Because the root node also forms a two-way ring list, the order of the root node is arbitrary.
The root node also has an attribute H.N that represents the current number of nodes.
Potential function:
The performance of Fibonacci Stacks is analyzed by the potential function. For a given heap H, use T (h) to represent trees in the root chain of h in the tree, and M (h) to represent the trees of the labeled nodes in H. The potential function of the Fibonacci H is defined as Φ (h) = t (h) + 2m (h).
maximum number of degrees:
The maximum degree of any node in a Fibonacci heap of N nodes has an upper bound D (N). If only the merge heap operation is supported, then D (n) ≤floor (LGN) requires d (n) = O (LGN) when the Fibonacci heap operation is supported.
can merge heap operations
Some of the merge operations on the Fibonacci heap should be deferred as much as possible. Different operations can be balanced for performance. For example, when you perform a extract-min operation, you have to traverse the remaining nodes of the root list to find the new minimum node. There is a performance balance problem here. As long as we facilitate the entire root list after performing the extract-min operation, and merge the nodes into the smallest heap tree to reduce the size of the root list. It will be discussed later that, after execution, each node in the root list requires a unique number of degrees, so that the root list size is up to D (n) +1, regardless of the extract-min.
To create a new Fibonacci heaps:
Creating a new heap, the MAKE-FIBHEAP process allocates and returns a Fibonacci object H, where H.N = 0 and h.min = null,h without a tree, because t (h) = 0 and M (h) = 0, so its potential Φ (h) = 0. The cost of its amortization is therefore equal to its actual cost O (1).
Insert a node:
The following procedure inserts a node x into H, where X.key has been assigned a value.
Fibheap-insert (List *h, Node *x) {X.degree=0x.parent=NULL X.child=NULL X.mark=Falseif(H.min = =NULL) Create a root list forH containing just x h.min=xElseinsert X into H's Root list if(X.key <h.min.key) H.min=x H.N++}
The increase of the potential is 1, the actual cost is O (1), so the amortization cost is O (1) + 1 = O (1).
To find the smallest node:
Can be obtained directly through the pointer H.min, and the amortization cost equals the actual cost of O (1).
Two Fibonacci Stacks merged:
This procedure simply links the root chain tables of H1 and H2, and then determines the new h.min.
Fibheap-union (list *h1, list *H2) { = make-fibheap () = H1.min concatenate the root List of H2 with that of H1if ((h1.min = = NULL) | | (H2.min! = NULL && H2.min.key < H1.min.key) ) = h2.min = h1.n + h2.n return H}
The 1th to 3rd line will link the root chain table of H1 and H2 to the new root list of H. The 2nd to 5th line sets the minimum root node of H. Line 6th sets the number of nodes after merging.
The potential change is 0, so the amortization cost equals the actual cost O (1).
Extract the minimum junction:
This procedure first turns each child of the smallest node h.min into the root node and removes the node from the root list. The same degree nodes are then combined to optimize the root list (this step is deferred until Extract-min is executed).
Fibheap-extract-min (List *H) { = h.min if (z! = NULL )for Each child X of z add x to the root list of H = NULL from the root list of H if (z = = z.right )= NULL else = z.right Consolidate (H) H.N-- return Z}
The next step is to merge the root list of H by calling Consolidate (h) To reduce the tree of the root-linked table trees. The merge process repeats the following process until each root has a different degree:
1. Find two root x and y of the same degree in the root list, assuming X.key≤y.key;
2. Link y to x: Remove y from the root list, call the Fibheap-link procedure, and make Y the child of X. This procedure increases the x.degree by 1 and clears the mark on Y.
Procedure Consolidate (H) uses a secondary array a[0..d (H.N)] to record the locus of the root node corresponding to the degree. If a[i]=y, then the current y is a root with y.degree=1. The process of calculating D (H.N) is left to be explained later.
Consolidate (List *H) {Create array a[0.. D (h,n)] fori = (0To D (h,n)) A[i]=NULL forEach node WinchThe root list of H x=W D=X.degree while(A[d]! =NULL) y=A[d]if(X.key >y.key) Exchange x with y fibheap-Link (H, y, x) a[d]=NULL D++H.min=NULL fori = (0To D (h,n))ifA[i]! =NULLifH.min = =NULL Create a root list forH containing just a[i]ElseInsert a[i] into H's Root list ifA[i].key <H.min.key h.min=A[i]} Fibheap-link (List *h, node *y, node *x) {Remove Y fromthe root list of H make y a child of X, incrementing X.degree Y.mark=False}
The cost of extracting the minimum node's amortization is O (LGN).
Fibonacci Heap operation-drop right and delete keyword drop right:
When the keyword falls right, if the node being lowered right is a child node of a root node, it is necessary to determine whether the minimum heap property is violated after lowering the right. If the child node is smaller than the root node, the child nodes tree is cut directly into the Fibonacci root list. If the parent node of the clipped child node is not marked, it is marked. If there is a tag, its parent node is also clipped to the root list, which is called cascading clipping. Cascading cuts are traced up until an unmarked node or root is encountered.
Fibheap-decrease-key (List *h, Node *x,intkey) { if(Key >x.key) Error"New key is greater than current one."X.key=Key y=x.parentif(Y! = NULL && X.key <y.key) Cut (H, x, y) cacsading-Cut (H, y)if(X.key <h.min.key) H.min=X.key} Cut (List*H, node *x, node *y) {remove x fromThe child list of Y, y.degree--add x to the root list of H x.parent=NULL X.mark=False} Cascading-cut (List *h, Node *y) {z=y.parentif(Z! =NULL)if(Y.mark = =False) Y.mark=TrueElseCut (H, y, z) cascading-Cut (H, z)}
The amortization of the keyword down-weight is at most O (1). There are twice times the number of nodes before the potential, one unit of potential pay off and the clearance of the mark bit, the other unit compensates for the shear node becomes the root node after the more potential.
To delete a node:
Very simple, down right to-∞ after direct Extract out.
Fibheap-delete (List *h, Node *x) { fibheap-decrease-key (H, X,-∞) fibheap-extract-Min ( H)}
Theoretical analysis of Fibonacci heaps
For each node x in the Fibonacci heap, the size (x) is defined as the number of nodes that include the x itself in the subtree that is the root of x. We will prove that size (x) is the power of X.degree.
Lemma 1: Set X is the arbitrary node in the Fibonacci heap, assuming x.degree = K. Set Y1, y2, ..., YK represents the children of X, and is arranged in the order in which they are linked in X, then y1.degree≥0, and for i = 2, 3, ..., K, there is yi.degree≥i-2.
Lemma 2: For all integers k≥0,fibk+2 = 1 + sigma (i = 0, k) Fibi.
Lemma 3: For all integers k≥0, the number of Fibonacci number k+2 satisfies Fibk+2≥φk, where φ= (1 + root 5)/2.
Lemma 4: Set X is the arbitrary node in the Fibonacci heap, and set k = X.degree, then there is a size (x) ≥fibk+2≥φk.
Lemma 5: The maximum degree D (n) = O (LGN) of any node in the Fibonacci heap of an N-node.
[CLRS] [CH 19] Fibonacci Heap