Example 12.4.1. Counting paths with words.
Consider paths in the \(5 \times 10\) grid below that start at the bottom left and end at the top right, and only move up or right at each step. (One such path is drawn in.) How many such paths are there?
Let \(P\) represent the set of all such paths. We can distinguish each element of \(P\) by the sequence of directions it takes at each step. Let \(\Sigma = \{R,U\}\text{,}\) where \(R\) and \(U\) stand for the directions “right” and “up”, respectively. Then for each path \(p \in P\) we can build a word \(w_p \in \words{\Sigma}\) by setting the letters of \(w_p\) to correspond to the steps in the path. For example, the path in the diagram above would correspond to the word \(RRURUURRRRURR\text{.}\)
This assignment of words in \(\words{\Sigma}\) to paths in \(P\) is a function! Let’s call it \(\funcdef{f}{P}{\words{\Sigma}}\text{,}\) and set \(W = f(P)\text{,}\) the image of \(f\) in \(\words{\Sigma}\text{.}\) This function is clearly one-to-one, as different paths must produce different words of direction indicators. And since every function maps its domain surjectively onto its image, we obtain a bijection \(\funcdef{f}{P}{W}\) by restricting the codomain. Therefore, we can count the paths in \(P\) by instead counting the words in \(W\text{!}\)
Since each path in \(P\) takes exactly \(13\) steps, exactly \(4\) of which must be upwards and exactly \(9\) of which must be to the right, we see that \(W\) consists precisely of those words in \(\words{\Sigma}\) that have length \(13\) and contain exactly \(4\) \(U\)s and \(9\) \(R\)s. Once we learn some basic counting techniques later in the course, you will be able to come back to this example to verify that
\begin{equation*}
\card{P} = \card{W} = 715 \text{.}
\end{equation*}