Jump to content

Fibonacci heap: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Tags: repeating characters Possible vandalism
m Reverting possible vandalism by 14.139.238.98 to version by Wingedsubmariner. False positive? Report it. Thanks, ClueBot NG. (1963227) (Bot)
Line 1: Line 1:
In [[computer science]], a '''Fibonacci heap''' is a [[Heap (data structure)|heap data structure]] consisting of a collection of [[Tree (data structure)|tree]]s. It has a better [[amortized analysis|amortized]] running time than a [[binomial heap]]. Fibonacci heaps were developed by [[Michael Fredman|Michael L. Fredman]] and [[Robert Tarjan|Robert E. Tarjan]] in 1984 and first published in a scientific journal in 1987. The name of Fibonacci heap comes from [[Fibonacci number]]s which are used in the running time analysis.
GANGU

GANGU
Find-minimum is ''O''(1) amortized time.<ref name="CLRS">[[Thomas H. Cormen]], [[Charles E. Leiserson]], [[Ronald L. Rivest]], and [[Clifford Stein]]. ''[[Introduction to Algorithms]]'', Second Edition. [[MIT Press]] and McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 20: Fibonacci Heaps, pp.476&ndash;497. Third edition p518.</ref> Operations insert, decrease key, and merge (union) work in constant amortized time.<ref name="Fredman And Tarjan"/> Operations delete and delete minimum work in [[Big O notation|''O'']](log ''n'') amortized time.<ref name="Fredman And Tarjan"/> This means that starting from an empty data structure, any sequence of ''a'' operations from the first group and ''b'' operations from the second group would take ''O''(''a''&nbsp;+&nbsp;''b''&nbsp;log&nbsp;''n'') time. In a [[binomial heap]] such a sequence of operations would take ''O''((''a''&nbsp;+&nbsp;''b'') log (''n'')) time. A Fibonacci heap is thus better than a binomial heap when ''b'' is [[asymptotic analysis|asymptotically]] smaller than ''a''.
GANGU

