id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

konstans@stuy.edu apcs1 > fibCost
prev  |  next  |  chance

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)

public int fibCost(int n){ }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Copyright Nick Parlante 2017 - privacy