AlgoScope

Unique Grid Paths

Algorithmbeginner2D Dynamic Programming

paths(r, c) = paths(r-1, c) + paths(r, c-1); Pascal's triangle on a grid.

Decision · step 7 of 14DP on a Grid: Paths on a 3 x 4 grid
01230121✓11✓1✓12

(1, 1) can be entered from above, 1 way, or from the left, 1 way. Those are disjoint, so 1 + 1 = 2.

Open in the player →or start at step 7

What you will see

Each cell sums the cell above and the cell to the left; values grow toward the corner.

How dp on a grid works →

Cost

BestO(r * c)
AverageO(r * c)
WorstO(r * c)
SpaceO(c)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.

Reduced motion: Dependency arrows appear statically and the cell value crossfades.

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

DP on a Grid covers these too, in the same run.