Counting Lattice Paths
The number of ways to walk from one corner of a grid to another, moving only right or up, is a single binomial coefficient — because every such path is just a choice of which steps are 'up' among all the steps taken.
Prerequisites: Counting: Permutations and Combinations
How many distinct routes are there from the bottom-left corner to the top-right corner of a 4-by-3 grid, moving only right or up along the grid lines, one unit at a time? Trying to draw and count every path by hand is slow and error-prone, and the grid could easily be much bigger. But every such route has an unavoidable structure hiding underneath: it's always exactly 4 rightward moves and 3 upward moves, in some order — and counting orderings is exactly what a binomial coefficient does.
The idea: a path is just a sequence of R's and U's
To go from to moving only right (R) or up (U), any valid path is a string of exactly R's and U's, and every arrangement of those letters corresponds to exactly one path — reading the string left to right tells you the move order. So the number of paths equals the number of ways to arrange R's and U's in a row, which is the number of ways to choose which of the total positions are U's:
In plain English: once you fix how many total steps there are and how many of them go up, a path is fully determined by which steps are the up-moves, and counting subsets is exactly what the binomial coefficient was built for.
Worked example 1: the 4-by-3 grid
From to needs 4 R's and 3 U's, 7 steps total. The number of distinct orderings is . There are 35 distinct routes — confirmable on a small grid by Pascal's-triangle-style counting (the number of ways to reach each intersection is the sum of the ways to reach the intersection below and the one to its left), but the binomial coefficient gets there in one step for grids far too large to enumerate by hand.
Worked example 2: paths through a required checkpoint
How many paths from to pass through the point ? Split the trip into two independent legs: needs 2 R's and 1 U, giving paths; needs 2 more R's and 2 more U's, giving paths. Since any first-leg path can be combined with any second-leg path, the total is — a multiplication rule, not an addition, because the two choices (how to get to the checkpoint, and how to leave it) are made independently. Note : about half of all paths happen to pass through this particular checkpoint.
The number of lattice paths from to using only right/up unit moves is — choosing which of the total steps are the "up" moves. Paths through a required intermediate point multiply the counts of the two independent legs.
"Paths that avoid a point or region" is usually solved as total paths minus paths through the forbidden region — count the complement, then subtract, rather than trying to enumerate the allowed paths directly.
Related concepts
Practice in interviews
Further reading
- Engel, Problem-Solving Strategies, ch. 3