How do I interpret following equations on fibonacii numbers?

40 Views Asked by At

I went through an online tutorial (http://codeforces.com/blog/entry/14385) on finding n-th fibonacci number which explains a method as,

You are standing at position n in Ox axis.

In a step, you can move to the left 1 or 2. How many ways to reach position $0$?

It is not hard to realize $f(n) = f(n - 1) + f(n - 2) $ with $f(0)=1$ and $f(1)=1$. Therefore $ f(n)$ is $(n+1)th $ element in fibonacci sequence.

There are two cases:

1. $n=2k$

we have two choices:

first choice is to jump from $2k$ to $k$ and jump to $0$,

another choice is to jump from $ n $ to $ k+1 $, move 2 step left, and jump from $ k-1 $ to 0. Therefore,$$ f(2k) = f(k)\cdot f(k) + f(k-1)\cdot f(k-1) \tag{1}$$

2. $n=2k+1$:

consider two segments $0..k$ and $k..n$.

There are two choices: first choice is to jump from $n$ to $k$ and jump from $k$ to $0$, another choice is to jump from $n$ to $k+1$, move 2 steps to the left, and jump from $k-1$ to $0$.

Therefore, $$ f(2k+1) = f(k)\cdot f(k+1) + f(k-1)\cdot f(k). \tag{2}$$

I am not getting how the eq. $(1)$ and $(2)$ are written although I understand that each equation represent combination of two cases but why aren't the steps(italicized) considered while forming the equation?

1

There are 1 best solutions below

2
On BEST ANSWER

Let us consider the case $n=2k$. Moving from $n$ to $0$ you have two disjoint cases: 1) you will stop at $k$ or 2) you will not stop at $k$.

1) You have $f(k)$ ways to arrive at $k$ and $f(k)$ ways to arrive at $0$ from $k$. Hence you get a total of $f(k)\cdot f(k)$ cases.

2) If you will not stop at $k$, since you can move left 1 or 2, you have to stop at $k+1$ (you can not jump more than 2 positions). So you have $f(k-1)$ ways to arrive at $k+1$. Then you take a step 2 and arrive at $k-1$ and finally in $f(k-1)$ ways you arrive at $0$. Hence you get a total of $f(k-1)\cdot f(k-1)$ cases.

A similar argument works for $n=2k+1$.

P.S. You can take a look at Example 2.4 (pdf file). There is a similar combinatorial proof of the identity $f(m+n)=f(m)f(n)+f(m-1)f(n-1)$.