AlgoPrecision

Dynamic Programming

DP State Tables

Watch tabulation fill one state at a time with dependencies, current result, and per-step time and space complexity.

O(n)
State 00
State 10
State 20
State 30
State 40
State 50
State 60
State 70
State 80
State 90
State 100

Result

-

Time

O(n)

Space

O(n)

Step Note

Build Fibonacci up to F(10).

Details
function fibonacci(n: number) {
  const dp = Array(n + 1).fill(0)
  dp[0] = 0
  dp[1] = 1
  for (let i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + dp[i - 2]
  }
  return dp[n]
}