GANGU
Using Fibonacci heaps for [[priority queue]]s improves the asymptotic running time of important algorithms, such as [[Dijkstra's algorithm]] for computing the [[shortest path]] between two nodes in a graph.
GANGU

GANGU
== Structure ==
GANGU
[[Image:Fibonacci heap.png|thumbnail|250px|Figure 1. Example of a Fibonacci heap. It has three trees of degrees 0, 1 and 3. Three vertices are marked (shown in blue). Therefore the potential of the heap is 9 (3 trees + 2 * marked-vertices).]]
GANGU
A Fibonacci heap is a collection of [[tree data structure|tree]]s satisfying the [[minimum-heap property]], that is, the key of a child is always greater than or equal to the key of the parent. This implies that the minimum key is always at the root of one of the trees. Compared with binomial heaps, the structure of a Fibonacci heap is more flexible. The trees do not have a prescribed shape and in the extreme case the heap can have every element in a separate tree. This flexibility allows some operations to be executed in a "lazy" manner, postponing the work for later operations. For example merging heaps is done simply by concatenating the two lists of trees, and operation ''decrease key'' sometimes cuts a node from its parent and forms a new tree.
GANGU

GANGU
However at some point some order needs to be introduced to the heap to achieve the desired running time. In particular, degrees of nodes (here degree means the number of children) are kept quite low: every node has degree at most ''O''(log ''n'') and the size of a subtree rooted in a node of degree ''k'' is at least ''F<sub>k</sub>''<sub>&nbsp;+&nbsp;2</sub>, where ''F<sub>k</sub>'' is the ''k''th [[Fibonacci number]]. This is achieved by the rule that we can cut at most one child of each non-root node. When a second child is cut, the node itself needs to be cut from its parent and becomes the root of a new tree (see Proof of degree bounds, below). The number of trees is decreased in the operation ''delete minimum'', where trees are linked together.
GANGU

GANGU
As a result of a relaxed structure, some operations can take a long time while others are done very quickly. For the [[amortized analysis|amortized running time]] analysis we use the [[potential method]], in that we pretend that very fast operations take a little bit longer than they actually do. This additional time is then later combined and subtracted from the actual running time of slow operations. The amount of time saved for later use is measured at any given moment by a potential function. The potential of a Fibonacci heap is given by
GANGU

GANGU
:Potential = ''t'' + 2''m''
GANGU

GANGU
where ''t'' is the number of trees in the Fibonacci heap, and ''m'' is the number of marked nodes. A node is marked if at least one of its children was cut since this node was made a child of another node (all roots are unmarked).
GANGU
The amortized time for an operation is given by the sum of the actual time and ''c'' times the difference in potential, where ''c'' is a constant (chosen to match the constant factors in the ''O'' notation for the actual time).
GANGU

GANGU
Thus, the root of each tree in a heap has one unit of time stored. This unit of time can be used later to link this tree with another tree at amortized time 0. Also, each marked node has two units of time stored. One can be used to cut the node from its parent. If this happens, the node becomes a root and the second unit of time will remain stored in it as in any other root.
GANGU

GANGU
== Implementation of operations ==
GANGU
To allow fast deletion and concatenation, the roots of all trees are linked using a circular, [[doubly linked list]]. The children of each node are also linked using such a list. For each node, we maintain its number of children and whether the node is marked. Moreover we maintain a pointer to the root containing the minimum key.
GANGU

GANGU
Operation '''find minimum''' is now trivial because we keep the pointer to the node containing it. It does not change the potential of the heap, therefore both actual and amortized cost is constant.
GANGU

GANGU
As mentioned above, '''merge''' is implemented simply by concatenating the lists of tree roots of the two heaps. This can be done in constant time and the potential does not change, leading again to constant amortized time.
GANGU

GANGU
Operation '''insert''' works by creating a new heap with one element and doing merge. This takes constant time, and the potential increases by one, because the number of trees increases. The amortized cost is thus still constant.
GANGU

GANGU
[[Image:Fibonacci heap extractmin1.png|170px|thumb|right|Fibonacci heap from Figure 1 after first phase of extract minimum. Node with key 1 (the minimum) was deleted and its children were added as separate trees.]]
GANGU
Operation '''extract minimum''' (same as ''delete minimum'') operates in three phases. First we take the root containing the minimum element and remove it. Its children will become roots of new trees. If the number of children was ''d'', it takes time ''O''(''d'') to process all new roots and the potential increases by ''d''−1. Therefore the amortized running time of this phase is ''O''(''d'') = ''O''(log ''n'').
GANGU

GANGU
[[Image:Fibonacci heap extractmin2.png|130px|thumb|left|Fibonacci heap from Figure 1 after extract minimum is completed. First, nodes 3 and 6 are linked together. Then the result is linked with tree rooted at node 2. Finally, the new minimum is found.]]
GANGU
However to complete the extract minimum operation, we need to update the pointer to the root with minimum key. Unfortunately there may be up to ''n'' roots we need to check. In the second phase we therefore decrease the number of roots by successively linking together roots of the same degree. When two roots ''u'' and ''v'' have the same degree, we make one of them a child of the other so that the one with the smaller key remains the root. Its degree will increase by one. This is repeated until every root has a different degree. To find trees of the same degree efficiently we use an array of length ''O''(log ''n'') in which we keep a pointer to one root of each degree. When a second root is found of the same degree, the two are linked and the array is updated. The actual running time is ''O''(log ''n'' + ''m'') where ''m'' is the number of roots at the beginning of the second phase. At the end we will have at most ''O''(log ''n'') roots (because each has a different degree). Therefore the difference in the potential function from before this phase to after it is: ''O''(log ''n'') − ''m'', and the amortized running time is then at most ''O''(log ''n'' + ''m'') + ''c''(''O''(log ''n'') − ''m''). With a sufficiently large choice of ''c'', this simplifies to ''O''(log ''n'').
GANGU

GANGU
In the third phase we check each of the remaining roots and find the minimum. This takes ''O''(log ''n'') time and the potential does not change. The overall amortized running time of extract minimum is therefore ''O''(log ''n'').
GANGU

GANGU
[[Image:Fibonacci heap-decreasekey.png|250px|thumb|right|Fibonacci heap from Figure 1 after decreasing key of node 9 to 0. This node as well as its two marked ancestors are cut from the tree rooted at 1 and placed as new roots.]]
GANGU
Operation '''decrease key''' will take the node, decrease the key and if the heap property becomes violated (the new key is smaller than the key of the parent), the node is cut from its parent. If the parent is not a root, it is marked. If it has been marked already, it is cut as well and its parent is marked. We continue upwards until we reach either the root or an unmarked node. In the process we create some number, say ''k'', of new trees. Each of these new trees except possibly the first one was marked originally but as a root it will become unmarked. One node can become marked. Therefore the number of marked nodes changes by &minus;(''k''&nbsp;&minus;&nbsp;1)&nbsp;+&nbsp;1&nbsp;=&nbsp;&minus;&nbsp;''k''&nbsp;+&nbsp;2. Combining these 2 changes, the potential changes by 2(&minus;''k''&nbsp;+&nbsp;2)&nbsp;+&nbsp;''k''&nbsp;=&nbsp;&minus;''k''&nbsp;+&nbsp;4. The actual time to perform the cutting was ''O''(''k''), therefore (again with a sufficiently large choice of ''c'') the amortized running time is constant.
GANGU

GANGU
Finally, operation '''delete''' can be implemented simply by decreasing the key of the element to be deleted to minus infinity, thus turning it into the minimum of the whole heap. Then we call extract minimum to remove it. The amortized running time of this operation is ''O''(log ''n'').
GANGU

GANGU
==Proof of degree bounds==
GANGU
The amortized performance of a Fibonacci heap depends on the degree (number of children) of any tree root being ''O''(log ''n''), where ''n'' is the size of the heap. Here we show that the size of the (sub)tree rooted at any node ''x'' of degree ''d'' in the heap must have size at least ''F<sub>d</sub>''<sub>+2</sub>, where ''F<sub>k</sub>'' is the ''k''th [[Fibonacci number]]. The degree bound follows from this and the fact (easily proved by induction) that <math>F_{d+2} \ge \varphi^d</math> for all integers <math>d\ge 0</math>, where <math>\varphi = (1+\sqrt 5)/2 \doteq 1.618</math>. (We then have <math>n \ge F_{d+2} \ge \varphi^d</math>, and taking the log to base <math>\varphi</math> of both sides gives <math>d\le \log_{\varphi} n</math> as required.)
GANGU

GANGU
Consider any node ''x'' somewhere in the heap (''x'' need not be the root of one of the main trees). Define '''size'''(''x'') to be the size of the tree rooted at ''x'' (the number of descendants of ''x'', including ''x'' itself). We prove by induction on the height of ''x'' (the length of a longest simple path from ''x'' to a descendant leaf), that '''size'''(''x'')&nbsp;≥&nbsp;''F<sub>d</sub>''<sub>+2</sub>, where ''d'' is the degree of ''x''.
GANGU

GANGU
'''Base case:''' If ''x'' has height 0, then ''d''&nbsp;=&nbsp;0, and '''size'''(''x'')&nbsp;=&nbsp;1&nbsp;=&nbsp;''F''<sub>2</sub>.
GANGU

GANGU
'''Inductive case:''' Suppose ''x'' has positive height and degree ''d''&gt;0. Let ''y''<sub>1</sub>, ''y''<sub>2</sub>, ..., ''y<sub>d</sub>'' be the children of ''x'', indexed in order of the times they were most recently made children of ''x'' (''y''<sub>1</sub> being the earliest and ''y<sub>d</sub>'' the latest), and let ''c''<sub>1</sub>, ''c''<sub>2</sub>, ..., ''c<sub>d</sub>'' be their respective degrees. We '''claim''' that ''c<sub>i</sub>''&nbsp;≥&nbsp;''i''-2 for each ''i'' with 2≤''i''≤''d'': Just before ''y<sub>i</sub>'' was made a child of ''x'', ''y''<sub>1</sub>,...,''y<sub>i</sub>''<sub>−1</sub> were already children of ''x'', and so ''x'' had degree at least ''i''−1 at that time. Since trees are combined only when the degrees of their roots are equal, it must have been that ''y<sub>i</sub>'' also had degree at least ''i''-1 at the time it became a child of ''x''. From that time to the present, ''y<sub>i</sub>'' can only have lost at most one child (as guaranteed by the marking process), and so its current degree ''c<sub>i</sub>'' is at least ''i''−2. This proves the '''claim'''.
GANGU

GANGU
Since the heights of all the ''y<sub>i</sub>'' are strictly less than that of ''x'', we can apply the inductive hypothesis to them to get '''size'''(''y<sub>i</sub>'')&nbsp;≥&nbsp;''F<sub>c<sub>i</sub></sub>''<sub>+2</sub>&nbsp;≥&nbsp;''F''<sub>(''i''−2)+2</sub>&nbsp;=&nbsp;''F<sub>i</sub>''. The nodes ''x'' and ''y''<sub>1</sub> each contribute at least 1 to '''size'''(''x''), and so we have
GANGU

GANGU
<math>\textbf{size}(x) \ge 2 + \sum_{i=2}^d \textbf{size}(y_i) \ge 2 + \sum_{i=2}^d F_i = 1 + \sum_{i=0}^d F_i.</math>
GANGU

GANGU
A routine induction proves that <math>1 + \sum_{i=0}^d F_i = F_{d+2}</math> for any <math>d\ge 0</math>, which gives the desired lower bound on '''size'''(''x'').
GANGU

GANGU
==Worst case==
GANGU
Although the total running time of a sequence of operations starting with an empty structure is bounded by the bounds given above, some (very few) operations in the sequence can take very long to complete (in particular delete and delete minimum have linear running time in the worst case). For this reason Fibonacci heaps and other amortized data structures may not be appropriate for [[real-time computing|real-time systems]]. It is possible to create a data structure which has the same worst-case performance as the Fibonacci heap has amortized performance.<ref name="bare_url">{{Citation |id = [[CiteSeerX]]: {{url|1=citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.8133|2=10.1.1.43.8133}} |title=Worst-Case Efficient Priority Queues |year=1996 |author=Gerth Stølting Brodal |journal=Proc. 7th ACM-SIAM Symposium on Discrete Algorithms |publisher = [[Society for Industrial and Applied Mathematics]]|pages=52–58 |doi=10.1145/313852.313883 |isbn=0-89871-366-8}}</ref> However the resulting structure (a [[Brodal queue]]) is, in the words of the creator, "quite complicated" and "[not] applicable in practice."
GANGU

GANGU
==Summary of running times==
GANGU
{{Heap Running Times}}
GANGU

GANGU
== References ==
GANGU
{{reflist}}
GANGU

GANGU
== External links ==
GANGU
* [http://www.cs.yorku.ca/~aaw/Jason/FibonacciHeapAnimation.html Java applet simulation of a Fibonacci heap]
GANGU
* [http://www.mathworks.com/matlabcentral/fileexchange/30072-fibonacci-heap MATLAB implementation of Fibonacci heap]
GANGU
* [http://www.labri.fr/perso/pelegrin/code/#fibonacci De-recursived and memory efficient C implementation of Fibonacci heap] (free/libre software, [http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html CeCILL-B license])
GANGU
* [http://github.com/evansenter/f_heap Ruby implementation of the Fibonacci heap (with tests)]
GANGU
* [http://www.cs.princeton.edu/~wayne/cs423/fibonacci/FibonacciHeapAlgorithm.html Pseudocode of the Fibonacci heap algorithm]
GANGU
* [http://stackoverflow.com/q/6273833/194609 Various Java Implementations for Fibonacci heap]
GANGU

GANGU
{{Data structures}}
GANGU

GANGU
{{DEFAULTSORT:Fibonacci Heap}}
GANGU
[[Category:Fibonacci numbers]]
GANGU
[[Category:Heaps (data structures)]]
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU1
GANGU2
GANGU3
GANGU4
GANGU5
GANGU5
GANGU6
GANGU7
GANGU8
GANGU9
GANGU
GANGU543
GANGU54
GANGU1234
GANGU5
GANGU46246
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU
GANGU

Revision as of 08:34, 23 September 2014

In computer science, a Fibonacci heap is a heap data structure consisting of a collection of trees. It has a better amortized running time than a binomial heap. Fibonacci heaps were developed by Michael L. Fredman and Robert E. Tarjan in 1984 and first published in a scientific journal in 1987. The name of Fibonacci heap comes from Fibonacci numbers which are used in the running time analysis.

Find-minimum is O(1) amortized time.[1] Operations insert, decrease key, and merge (union) work in constant amortized time.[2] Operations delete and delete minimum work in O(log n) amortized time.[2] This means that starting from an empty data structure, any sequence of a operations from the first group and b operations from the second group would take O(a + b log n) time. In a binomial heap such a sequence of operations would take O((a + b) log (n)) time. A Fibonacci heap is thus better than a binomial heap when b is asymptotically smaller than a.

Using Fibonacci heaps for priority queues improves the asymptotic running time of important algorithms, such as Dijkstra's algorithm for computing the shortest path between two nodes in a graph.

Structure

Figure 1. Example of a Fibonacci heap. It has three trees of degrees 0, 1 and 3. Three vertices are marked (shown in blue). Therefore the potential of the heap is 9 (3 trees + 2 * marked-vertices).

A Fibonacci heap is a collection of trees satisfying the minimum-heap property, that is, the key of a child is always greater than or equal to the key of the parent. This implies that the minimum key is always at the root of one of the trees. Compared with binomial heaps, the structure of a Fibonacci heap is more flexible. The trees do not have a prescribed shape and in the extreme case the heap can have every element in a separate tree. This flexibility allows some operations to be executed in a "lazy" manner, postponing the work for later operations. For example merging heaps is done simply by concatenating the two lists of trees, and operation decrease key sometimes cuts a node from its parent and forms a new tree.

However at some point some order needs to be introduced to the heap to achieve the desired running time. In particular, degrees of nodes (here degree means the number of children) are kept quite low: every node has degree at most O(log n) and the size of a subtree rooted in a node of degree k is at least Fk + 2, where Fk is the kth Fibonacci number. This is achieved by the rule that we can cut at most one child of each non-root node. When a second child is cut, the node itself needs to be cut from its parent and becomes the root of a new tree (see Proof of degree bounds, below). The number of trees is decreased in the operation delete minimum, where trees are linked together.

As a result of a relaxed structure, some operations can take a long time while others are done very quickly. For the amortized running time analysis we use the potential method, in that we pretend that very fast operations take a little bit longer than they actually do. This additional time is then later combined and subtracted from the actual running time of slow operations. The amount of time saved for later use is measured at any given moment by a potential function. The potential of a Fibonacci heap is given by

Potential = t + 2m

where t is the number of trees in the Fibonacci heap, and m is the number of marked nodes. A node is marked if at least one of its children was cut since this node was made a child of another node (all roots are unmarked). The amortized time for an operation is given by the sum of the actual time and c times the difference in potential, where c is a constant (chosen to match the constant factors in the O notation for the actual time).

Thus, the root of each tree in a heap has one unit of time stored. This unit of time can be used later to link this tree with another tree at amortized time 0. Also, each marked node has two units of time stored. One can be used to cut the node from its parent. If this happens, the node becomes a root and the second unit of time will remain stored in it as in any other root.

Implementation of operations

To allow fast deletion and concatenation, the roots of all trees are linked using a circular, doubly linked list. The children of each node are also linked using such a list. For each node, we maintain its number of children and whether the node is marked. Moreover we maintain a pointer to the root containing the minimum key.

Operation find minimum is now trivial because we keep the pointer to the node containing it. It does not change the potential of the heap, therefore both actual and amortized cost is constant.

As mentioned above, merge is implemented simply by concatenating the lists of tree roots of the two heaps. This can be done in constant time and the potential does not change, leading again to constant amortized time.

Operation insert works by creating a new heap with one element and doing merge. This takes constant time, and the potential increases by one, because the number of trees increases. The amortized cost is thus still constant.

Fibonacci heap from Figure 1 after first phase of extract minimum. Node with key 1 (the minimum) was deleted and its children were added as separate trees.

Operation extract minimum (same as delete minimum) operates in three phases. First we take the root containing the minimum element and remove it. Its children will become roots of new trees. If the number of children was d, it takes time O(d) to process all new roots and the potential increases by d−1. Therefore the amortized running time of this phase is O(d) = O(log n).

Fibonacci heap from Figure 1 after extract minimum is completed. First, nodes 3 and 6 are linked together. Then the result is linked with tree rooted at node 2. Finally, the new minimum is found.

However to complete the extract minimum operation, we need to update the pointer to the root with minimum key. Unfortunately there may be up to n roots we need to check. In the second phase we therefore decrease the number of roots by successively linking together roots of the same degree. When two roots u and v have the same degree, we make one of them a child of the other so that the one with the smaller key remains the root. Its degree will increase by one. This is repeated until every root has a different degree. To find trees of the same degree efficiently we use an array of length O(log n) in which we keep a pointer to one root of each degree. When a second root is found of the same degree, the two are linked and the array is updated. The actual running time is O(log n + m) where m is the number of roots at the beginning of the second phase. At the end we will have at most O(log n) roots (because each has a different degree). Therefore the difference in the potential function from before this phase to after it is: O(log n) − m, and the amortized running time is then at most O(log n + m) + c(O(log n) − m). With a sufficiently large choice of c, this simplifies to O(log n).

In the third phase we check each of the remaining roots and find the minimum. This takes O(log n) time and the potential does not change. The overall amortized running time of extract minimum is therefore O(log n).

Fibonacci heap from Figure 1 after decreasing key of node 9 to 0. This node as well as its two marked ancestors are cut from the tree rooted at 1 and placed as new roots.

Operation decrease key will take the node, decrease the key and if the heap property becomes violated (the new key is smaller than the key of the parent), the node is cut from its parent. If the parent is not a root, it is marked. If it has been marked already, it is cut as well and its parent is marked. We continue upwards until we reach either the root or an unmarked node. In the process we create some number, say k, of new trees. Each of these new trees except possibly the first one was marked originally but as a root it will become unmarked. One node can become marked. Therefore the number of marked nodes changes by −(k − 1) + 1 = − k + 2. Combining these 2 changes, the potential changes by 2(−k + 2) + k = −k + 4. The actual time to perform the cutting was O(k), therefore (again with a sufficiently large choice of c) the amortized running time is constant.

Finally, operation delete can be implemented simply by decreasing the key of the element to be deleted to minus infinity, thus turning it into the minimum of the whole heap. Then we call extract minimum to remove it. The amortized running time of this operation is O(log n).

Proof of degree bounds

The amortized performance of a Fibonacci heap depends on the degree (number of children) of any tree root being O(log n), where n is the size of the heap. Here we show that the size of the (sub)tree rooted at any node x of degree d in the heap must have size at least Fd+2, where Fk is the kth Fibonacci number. The degree bound follows from this and the fact (easily proved by induction) that for all integers , where . (We then have , and taking the log to base of both sides gives as required.)

Consider any node x somewhere in the heap (x need not be the root of one of the main trees). Define size(x) to be the size of the tree rooted at x (the number of descendants of x, including x itself). We prove by induction on the height of x (the length of a longest simple path from x to a descendant leaf), that size(x) ≥ Fd+2, where d is the degree of x.

Base case: If x has height 0, then d = 0, and size(x) = 1 = F2.

Inductive case: Suppose x has positive height and degree d>0. Let y1, y2, ..., yd be the children of x, indexed in order of the times they were most recently made children of x (y1 being the earliest and yd the latest), and let c1, c2, ..., cd be their respective degrees. We claim that ci ≥ i-2 for each i with 2≤id: Just before yi was made a child of x, y1,...,yi−1 were already children of x, and so x had degree at least i−1 at that time. Since trees are combined only when the degrees of their roots are equal, it must have been that yi also had degree at least i-1 at the time it became a child of x. From that time to the present, yi can only have lost at most one child (as guaranteed by the marking process), and so its current degree ci is at least i−2. This proves the claim.

Since the heights of all the yi are strictly less than that of x, we can apply the inductive hypothesis to them to get size(yi) ≥ Fci+2 ≥ F(i−2)+2 = Fi. The nodes x and y1 each contribute at least 1 to size(x), and so we have

A routine induction proves that for any , which gives the desired lower bound on size(x).

Worst case

Although the total running time of a sequence of operations starting with an empty structure is bounded by the bounds given above, some (very few) operations in the sequence can take very long to complete (in particular delete and delete minimum have linear running time in the worst case). For this reason Fibonacci heaps and other amortized data structures may not be appropriate for real-time systems. It is possible to create a data structure which has the same worst-case performance as the Fibonacci heap has amortized performance.[3] However the resulting structure (a Brodal queue) is, in the words of the creator, "quite complicated" and "[not] applicable in practice."

Summary of running times

Here are time complexities[1] of various heap data structures. The abbreviation am. indicates that the given complexity is amortized, otherwise it is a worst-case complexity. For the meaning of "O(f)" and "Θ(f)" see Big O notation. Names of operations assume a min-heap.

Operation find-min delete-min decrease-key insert meld make-heap[a]
Binary[1] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(n) Θ(n)
Skew[4] Θ(1) O(log n) am. O(log n) am. O(log n) am. O(log n) am. Θ(n) am.
Leftist[5] Θ(1) Θ(log n) Θ(log n) Θ(log n) Θ(log n) Θ(n)
Binomial[1][7] Θ(1) Θ(log n) Θ(log n) Θ(1) am. Θ(log n)[b] Θ(n)
Skew binomial[8] Θ(1) Θ(log n) Θ(log n) Θ(1) Θ(log n)[b] Θ(n)
2–3 heap[10] Θ(1) O(log n) am. Θ(1) Θ(1) am. O(log n)[b] Θ(n)
Bottom-up skew[4] Θ(1) O(log n) am. O(log n) am. Θ(1) am. Θ(1) am. Θ(n) am.
Pairing[11] Θ(1) O(log n) am. o(log n) am.[c] Θ(1) Θ(1) Θ(n)
Rank-pairing[14] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Fibonacci[1][2] Θ(1) O(log n) am. Θ(1) am. Θ(1) Θ(1) Θ(n)
Strict Fibonacci[15][d] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)
Brodal[16][d] Θ(1) Θ(log n) Θ(1) Θ(1) Θ(1) Θ(n)[17]
  1. ^ make-heap is the operation of building a heap from a sequence of n unsorted elements. It can be done in Θ(n) time whenever meld runs in O(log n) time (where both complexities can be amortized).[4][5] Another algorithm achieves Θ(n) for binary heaps.[6]
  2. ^ a b c For persistent heaps (not supporting decrease-key), a generic transformation reduces the cost of meld to that of insert, while the new cost of delete-min is the sum of the old costs of delete-min and meld.[9] Here, it makes meld run in Θ(1) time (amortized, if the cost of insert is) while delete-min still runs in O(log n). Applied to skew binomial heaps, it yields Brodal-Okasaki queues, persistent heaps with optimal worst-case complexities.[8]
  3. ^ Lower bound of [12] upper bound of [13]
  4. ^ a b Brodal queues and strict Fibonacci heaps achieve optimal worst-case complexities for heaps. They were first described as imperative data structures. The Brodal-Okasaki queue is a persistent data structure achieving the same optimum, except that decrease-key is not supported.

References

  1. ^ a b c d e Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Chapter 20: Fibonacci Heaps, pp.476–497. Third edition p518. Cite error: The named reference "CLRS" was defined multiple times with different content (see the help page).
  2. ^ a b c Fredman, Michael Lawrence; Tarjan, Robert E. (July 1987). "Fibonacci heaps and their uses in improved network optimization algorithms" (PDF). Journal of the Association for Computing Machinery. 34 (3): 596–615. CiteSeerX 10.1.1.309.8927. doi:10.1145/28869.28874.
  3. ^ Gerth Stølting Brodal (1996), "Worst-Case Efficient Priority Queues", Proc. 7th ACM-SIAM Symposium on Discrete Algorithms, Society for Industrial and Applied Mathematics: 52–58, doi:10.1145/313852.313883, ISBN 0-89871-366-8, CiteSeerX: 10.1.1.43.8133
  4. ^ a b c Sleator, Daniel Dominic; Tarjan, Robert Endre (February 1986). "Self-Adjusting Heaps". SIAM Journal on Computing. 15 (1): 52–69. CiteSeerX 10.1.1.93.6678. doi:10.1137/0215004. ISSN 0097-5397.
  5. ^ a b Tarjan, Robert (1983). "3.3. Leftist heaps". Data Structures and Network Algorithms. pp. 38–42. doi:10.1137/1.9781611970265. ISBN 978-0-89871-187-5.
  6. ^ Hayward, Ryan; McDiarmid, Colin (1991). "Average Case Analysis of Heap Building by Repeated Insertion" (PDF). J. Algorithms. 12: 126–153. CiteSeerX 10.1.1.353.7888. doi:10.1016/0196-6774(91)90027-v. Archived from the original (PDF) on 2016-02-05. Retrieved 2016-01-28.
  7. ^ "Binomial Heap | Brilliant Math & Science Wiki". brilliant.org. Retrieved 2019-09-30.
  8. ^ a b Brodal, Gerth Stølting; Okasaki, Chris (November 1996), "Optimal purely functional priority queues", Journal of Functional Programming, 6 (6): 839–857, doi:10.1017/s095679680000201x
  9. ^ Okasaki, Chris (1998). "10.2. Structural Abstraction". Purely Functional Data Structures (1st ed.). pp. 158–162. ISBN 9780521631242.
  10. ^ Takaoka, Tadao (1999), Theory of 2–3 Heaps (PDF), p. 12
  11. ^ Iacono, John (2000), "Improved upper bounds for pairing heaps", Proc. 7th Scandinavian Workshop on Algorithm Theory (PDF), Lecture Notes in Computer Science, vol. 1851, Springer-Verlag, pp. 63–77, arXiv:1110.4428, CiteSeerX 10.1.1.748.7812, doi:10.1007/3-540-44985-X_5, ISBN 3-540-67690-2
  12. ^ Fredman, Michael Lawrence (July 1999). "On the Efficiency of Pairing Heaps and Related Data Structures" (PDF). Journal of the Association for Computing Machinery. 46 (4): 473–501. doi:10.1145/320211.320214.
  13. ^ Pettie, Seth (2005). Towards a Final Analysis of Pairing Heaps (PDF). FOCS '05 Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science. pp. 174–183. CiteSeerX 10.1.1.549.471. doi:10.1109/SFCS.2005.75. ISBN 0-7695-2468-0.
  14. ^ Haeupler, Bernhard; Sen, Siddhartha; Tarjan, Robert E. (November 2011). "Rank-pairing heaps" (PDF). SIAM J. Computing. 40 (6): 1463–1485. doi:10.1137/100785351.
  15. ^ Brodal, Gerth Stølting; Lagogiannis, George; Tarjan, Robert E. (2012). Strict Fibonacci heaps (PDF). Proceedings of the 44th symposium on Theory of Computing - STOC '12. pp. 1177–1184. CiteSeerX 10.1.1.233.1740. doi:10.1145/2213977.2214082. ISBN 978-1-4503-1245-5.
  16. ^ Brodal, Gerth S. (1996), "Worst-Case Efficient Priority Queues" (PDF), Proc. 7th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 52–58
  17. ^ Goodrich, Michael T.; Tamassia, Roberto (2004). "7.3.6. Bottom-Up Heap Construction". Data Structures and Algorithms in Java (3rd ed.). pp. 338–341. ISBN 0-471-46983-1.