fibonacci algorithm using BigInteger
I'm not quite sure how to write a timer.java. that times the three algorithms for n up to 1000. Also I need to time the two fastest algorithms up to the given limit. Time fibo1 for increasing values of n until the waiting time becomes unreasonable (order of minutes).
This timer needs to output a table of the form
0 t1(0) t2(0) t3(0)
1 t1(1) t2(1) t3(1)
2 t1(2) t2(2) t3(2)
...
n t1(n) t2(n) t3(n)
ti(n) is the time of fiboi on input n.
here's my fibonacci.java
/*
import java.math.BigInteger;
import javax.swing.*;
import javax.swing.event.*;
import java.math.BigInteger;
public class Fibonacci
{
/*BigInteger fibo1( int k );
BigInteger fibo2( int k );
BigInteger fibo3( int k );*/
public BigInteger fibo1( int k )
{
if( k == 0 || k == 1)
return k;
else
return fibo1(k-1) + fibo1(k-2);
}
public BigInteger fibo2( int k )
{
BigInteger j[] = new BigInteger [k+1];
for( int i=0; i<=k; i++ )
j[]=-1; j[0]=0; f[1]=1;
return fibo(j,k);
}
int fibo( int j[], int k)
{
if( f[n] >= 0)
return j[k];
if( k==0 || k==1 )
return f[k]=k;
else
{
j[k]=fibo(f, k-1) + fibo(f, k-2);
return j[k];
}
}
public BigInteger fibo3 (int k)
{
BigInteger f0 = BigInteger.ZERO;
BigInteger f1 = BigInteger.ONE;
BigInteger temp;
if( k==0 )
return f0;
else if ( k==1 )
return f1;
for( int k=1; i<=k; i++ )
{
BigInteger f2=f0.add(f1);
f0=f1;
f1=f2;
}
return f1;
}
}
*/

