79

Fibonacci numbers have become a popular introduction to recursion for Computer Science students and there's a strong argument that they persist within nature. For these reasons, many of us are familiar with them.

They also exist within Computer Science elsewhere too; in surprisingly efficient data structures and algorithms based upon the sequence.

There are two main examples that come to mind:

  • Fibonacci heaps which have better amortized running time than binomial heaps.
  • Fibonacci search which shares O(log N) running time with binary search on an ordered array.

Is there some special property of these numbers that gives them an advantage over other numerical sequences? Is it a spatial quality? What other possible applications could they have?

It seems strange to me as there are many natural number sequences that occur in other recursive problems, but I've never seen a Catalan heap.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Ian Bishop
  • 5,185
  • 3
  • 26
  • 37
  • Wouldn't familiarity be the largest factor? – Cyclone Dec 31 '10 at 18:27
  • 13
    I think this kind of question belongs on either the cstheory or math SE. Intriguing, but OT. – Fred Foo Dec 31 '10 at 18:42
  • 7
    @larsmans Disagree. One of the most interesting questions I've seen lately, and its relevance is backed by the fact that as programmers, we see it everywhere. – Mike Dec 31 '10 at 18:44
  • 2
    This appears to be related to the ["Applications of the fibonacci sequence"](http://math.stackexchange.com/questions/381/applications-of-the-fibonacci-sequence) asked over on [math.stackexchange.com](http://math.stackexchange.com). There are other similar questions over there about specific applications of the sequence. That's probably a good place to discuss the "properties" of the sequence in general, and as it applies to more general algorithms. It seems to me that this question is approaching a discussion of computational theory which might get better/more attention there. – RobertB Dec 31 '10 at 18:45
  • hmm, I am using FN in the context of recursion mostly to show that simple recursive approach might be totally inefficient while we are talking about imperative languages (the next step is to introduce the Dynamic Prgoramming) concept. To show the usability of recursive approach I like problems similar to [this one](http://www.spoj.pl/HSPLARCH/problems/HS10SUMS/) – kuszi Dec 31 '10 at 18:46
  • 1
    I'm with larsmans on this one (obviously), and I agree that cstheory would be another good place to go with this. – RobertB Dec 31 '10 at 18:48
  • @kuszi The comment was simply an observation, not a claim it is in anyway superior to anything else. If you look up (http://stackoverflow.com/questions/tagged/fibonacci) you will notice that almost all (save this one) 65 of these questions are homework. – Ian Bishop Dec 31 '10 at 18:49

10 Answers10

71

The Fibonacci numbers have all sorts of really nice mathematical properties that make them excellent in computer science. Here's a few:

  1. They grow exponentially fast. One interesting data structure in which the Fibonacci series comes up is the AVL tree, a form of self-balancing binary tree. The intuition behind this tree is that each node maintains a balance factor so that the heights of the left and right subtree differ by at most one. Because of this, you can think of the minimum number of nodes necessary to get an AVL tree of height h is defined by a recurrence that looks like N(h + 2) ~= N(h) + N(h + 1), which looks a lot like the Fibonacci series. If you work out the math, you can show that the number of nodes necessary to get an AVL tree of height h is F(h + 2) - 1. Because the Fibonacci series grows exponentially fast, this means that the height of an AVL tree is at most logarithmic in the number of nodes, giving you the O(lg n) lookup time we know and love about balanced binary trees. In fact, if you can bound the size of some structure with a Fibonacci number, you're likely to get an O(lg n) runtime on some operation. This is the real reason that Fibonacci heaps are called Fibonacci heaps - the proof that the number of heaps after a dequeue min involves bounding the number of nodes you can have in a certain depth with a Fibonacci number.
  2. Any number can be written as the sum of unique Fibonacci numbers. This property of the Fibonacci numbers is critical to getting Fibonacci search working at all; if you couldn't add together unique Fibonacci numbers into any possible number, this search wouldn't work. Contrast this with a lot of other series, like 3n or the Catalan numbers. This is also partially why a lot of algorithms like powers of two, I think.
  3. The Fibonacci numbers are efficiently computable. The fact that the series can be generated extremely efficiently (you can get the first n terms in O(n) or any arbitrary term in O(lg n)), then a lot of the algorithms that use them wouldn't be practical. Generating Catalan numbers is pretty computationally tricky, IIRC. On top of this, the Fibonacci numbers have a nice property where, given any two consecutive Fibonacci numbers, let's say F(k) and F(k + 1), we can easily compute the next or previous Fibonacci number by adding the two values (F(k) + F(k + 1) = F(k + 2)) or subtracting them (F(k + 1) - F(k) = F(k - 1)). This property is exploited in several algorithms, in conjunction with property (2), to break apart numbers into the sum of Fibonacci numbers. For example, Fibonacci search uses this to locate values in memory, while a similar algorithm can be used to quickly and efficiently compute logarithms.
  4. They're pedagogically useful. Teaching recursion is tricky, and the Fibonacci series is a great way to introduce it. You can talk about straight recursion, about memoization, or about dynamic programming when introducing the series. Additionally, the amazing closed-form for the Fibonacci numbers is often taught as an exercise in induction or in the analysis of infinite series, and the related matrix equation for Fibonacci numbers is commonly introduced in linear algebra as a motivation behind eigenvectors and eigenvalues. I think that this is one of the reasons that they're so high-profile in introductory classes.

I'm sure there are more reasons than just this, but I'm sure that some of these reasons are the main factors. Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • 31
    All this also applies to powers of 2 ;-) –  Jan 01 '11 at 00:11
  • Generating Catalan numbers in order in "O(n)": `perl -Mbignum -le'$n=0;$c=1;while(1){$n++;$c*=(4*$n-2);$c/=($n+1);print"$n\t$c"}' | head -n 100` – A. Rex Jan 05 '11 at 21:33
  • 3
    In #2 it's important that the fibonacci numbers to be non-consecutive so the sum can be unique. – kunigami Jan 05 '11 at 22:40
  • 1
    What makes Fibonacci search useful is that their generating polynomial is x^2-x-1. Fibonacci search shares properties with the Golden Ratio Search for the minimum of a continuous function. – Alexandre C. Aug 04 '11 at 20:54
  • @Alexandre C.- Can you elaborate on this? I'm not familiar with why that particular generating polynomial is useful. – templatetypedef Aug 09 '11 at 07:53
  • Fibonacci numbers can also be used in Fibonacci primality tests (not the best way of testing, but eh)... with the exception of p=5, p will always divide either F(p-1) or F(p+1), and the modulus (of 5) of p determines which. Its probabilistic by itself, but in conjunction with other probabilistic tests like fermat test, there are some deterministic models. – CogitoErgoCogitoSum Nov 29 '21 at 00:40
  • *"Teaching recursion is tricky"* << Personally I have always found that teaching recursion was easier than teaching iteration. Recursion is way more "natural" for a human being than a for-loop or while-loop. – Stef Jun 10 '22 at 09:26
4

Greatest Common Divisor is another magic; see this for too many magics. But Fibonacci numbers are easy to calculate; also it has a specific name. For example, natural numbers 1,2,3,4,5 have too many logic; all primes are within them; sum of 1..n is computable, each one can produce with other ones, ... but no one take care about them :)

One important thing I forgot about it is Golden Ratio, which has very important impact in real life (for example you like wide monitors :)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
1

If you have an algorithm that can be successfully explained in a simple and concise mannor with understandable examples in CS and nature, what better teaching tool could someone come up with?

savalia
  • 57
  • 8
1

Fibonacci sequences are indeed found everywhere in nature/life. They're useful at modeling growth of animal populations, plant cell growth, snowflake shape, plant shape, cryptography, and of course computer science. I've heard it being referred to as the DNA pattern of nature.

Fibonacci heap's have already been mentioned; the number of children of each node in the heap is at most log(n). Also the subtree starting a node with m children is at least (m+2)th fibonacci number.

Torrent like protocols which use a system of nodes and supernodes use a fibonacci to decide when a new super node is needed and how many subnodes it will manage. They do node management based on the fibonacci spiral (golden ratio). See the photo below how nodes are split/merged (partitioned from one large square into smaller ones and vice versa). See photo: http://smartpei.typepad.com/.a/6a00d83451db7969e20115704556bd970b-pi

Some occurences in nature

http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/sneezewort.GIF

http://img.blogster.com/view/anacoana/post-uploads/finger.gif

http://jwilson.coe.uga.edu/EMAT6680/Simmons/6690Pictures/pinecone3yellow.gif

http://2.bp.blogspot.com/-X5II-IhjXuU/TVbHrpmRnLI/AAAAAAAAABU/nv73Y9Ylkkw/s320/amazing_fun_featured_2561778790105101600S600x600Q85_200907231856306879.jpg

Community
  • 1
  • 1
Adrian
  • 5,603
  • 8
  • 53
  • 85
0

Their computation as a power of [[0,1],[1,1]] matrix can be considered as the most primitive problem of Operational Research (sort of like Prisoner's Dilemma is the most primitive problem of Game Theory).

Dmitry Rubanovich
  • 2,471
  • 19
  • 27
0

I don't think there's a definitive answer but one possibility is that the operation of dividing a set S into two partitions S1 and S2 one of which is then divided into to sub-partitions S11 and S12, one of which has the same size as S2 - is a likely approach to many algorithms and that can be sometimes numerically described as a Fibonacci sequence.

DVK
  • 126,886
  • 32
  • 213
  • 327
0

Let me add another data structure to yours: Fibonacci trees. They are interesting because the calculation of the next position in the tree can be done by mere addition of the previous nodes:

http://xw2k.nist.gov/dads/html/fibonacciTree.html

It ties well in with the discussion by templatetypedef on AVL-trees (an AVL tree can at worst have fibonacci structure). I've also seen buffers extended in fibonacci-steps rather than powers of two in some cases.

I GIVE CRAP ANSWERS
  • 18,739
  • 3
  • 42
  • 47
0

Symbols with frequencies that are successive fibonacci numbers create maximum depth huffman trees, which trees correspond to source symbols being encoded with maximum length binary codes. Non-fibonacci source symbol frequencies create more balanced trees, with shorter codes. The code length has direct implications in the description complexity of the finite state machine that is responsible for decoding a given huffman code.


Conjecture: The 1st(fib) image will be compressed to 38bits, while the 2nd(uniform) with 50bits. It seems that the closer your source symbol frequencies are to fibonacci numbers the shorter the final binary sequence, the better the compression, maybe optimal in the huffman model.

huffman.ooz.ie/?text=ABBCCCDDDDDEEEEEEEE

enter image description here

Further Reading:

Buro, M. (1993). On the maximum length of Huffman codes. Information Processing Letters, 45(5), 219-223. doi:10.1016/0020-0190(93)90207-p

FranG
  • 116
  • 6
0

For me This is about order and space coordinates.

The Fibonacci sequence can be used as a clock.

The Fibonacci sequence allows to calculate the golden number decimal by decimal.

The golden number multiplied by itself gives almost the golden number +1.

So we can certainly cut an integer into a series of integers, of units by using for example the indexes.

I made a first naive version in python.(poc) code to be updated.

https://gitlab.com/numbers/Numbers/-/blob/main/ranging.py

So we can frame, count and coordinate the calculation steps and the memory spaces to this perfectly periodic reference frame (in time) and thus make it a kind of universal multiplication table equivalent. For me it is explicitly a mapping.

The idea is to eventually propose a ternary code with explicit management of the memory spaces according to the Fibonacci calculation step, and then to find all our numbers there.

Once done, to use this mapping, this universal table, this filter : to check the concordance, the consistency, the periodicity of complex computable operations, such as the wheeler experiment, sinus, gravity etc...

It sounds pretentious when you say it like that. It is not. Nobody create the golden number or Fibonacci. They are here, they are given like fruits on a tree.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '22 at 13:28
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32787995) – user16217248 Sep 29 '22 at 02:22
0

Just to add a trivia about this, Fibonacci numbers describe the breading of rabbits. You start with (1, 1), two rabbits, and then their population grows exponentially .

Mihaela
  • 2,482
  • 3
  • 21
  • 27