[Math] Number of Unique Paths in $M\times N$ Matrix; Combination or Permutation

combinationspermutations

I was checking out this problem about # of unique paths in a mxn matrix where you go from top left to bottom right, using only down and right.

http://researchideas.ca/wmt/c6b3.html

enter image description here

There's a solution using combination, by rephrasing the problem as out of total steps to get to the goal how many can you have to pick them to be right (the other ones are down by default).

The article has this quote "In fact, the order of the moves does not matter as long as there are a total of 10 moves, five of which are right."

I don't understand that. If I didn't look at the solution using combination, I would have guessed this needs to be solved using permutation because order seem to matter:

D D D D D R R R R R is a different path than D D D D R D R R R R.

I'm confused at why the order doesn't matter? Why is this combination instead of permutation?

Best Answer

The task

Imagine a 𝑛×𝑚 matrix where one can make steps only in two directions - down and to the right.

The task is to find a number of unique paths connecting top left and bottom right corners.

As correctly mentioned above, there are exactly 𝑛 vertical and 𝑚 horizontal moves. This is an important assumption and having made it one is tempted to use it literally to represent a set of possible steps

$𝒮 ={ \underbrace{ ℎ,…, ℎ }_\text{𝑚} , \underbrace{𝑣,…, 𝑣}_\text{𝑛} }$, i.e. by step types.

However, this is not a set as defined for the purpose of combinatorics formulas used - all elements must be unique. So the challenge is just to represent the steps set properly.

The trick

Here is the trick to solve this representation problem.
Instead of step types consider a set of step numbers

$𝒮 ={ \underbrace{ 1,2,…,𝑛+𝑚−2 }_\text{𝑛+𝑚−2} }$.

Now, picking any 𝑛−1 step numbers to be vertical will uniquely represent a path forcing the remaining 𝑚-1 steps to be horizontal.

Finally, answering your very question

Say, out of 3 vertical and 5 horizontal steps in total we picked 3 vertical steps to be number 2, 4 and 8. That will leave us with steps number 1, 3, 5, 6 and 7 to be horizontal. These two are true sets, and picking {2,4,8} to be vertical ones is essentially the same as picking {8,2,4}. That is why, following the above representation we use combinations instead of permutations.

Due to the trivial identity of binomial coefficients, the number of ways to pick 𝑘 elements out of 𝑛 is equal to the number of ways to pick 𝑛-𝑘 elements. Hence we do not care which of type to pick, and consequently

$\binom{𝑛+𝑚−2}{𝑛−1} =\binom{𝑛+𝑚−2}{𝑚−1} = \frac{(𝑛+𝑚−2)!}{(𝑛−1)!(𝑚−1)!}$

Hope that helps.