Complete the code to define the base case for the Fibonacci recursion.
if (n == [1]) return n;
The base case for Fibonacci recursion is when n is 0, return 0.
Complete the code to recursively calculate Fibonacci numbers.
return fibonacci(n - 1) [1] fibonacci(n - 2);
Fibonacci numbers are the sum of the two previous numbers.
Fix the error in the recursive Fibonacci method to avoid repeated calculations.
if (memo[n] != [1]) return memo[n];
We use -1 to indicate that the Fibonacci number for n is not yet calculated.
Fill both blanks to implement memoization in Fibonacci recursion.
memo[n] = fibonacci([1]) [2] fibonacci(n - 2);
Memoization stores the sum of fibonacci(n-1) and fibonacci(n-2) in memo[n].
Fill all three blanks to create a bottom-up dynamic programming Fibonacci solution.
for (int i = [1]; i <= n; i++) { dp[i] = dp[i - [2]] [3] dp[i - 2]; }
Start loop from 2, use dp[i-1] + dp[i-2] to fill dp array bottom-up.
