Learn DP through interactive vector-based pathfinding
Dynamic Programming (DP) is an optimization technique that solves complex problems by breaking them into simpler subproblems and storing their solutions.
Given a grid with costs on each cell, find the minimum cost path from the top-left to bottom-right corner. You can only move right or down.
Without DP, we'd need to check all possible paths (exponential time). With DP, we compute the optimal solution in O(nĆm) time by building on previous solutions.
Numbers show the cost of passing through each cell
In pathfinding, we represent positions and movements as 2D vectors.
A position (row, col) represents coordinates on our grid.
We define movement as vector addition:
The "cost" to reach a cell is the sum of all cell values along the path.
For each cell, the minimum cost to reach it is:
Watch how the DP table is built step by step:
Click cells to toggle obstacles, then run the DP algorithm to find the optimal path.
What is the time complexity of the DP pathfinding solution for an nĆm grid?
In the DP formula dp[i][j] = grid[i][j] + min(dp[i-1][j], dp[i][j-1]), what does dp[i-1][j] represent?
Given movement vector right = [0, 1] and position [2, 3], what is the new position after moving right?
Answer all questions to see your score!