Question: public class Fibonacci { public static void main ( String [ ] args ) { for ( int num = 0 ; num < 1

public class Fibonacci
{
public static void main(String[] args)
{
for (int num =0; num <100; num++)
{
System.out.println(num +""+ fib(num));
}
}
public static long fib(int num)
{
if (num ==0)
{
return 0; //base case
}
if (num ==1)
{
return 1; //base case
}
//Recursive
return fib(num -1)+ fib(num -2);
}
}
At what term does it take more than 5 minutes to print the output?
why at some point this program gets so slow?
What property should a recursive algorithm have to be effective?
Define a nonrecursive method using a loop and an array to implement the Fibonacci series.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!