Quant Memo
Coding/●●●●●

Counting grid paths, top-down then bottom-up

A robot starts at the top-left of an m×nm \times n grid and moves only right or down until it reaches the bottom-right. The number of distinct paths satisfies

paths(i, j) = paths(i-1, j) + paths(i, j-1)

with paths(0, j) = paths(i, 0) = 1 along the top row and left column.

Explain why plain recursion is exponential and rewrite it to run in O(mn)O(mn).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions