Question: Java Question: Write an efficient itnerative (i.e. loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2)
Java Question: Write an efficient itnerative (i.e. loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is theta(n), i.e. the function is linear in n.
Is recursion efficient? from what I believe, it isn't.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
