| about | help | code help+videos | done | prefs |
The dual-call recursive fibonacci solution requires a lot of function calls and additions. If we were to say that a fib() call costs 5 , and a + operator costs 1, how much does fib(n) cost? Write the fibCost(n) function which returns the cost of the fib(n). Explanation of results: The cost of fib(0) and fib(1) - These are easiest, as they do not cost an addition, or additional calls to fib. However, all subsequent calls to fib require additional fib() calls and a + operation. The cost of fib(2) is 16 - This is because it costs 5 for the fib(2) call, then you have 1 cost for the '+' operation, then 10 more for the two recursive calls. fibCost(0) → 5 fibCost(1) → 5 fibCost(2) → 16 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy