ArticleslgStudy

computer science

Fibonacci heap

Fibonacci heap is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Fibonacci heap rather than just read about it. In short: In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the binary heap and binomial heap.

Fibonacci heap — main illustration
Fibonacci heap — illustration

Key takeaways

  • Fibonacci heap belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Fibonacci heap to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Fibonacci heap from memory before moving on to harder problems.

Reference excerpt

In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the binary heap and binomial heap. Michael L. Fredman and Robert E. Tarjan developed Fibonacci heaps in 1984 and published them in a scientific journal in 1987. Fibonacci heaps are named after the Fibonacci numbers, which are used in their running time analysis. The amortized times of all operations on Fibonacci heaps is constant, except delete-min. Deleting an element (most often used in the special case of deleting the minimum element) works in O(log⁡n) amortized time, where n is the size of the heap. This means that starting from an empty data structure, any sequence of a insert and decrease-key operations and b delete-min operations would take O(a+blog⁡n) worst case time, where n is the maximum heap size. In a binary or binomial heap, such a sequence of operations would take O((a+b)log⁡n) time. A Fibonacci heap is thus better than a binary or binomial heap when b is smaller than a by a non-constant factor. It is also possible to merge two Fibonacci heaps in constant amortized time, improving on the logarithmic merge time of a binomial heap, and improving on binary heaps which cannot handle merges efficiently. Using Fibonacci heaps improves the asymptotic running time of algorithms which utilize priority queues. For example, Dijkstra's algorithm and Prim's algorithm can be made to run in O(|E|+|V|log⁡|V|) time.

Structure

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 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 direct children) are kept quite low: every node has degree at most log⁡n and the size of a subtree rooted in a node of degree k is at least Fk+2, where Fi is the ith Fibonacci number. This is achieved by the rule: at most one child can be cut off 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-min, 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 ϕ=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 big 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.

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.

Find-min We maintain a pointer to the root containing the minimum key, allowing O(1) access to the minimum. This pointer must be updated during the other operations, which adds only a constant time overhead.

Merge The merge operation simply concatenates the root lists of two heaps together and sets the minimum to be the smaller of the two heaps. This can be done in constant time, and the potential does not change, leading again to constant amortized time.

Insert The insertion operation can be considered a special case of the merge operation, with a single node. The node is simply appended to the root list, increasing the potential by one. The amortized cost is thus still constant.

Delete-min

The delete-min operation does most of the work in restoring the structure of the heap. It has three phases:

… excerpt ends here. Continue reading the full article.

Illustrations

Fibonacci heap: Figure 2. First phase of delete-min.
Figure 2. First phase of delete-min.
Fibonacci heap: Figure 3. Third phase of delete-min.
Figure 3. Third phase of delete-min.
Fibonacci heap: Figure 4. Fibonacci heap from Figure 1 after decreasing key of node 9 to 0.
Figure 4. Fibonacci heap from Figure 1 after decreasing key of node 9 to 0.

Worked examples

Example 1 — a first encounter with Fibonacci heap

Start with the simplest possible case. Write down what Fibonacci heap claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Fibonacci heap before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Fibonacci heap ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Fibonacci heap

In research
Fibonacci heap appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Fibonacci heap in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Fibonacci heap is common in secondary-school and first-year university syllabi. It links to neighbouring topics Amortized data structures, Fibonacci numbers, Heaps (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for Fibonacci heap outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Fibonacci heap” →

How to study Fibonacci heap in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Fibonacci heap means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Fibonacci heap out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Fibonacci heap in simple terms?

In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the binary heap and binomial heap.

Why does Fibonacci heap matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Fibonacci heap?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Fibonacci heap.

Tags

  • Amortized data structures
  • Fibonacci numbers
  • Heaps (data structures)

Keep exploring