namespace ALGA { public class Fibonacci { public static int fibonacci_recursive(int n) { if (n <= 0) return 0; if (n == 1) return 1; return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2); } public static int fibonacci_iterative(int n) { if (n < 0) return 0; int a = 0, b = 1; for (int i = 0; i < n; i++) (a, b) = (b, a + b); return a; } public enum Answer { IterativeIsFaster, RecursiveIsFaster }; public static Answer which_is_faster() { /** * Iterative is 'sneller' omdat deze O(n) is in tegenstelling tot de * recursieve versie die O(2^n) is */ return Answer.IterativeIsFaster; } } }