101 Logo
onenoughtone

Interactive DP Visualization

Fibonacci Sequence

Watch how dynamic programming efficiently computes Fibonacci numbers by storing and reusing previously calculated values.

Interactive Visualization:

Fibonacci Sequence Visualization

Fibonacci Sequence: Each number is the sum of the two preceding ones, starting from 0 and 1. The sequence starts: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

Call Stack:
Stack is empty
Memoization Table:
Memo table is empty

Time Complexity

  • Recursive: O(2^n) - exponential growth
  • Memoization: O(n) - linear time
  • Tabulation: O(n) - linear time

Space Complexity

  • Recursive: O(n) - call stack depth
  • Memoization: O(n) - memo table + call stack
  • Tabulation: O(n) - DP table

Step 0 of 0: Initial state

Knapsack Problem

See how dynamic programming solves the classic knapsack problem by building a table of optimal solutions for subproblems.

Interactive Visualization:

Knapsack Problem Visualization

Knapsack Problem: Given a set of items, each with a weight and a value, determine which items to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.

Loading visualization...

Time Complexity

  • Recursive: O(2^n) - exponential in the number of items
  • Memoization: O(n*W) - where n is the number of items and W is the capacity
  • Tabulation: O(n*W) - where n is the number of items and W is the capacity

Space Complexity

  • Recursive: O(n) - call stack depth
  • Memoization: O(n*W) - memo table + call stack
  • Tabulation: O(n*W) - DP table

Step 0 of 0: Initial state

Longest Common Subsequence

Explore how dynamic programming finds the longest common subsequence between two strings by building a 2D table of solutions.

Interactive Visualization:

Longest Common Subsequence Visualization

Longest Common Subsequence (LCS): The longest subsequence that appears in the same relative order in both strings, but not necessarily contiguous.

DP Table (rows: String 1, columns: String 2)
i\j0BDCABA
00000000
A0000000
B0000000
C0000000
B0000000
D0000000
A0000000
B0000000
Current Cell
Highlighted Cell

Time Complexity

  • Recursive: O(2^(m+n)) - exponential in the length of the strings
  • Memoization: O(m*n) - where m and n are the lengths of the strings
  • Tabulation: O(m*n) - where m and n are the lengths of the strings

Space Complexity

  • Recursive: O(m+n) - call stack depth
  • Memoization: O(m*n) - memo table + call stack
  • Tabulation: O(m*n) - DP table

Applications of LCS

  • Diff Tools: Finding differences between files or versions
  • DNA Sequence Alignment: Comparing genetic sequences
  • Plagiarism Detection: Finding similarities between documents
  • Version Control Systems: Merging changes from different branches
  • Spell Checking: Suggesting corrections for misspelled words

Step 0 of 0: Initial state

IntroVisualizePatternsPractice
101 Logo
onenoughtone