The Unique Paths problem asks: given a grid of size m×n, how many unique paths exist from the top-left corner to the bottom-right corner? You can only move right or down at each step. This visualization demonstrates two different approaches to solving this problem - first using a brute force DFS approach, and then showing how Dynamic Programming can optimize the solution by reusing calculations.
Looking at the DFS visualization above, you might notice something inefficient. As the DFS explores each possible path, it repeatedly calculates the same subproblems. For example, when it reaches position (1,1), it calculates all possible paths from that point to the target - but it will do this calculation multiple times, once for each different way of reaching (1,1)!
This is where Dynamic Programming shines. Instead of recalculating paths from each position multiple times, we can calculate it once and reuse that result. Watch the DP visualization below and notice how:
This "building upon previous calculations" is the essence of Dynamic Programming. It transforms our solution from repeatedly solving the same subproblems to solving each subproblem exactly once and reusing those results.