|
CS 3343/3341 Analysis of Algorithms Fall 2012 Recitation 2 Recursion, Etc. Partial Answers |
[See Cascade of Recursive Calls. Denote by An the total number of function calls needed to calculate Fn. (These are called "Leonardo numbers".) It is easy to count initial values for An:
n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ... |
An | 1 | 1 | 3 | 5 | 9 | 15 | 25 | 41 | 67 | 109 | 177 | ... |
A0 = 1 A1 = 1 An = An-1 + An-2 + 1 |
An = 2 * Fn+1 -1, for all n >= 0 |
+---+---+------------+-------------+--------------+ | 1 | 2 | column 3 | column 4 | column 5 | +---+---+------------+-------------+--------------+ | a | b | a1=a xor b | b1=a1 xor b | a2=a1 xor b1 | +---+---+------------+-------------+--------------+ | 0 | 0 | 0 | 0 | 0 | | 0 | 1 | 1 | 0 | 1 | | 1 | 0 | 1 | 1 | 0 | | 1 | 1 | 0 | 1 | 1 | +---+---+------------+-------------+--------------+ |
1st Info | 1st Burn | 2nd Info | 2nd Burn |
---|---|---|---|
01 | 001 | 10 | 101 |
11 | 100 | 01 | 110 |
10 | 010 | 00 | 111 |
11 | 100 | 11 | 100 |
00 | 000 | 10 | 101 |
10 | 010 | 10 | 010 |