Example 12.4.1. Counting paths with words.
Consider paths in the 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 represent the set of all such paths. We can distinguish each element of by the sequence of directions it takes at each step. Let where and stand for the directions “right” and “up”, respectively. Then for each path we can build a word by setting the letters of to correspond to the steps in the path. For example, the path in the diagram above would correspond to the word
This assignment of words in to paths in is a function! Let’s call it and set the image of in 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 by restricting the codomain. Therefore, we can count the paths in by instead counting the words in
Since each path in takes exactly steps, exactly of which must be upwards and exactly of which must be to the right, we see that consists precisely of those words in that have length and contain exactly s and 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