I am getting the following statement:
Code
RecFibo(n):
if (n < 2)
return n
else
return RecFibo(n − 1) + RecFibo(n − 2)
From text:
Another way to see this is that the RecFibo is building a big binary tree of additions, with nothing but zeros and ones at the leaves. Since the eventual output is Fn , our algorithm must call RecRibo(1) (which returns 1) exactly Fn times. A quick inductive argument implies that RecFibo(0) is called exactly Fn−1 times. Thus, the recursion tree has Fn + Fn−1 = Fn+1 leaves, and therefore, because it’s a full binary tree, it must have 2Fn+1 − 1 nodes.
Further
A quick inductive argument implies that RECFIBO(0) is called exactly Fn−1 times. Thus, the recursion tree has Fn + Fn−1 = Fn+1 leaves, and therefore, because it’s a full binary tree, it must have 2Fn+1 − 1 nodes.
Although I understand and can visualize the recursive tree but the induction analysis leaves me puzzled. My main confusion is the most obvious part from the author claiming "our algorithm must call RecFibo(1) (which returns 1) exactly Fn times" and same for "RecFibo(0)".
Reference:
http://jeffe.cs.illinois.edu/teaching/algorithms/notes/05-dynprog.pdf
If (by the inductive hypothesis)
RecFibo(n-1)you callRecFibo(1)$F_{n-1}$ times andRecFibo(0)$F_{n-2}$ timesRecFibo(n-2)you callRecFibo(1)$F_{n-2}$ times andRecFibo(0)$F_{n-3}$ timesthen in calculating
RecFibo(n)by callingRecFibo(n-1)andRecFibo(n-2)you callRecFibo(1)$F_{n-1}+F_{n-2}=F_{n}$ times andRecFibo(0)$F_{n-2}+F_{n-3}=F_{n-1}$ timesYou should probably also show the hypothesis is true for
RecFibo(2)and eitherRecFibo(3)orRecFibo(1)This is not the most efficient algorithm