Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ratio of leaves to total nodes in a Fibonacci call stack

If you were to look at a recursive implementation of calculating the nth Fibonacci number (root 100, children 99 and 98, grandchildren 98, 97, 97, and 96, etc. etc.), roughly what would be the ratio of the number of leaves to the total number of nodes in the recursive tree?

    100
   /   \
  98   97
 /  \   .
96  97  .
.    .  .
.    .  

Not homework, just academically curious about this. (And yes, I realize that a recursive implementation is a god-awful way to calculate Fibonacci numbers)

like image 504
user666866 Avatar asked Jul 27 '11 16:07

user666866


People also ask

What is the Fibonacci sequence of leaves?

The Fibonacci sequence is present in both the structure and arrangement of leaves in many plants. Since plants rely on photosynthesis, they want to maximize the amount of sunlight that strikes their leaves. The vertical growth of many plants means that leaves can cover up each other.

How many nodes are in the Fibonacci tree?

Note: A Fibonacci tree of order n has F(n+2)-1 nodes, where F(n) is the nth Fibonacci number.

How do you calculate Fibonacci?

In the Fibonacci sequence of numbers, each number in the sequence is the sum of the two numbers before it, with 0 and 1 as the first two numbers. The Fibonacci series of numbers begins as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on.

How do trees follow the Fibonacci sequence?

Some plants express the Fibonacci sequence in their growth points, the places where tree branches form or split. One trunk grows until it produces a branch, resulting in two growth points. The main trunk then produces another branch, resulting in three growth points.


2 Answers

The number of leaves is simply F(n) since the F(i) is simply the number of leaves beneath that node. Do you see why? (hint: use induction)

The number of non-leaf nodes is the number of leaf nodes-1. This is a property of binary trees. So the total number of nodes is F(n) + F(n)-1 = 2F(n)-1.

The ratio thus approaches 1/2 as n grows large.

like image 149
tskuzzy Avatar answered Oct 01 '22 05:10

tskuzzy


fib(x) consist of leaves fib(x-1) and leaves of fib(x-2). So you get the same recursive equation as you have for fibonacci numbers.

If the termination point (leaves) are Fib1 and Fib0, then

tree   numofleaves
fib2   2
fib3   3
fib4   5
fib5   8
fib6   13
...

and numofleaves(x) = fib(x+1).

For the number of nodes you get the equation numnodes(x) = 1 + numnodes(x-1) + numnodes(x-2).

like image 37
Karoly Horvath Avatar answered Oct 01 '22 03:10

Karoly Horvath