04 - Fibonacci Numbers - Dynamic Programming Bottom Up

@Rishi Srivastava Using Dynamic Programming Bottom up approach, we use the tabulation technique through iteration. Starting from the smallest subproblem, we store the results in a table (an array), do something with the data (for example: add the data for Fibonacci) until we arrive at the solution. Dynamic Programming Bottom Up pseudocode: function fibBottomUp(n){ if (n === 0 || n === 1){ return n; } long[] dp = new long[n]; dp[0] = 0; dp[1] = 1; for (int i = 2; i is less than n; i ) { dp[i] = dp[i - 1] dp[i - 2]; } return dp[n - 1] dp[n - 2]; } Time complexity: O(n) Space complexity: O(n) Github: Leetcode:
Back to Top