Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by Raffael ( 14 years ago )
//Majewski Raffael, 1121099; Nikolaus Sterzinger, 1121162
public class Rekursion{
//Instanzvariablen
private long currentRuntime=0;
private long runtimeMemory =0;
//Methoden
public long getLastRuntime() { // Gibt die Zeit (in ms) zurück die für die letzte Berechnung nötig war.
return currentRuntime;
}
public long Fibonacci( int n){ // Nicht rekursive Berechnung der n-ten Fibonacci Zahl.
runtimeMemory = System.currentTimeMillis();
long fib = 1,erg=0;
for (int i = 1; i <= n; i++){
erg = fib + erg;
fib = erg - fib;
}
currentRuntime= System.currentTimeMillis() - runtimeMemory;
return erg;
}
public long FibonacciRekursiv( int n){ // Rekursive Berechnung der n-ten Fibonacci Zahl. (Inkludiert nur Zeitberechnung und Verweis auf Hilfsmethode
runtimeMemory = System.currentTimeMillis();
long erg = privateFibonacciRekursiv(n);
currentRuntime = System.currentTimeMillis() - runtimeMemory;
return erg;
}
private long privateFibonacciRekursiv(int n) { ///Hilfsmethode zur rekursiven Berechnung
if(n == 0)
return 0;
if(n == 1)
return 1;
return (privateFibonacciRekursiv(n-1) + privateFibonacciRekursiv(n-2));
}
public long Fakultaet( int n){ // Nicht rekursive Berechnung von n!.
runtimeMemory= System.currentTimeMillis();
long fak = 1;
int faktor = 1;
while (faktor <= n){
fak = fak*faktor;
faktor++;
}
currentRuntime= System.currentTimeMillis()- runtimeMemory;
return fak;
}
public long FakultaetRekursiv( int n){ // Rekursive Berechnung von n!.
long runtimeMemory= System.currentTimeMillis(), erg= 1;
if (n > 0)
erg = n*FakultaetRekursiv(n-1);
currentRuntime = System.currentTimeMillis() - runtimeMemory;
return erg;
}
}
Revise this Paste