A Fibonacci heap refers to a heap data structure consisting of various collection of trees. It is been a better amortized running time when compared to binomial heap. Fibonacci heaps was first developed by Michael L. Fredman and Robert E. Tarjan in 1984 and published in a scientific journal in 1987. The name of Fibonacci heap was coined from Fibonacci numbers which were used in the running time analysis.
C:\Users\Saravanan\Desktop\labelled.JPG
Find-minimum is referred to as O(1) amortized time. The Operations such as insert, decrease key, and merge (union) are better utilized in constant amortized time. The Operations delete and delete minimum works better in O(log n) amortized time. Hence we say that beginning from an empty data structure, any sequences of ' a 'operations The first group 'a' and 'b' will have the operations for the first group will have to take O (a + b log n) time to complete the single heap. This is the binomial heap will have the sequence of operations that would take O((a + b) log (n)) time to finish this task. Hence we can even allocate the Fibonacci series when b will have the asymptotically larger than the, this Fibonacci heap will have the heap in thus better than this binomial heap.
The Fibonacci heaps for the priority queues improvises the asymptotic running time for the vital algorithms, such as Dijkstra's algorithm for computing the shortest path between two nodes in a graph.
Example:
C:\Users\Saravanan\Desktop\pic\Dijkstraexample.png
Using vertex 5 as the source (setting its distance to 0), we initialize all the other distances to ∞, set S = ∅, and place all the vertices in the queue (resolving ties by lowest vertex number)
C:\Users\Saravanan\Desktop\pic\Dijkstraexample1.png
Iteration 1: Dequeue vertex 5 placing it in S (with a distance 0) and relaxing edges (u5,u2) and (u5,u4) then reprioritizing the queue
C:\Users\Saravanan\Desktop\pic\Dijkstraexample2.png
Iteration 2: Dequeue vertex 4 placing it in S (with a distance 2) and relaxing edges (u4,u2) and (u4,u3) then reprioritizing the queue. Note edge (u4,u2) finds a shorter path to vertex 2 by going through vertex 4
C:\Users\Saravanan\Desktop\pic\Dijkstraexample3.png
Iteration 3: Dequeue vertex 2 placing it in S (with a distance 3) and relaxing edge (u2,u1) then reprioritizing the queue.C:\Users\Saravanan\Desktop\pic\Dijkstraexample5.png
Iteration 4: Dequeue vertex 3 placing it in S (with a distance 3) and relaxing no edges then reprioritizing the queue.
C:\Users\Saravanan\Desktop\pic\Dijkstraexample6.png
Iteration 5: Dequeue vertex 1 placing it in S (with a distance 6) and relaxing no edges.
The final shortest paths from vertex 5 with corresponding distances is
C:\Users\Saravanan\Desktop\pic\Dijkstraexample7.png
A Fibonacci heap must satisfy minimum-heap property, the key of a child must always be greater than or might be The equal key for the entire parent. This will really replicate the implicates that the minimum and maximum key will be at the root of one or two of these trees. It will be comparing with the entire binomial heap; the structure which indicates the tree of a Fibonacci heap in one or more flexible state and that is the major advantage. The trees do not have a particular shape and in the worst In this case this type of heap will have these type of heap in every element which will be used to in a separate tree. Since this flexibility will allow all the trees in the some operations will be executed in a "lazy" manner to put the heap correctly., by postponing the work for later operations. For instance merging heaps is done by This will have concatenating the two lists for all the trees with operation which can even increase or decrease key. These can have some times which cuts the entire node from its parent to child node and forms a new heap tree.
However this will have some order that should have the entire element in the heap otherwise it will be introduced to all the heap for achieving the desired way of the running time at some of the heap will be changed at some point of time. In long, degrees this will have all of nodes be together here degree to refers all the number of child node are aside to kept quite low that is every node will always have the single upwards nodes which will be having degree of O(log n) and these size will differ in the sub tree rooted in the node for degree of all the k will be at least to Fk + 2, where it can be Fk in the kth this sub tree will be Fibonacci number. It can be achieved by adding some of the rules that we can even have the Fibonacci heap that cut at most one child and two parent node at each non-root node. Which as the first and second child is cut, this node itself needs to do these cut from its parent and even in the child node and it becomes the root of a new and odd tree. These number of trees
Actually will have the running time of slow and even fast operations. This can have the loss in the amount of time which saved for the later which can be used to measure at any given moment for the potential function. These potential function of the Fibonacci heap is given by
Potential = t + 2m
Where this t refers for the number of trees that can be in the Fibonacci heap and m will be commonly refers to the number of marked nodes. These node can be marked if it is one of its child and parent node was cut then it will be kept has another children node.
Fibonacci Heap Implementation
Creating a new Fibonacci heap
For making an empty Fibonacci heap, the MAKE-FIB-HEAP procedure is used to allocate and return the Fibonacci heap object H, where n[H] = 0 and min[H] = NIL and there are no trees in H. Since t (H) = 0 and m(H) = 0, the potential of the empty Fibonacci heap is http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif(H) = 0. The amortized cost of MAKE-FIB-HEAP is thus equal to its O(1) actual cost.
Inserting a node
The FIB-HEAP-INSERT(H, x) procedure inserts node x into Fibonacci heap H, assuming the course that the node has already been allocated and that key[x] has already been filled in.
Algorithm:
degree[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif 0
p[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif NIL
child[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif NIL
left[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif x
right[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif x
mark[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif FALSE
concatenate the root list containing x with root list H
if min[H] = NIL or key[x] < key[min[H]]
then min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif x
n[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif n[H] + 1
FIB-HEAP-INSERT makes no effort to consolidate the trees within the Fibonacci heap. If k consecutive FIB-HEAP-INSERT operations occurs, then k single-node tree has been added to the root list.
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/425_a.gif
For determining the amortized cost of FIB-HEAP-INSERT, Consider H be the input Fibonacci heap and H' be the resulting Fibonacci heap. Then, t(H') = t(H) + 1 and m(H') = m(H), and the increase in potential is referred as
((t(H) + 1) + 2m(H)) - (t(H) + 2m(H)) = 1 .
Since the actual cost is O(1), the amortized cost is O(1) + 1 = O(1).
Finding the minimum node
The minimum node of a Fibonacci heap H is given by the pointer min[H], so find the minimum node in O(1) actual time. Since the potential of H does not change, the amortized cost of the operation is equal to its O(1) actual cost.
Uniting two Fibonacci heaps
The procedure given below unites Fibonacci heaps H1 and H2,by destroying H1 and H2 in the process.
FIB-HEAP-UNION(H1,H2)
1 H http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif MAKE-FIB-HEAP()
2 min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif min[H1]
3 concatenate the root list of H2 with the root list of H
4 if (min[H1] = NIL) or (min[H2] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/noteq.gif NIL and min[H2] < min[H1])
5 then min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif min[H2]
6 n[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif n[H1] + n[H2]
7 free the objects H1 and H2
8 return H
The change in potential is denoted as
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif(H) - (http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif(H1) + http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif(H2))= (t(H) + 2m(H)) - ((t(H1) + 2 m(H1)) + (t(H2) + 2m(H2)))= 0,
Since t(H) = t(H1) + t(H2) and m(H) = m(H1) + m(H2). The amortized cost of FIB-HEAP-UNION is hence equal to its O(1) actual cost.
Extracting the minimum node
The process of extracting the minimum node is the most difficult operations . It is the place where the delayed work of consolidating trees in the root list occurs. The following pseudocode extracts the minimum node.
FIB-HEAP-EXTRACT-MIN(H)
1 z http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif min[H]
2 if z http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/noteq.gif NIL
3 then for each child x of z
4 do add x to the root list of H
5 p[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif NIL
6 remove z from the root list of H
7 if z = right[z]
8 then min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif NIL
9 else min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif right[z]
10 CONSOLIDATE(H)
11 n[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif n[H] - 1
12 return z
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/428_a.gif
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/429_a.gif
The amortized cost of extracting the minimum node of an n-node Fibonacci heap is O(D(n)). Let H denote the Fibonacci heap just prior to the FIB-HEAP-EXTRACT-MIN operation.
The potential before extracting the minimum node is t(H) + 2m(H), and the potential afterward is at most (D(n) + 1) + 2m(H), since at most D(n) + 1 roots remain and no nodes become marked during the operation. The amortized cost is thus at most
O(D(n) + t(H)) + ((D(n) + 1) + 2m(H)) - (t(H) + 2m(H))
= O(D(n)) + O(t(H)) - t(H)
= O(D(n)),
because we can scale up the units of potential to dominate the constant hidden in O(t(H)). Intuitively, the cost of performing each link is paid for by the reduction in potential due to the link reducing the number of roots by one.
Decreasing a key and deleting a node
We can show how to decrease the key of a node in a Fibonacci heap in O(1) amortized time and how to delete any node from an n-node Fibonacci heap in O(D(n)) amortized timeThey are close enough,that we can bound the maximum degree D(n) by O(1g n). Proving this bound will imply that FIB-HEAP-EXTRACT-MIN and FIB-HEAP-DELETE run in O(1g n) amortized time.
Decreasing a key
In the below pseudocode for the operation FIB-HEAP-DECREASE-KEY, lets assume as before that removing a node from a linked list does not change any of the structural fields in the removed node.
FIB-HEAP-DECREASE-KEY(H,x,k)
1 if k > key[x]
2 then error "new key is greater than current key"
3 key[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif k
4 y http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif p[x]
5 if y http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/noteq.gif NIL and key[x] < key[y]
6 then CUT(H,x,y)
7 CASCADING-CUT(H,y)
8 if key[x] < key[min[H]]
9 then min[H] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif x
CUT(H,x,y)
1 remove x from the child list of y, decrementing degree[y]
2 add x to the root list of H
3 p[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif NIL
4 mark[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif FALSE
CASCADING-CUT(H,y)
1 z http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif p[y]
2 if z http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/noteq.gif NIL
3 then if mark[y] = FALSE
4 then mark[y] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/arrlt12.gif TRUE
5 else CUT(H,y,z)
6 CASCADING-CUT(H,z)
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/434_a.gif
Figure 21.4 Two calls of FIB-HEAP-DECREASE-KEY. (a) The initial Fibonacci heap. (b) The node with key 46 has its key decreased to 15. The node becomes a root, and its parent (with key 24), which had previously been unmarked, becomes marked. (c)-(e) The node with key 35 has its key decreased to 5. In part (c), the node, now with key 5, becomes a root. Its parent, with key 26, is marked, so a cascading cut occurs. The node with key 26 is cut from its parent and made an unmarked root in (d). Another cascading cut occurs, since the node with key 24 is marked as well. This node is cut from its parent and made an unmarked root in part (e). The cascading cuts stop at this point, since the node with key 7 is a root. (Even if this node were not a root, the cascading cuts would stop, since it is unmarked.) The result of the FIB-HEAP-DECREASE-KEY operation is shown in part (e), with min[H] pointing to the new minimum node.
Deleting a node
It is easy to delete a node from an n-node Fibonacci heap in O(D(n)) amortized time, as is done by the following pseudocode. We assume that there is no key value of -http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/infin.gif currently in the Fibonacci heap.
FIB-HEAP-DELETE(H, x)
1 FIB-HEAP-DECREASE-KEY(H, x, -http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/infin.gif)
2 FIB-HEAP-EXTRACT-MIN(H)
FIB-HEAP-DELETE is analogous to BINOMIAL-HEAP-DELETE. It makes x become the minimum node in the Fibonacci heap by giving it a uniquely small key of -http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/infin.gif. Node x is then removed from the Fibonacci heap by theFIB-HEAP-EXTRACT-MIN procedure. The amortized time of FIB-HEAP-DELETE is the sum of the O(1) amortized time of FIB-HEAP-DECREASE-KEY and the O(D(n)) amortized time of FIB-HEAP-EXTRACT-MIN.
Bounding the maximum degree
To prove that the amortized time of FIB-HEAP-EXTRACT-MIN and FIB-HEAP-DELETE is O(lg n), we must show that the upper bound D(n) on the degree of any node of an n-node Fibonacci heap is O(lg n). By Exercise 21.2-3, when all trees in the Fibonacci heap are unordered binomial trees, D(n) = http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdl12.giflg nhttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdr12.gif. The cuts that occur in FIB-HEAP-DECREASE-KEY, however, may cause trees within the Fibonacci heap to violate the unordered binomial tree properties. In this section, we shall show that because we cut a node from its parent as soon as it loses two children, D(n) is O(lg n). In particular, we shall show that D(n) http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/lteq12.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdl12.gifloghttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif nhttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdr12.gif, where http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/435_a.gif.
The key to the analysis is as follows. For each node x within a Fibonacci heap, define size(x) to be the number of nodes, including x itself, in the subtree rooted at x. (Note that x need not be in the root list--it can be any node at all.) We shall show that size(x) is exponential in degree[x]. Bear in mind that degree[x] is always maintained as an accurate count of the degree of x.
Lemma 21.1
Let x be any node in a Fibonacci heap, and suppose that degree[x] = k. Let y1, y2, ..., yk denote the children of x in the order in which they were linked to x, from the earliest to the latest. Then, degree [y1] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 0 anddegree[yi] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif i - 2 for i = 2, 3, . . . , k.
Proof Obviously, degree[y1] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 0.
For i http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 2, we note that when yi was linked to x, all of y1, y2, . . . , yi-1 were children of x, so we must have had degree[x] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif i - 1. Node yi is linked to x only if degree[x] = degree[yi], so we must have also haddegree[yi] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif i - 1 at that time. Since then, node yi has lost at most one child, since it would have been cut from x if it had lost two children. We conclude that degree [yi ] http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif i - 2.
We finally come to the part of the analysis that explains the name "Fibonacci heaps." Recall from Section 2.2 that for k = 0, 1, 2, . . . , the kth Fibonacci number is defined by the recurrence
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_a.gif
The following lemma gives another way to express Fk.
Lemma 21.2
For all integers k http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 0,
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_b.gif
Proof The proof is by induction on k. When k = 0,
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_c.gif
We now assume the inductive hypothesis that http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_d.gif, and we have
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_e.gif
The following lemma and its corollary complete the analysis. It uses the inequality (proved in Exercise 2.2-8)
Fk+2 http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gifk ,
where http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif is the golden ratio defined in equation (2.14) as http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/436_f.gif.
Lemma 21.3
Let x be any node in a Fibonacci heap, and let k = degree[x]. Then, size (x) http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif Fk+2 http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gifk, where http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif = http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/437_a.gif.
Proof Let sk denote the minimum possible value of size(z) over all nodes z such that degree[z] = k. Trivially, s0 = 1, s1 = 2, and s2 = 3. The number sk is at most size(x). As in Lemma 21.1, let y1, y2, . . . , yk denote the children of x in the order in which they were linked to x. To compute a lower bound on size(x), we count one for x itself and one for the first child y1 (for which size(y1) http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 1 ) and then apply Lemma 21.1 for the other children. We thus have
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/437_b.gif
We now show by induction on k that sk http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif Fk+2 for all nonnegative integer k. The bases, for k = 0 and k = 1, are trivial. For the inductive step, we assume that k http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif 2 and that si http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif Fi + 2 for i = 0, 1, . . . , k - 1. We have
http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/book6/437_c.gif
The last equality follows from Lemma 21.2.
Thus, we have shown that size(x) http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif sk + 2 http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gifk.
Corollary 21.4
The maximum degree D(n) of any node in an n-node Fibonacci heap is O(lg n).
Proof Let x be any node in an n-node Fibonacci heap, and let k = degree[x]. By Lemma 21.3, we have n http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif size(x) http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gifk. Taking base-http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif logarithms yields k http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/gteq.gif loghttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif n. (In fact, because k is an integer, k http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/lteq12.gif http://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdl12.gifloghttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/phicap12.gif nhttp://net.pku.edu.cn/~course/cs101/2007/resource/Intro2Algorithm/images/hfbrdr12.gif.) The maximum degree D(n) of any node is thus O(lg n).