Number of Paths from A to B

691 Views Asked by At

These type of questions that ask the Number of Paths are relatively easy when it a ordered grid, However this one isn't:

image

How do I account for all the paths without counting. And when you are only allowed to move to the right or down.

This is part of a timed test so what would be the fastest way to do it?

2

There are 2 best solutions below

0
On BEST ANSWER

Start by labelling the A as 1 (since there is one way to start your path, at A).

Then go to all the points that are reachable from already labelled points. The number of ways of getting to those points is the sum of the labels of the adjacent points. Repeat until you have the number of ways of travelling to B and all nodes are labelled.

If you are able to go backwards and repeat points then a simple cycle will tell you there are infinitely many ways of making it through the maze.

If you can only go on edges once then. Look at Eulerian paths. You'll need to omit some edges.

If you can only go to nodes once then see Hamiltonian paths.

4
On

First of all, we can label the vertices from which there is more than one viable path to $B.$

labeling

Now we work in reverse from $B.$ The only labeled vertex from which we can get to $B$ directly is $L,$ and there are clearly $3$ ways to do so. Hence, we get

first round counting

We continue in the same way. The only vertex from which we can get directly to $L$ is $K,$ and $K$ can only get to either $L$ or a single unlabeled vertex, so there are $3+1=4$ ways to get from $K$ to $B.$

second round counting

Next, only $J$ allows us a direct path to $K,$ and we can also get to an unlabeled vertex, so there are $4+1=5$ ways to get from $J$ to $B.$

third round counting

Each of $E$ and $H$ connect directly to $J,$ and to exactly $1$ unlabeled vertex, so there are $5+1=6$ ways to get to $B$ from either of them.

fourth round counting

From $C,$ we can get directly to $E$ and $1$ unlabeled vertex, giving $6+1=7$ ways to get from $C$ to $B.$ From $G,$ we can get directly to $E$ and $2$ unlabeled vertices, giving us $6+2=8$ ways to get to $B$ from $G.$ We can also get to $E$ from $D,$ but we need to hold off on that, since we can also get to the (as yet unnumbered) vertex $F$ from there.

fifth round counting

Next, we can get directly from $F$ to $G$ and to $1$ unlabeled vertex, giving us $8+1=9$ ways to get from $F$ to $B.$

sixth round counting

Then, from $D,$ we can get directly to $E$ or $F,$ giving us $6+9=15$ ways to get from $D$ to $B.$

seventh round counting

Finally, from $A,$ we can get directly to $C$ and $D,$ giving us $7+15=22$ ways to get from $A$ to $B.$