Effecfively we are creating a loop in which a and b


programming language is JAVA:

Write a public static method named static long fibFast(int n, long a, long b)

that returns the nth fibonacci number. The method should be coded as follows:

If n is zero then just return a (the zeroth fibonacci number).

If n > 0 call the function recursively with n-1 as the first parameter , b as the second parameter and a+b as the last parameter .

Effecfively, we are creating a loop in which a and b represent two consecutive fibonacci numbers. As n goes down by 1 we replace those by the next consecutive pair of Fibonacci numbers.

Eventually n reaches 0 and the first parameter will equal the nth fibonacci number.

Note: this only works if the initial call is fibFast(n, 0, 1).

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Effecfively we are creating a loop in which a and b
Reference No:- TGS02901399

Expected delivery within 24 Hours