how could the number of paths in a directed graph calculated? Are there any algorithms for this purpose?
Best wishes
EDIT: The graph is not a tree.
Let A
be the adjacency matrix of a graph G
. Then A^n
(i.e. A
multiplied n
times with itself) has the following interesting property:
The entry at position (i,j)
of A^n
equals the number of different paths of length n
from vertex i
to vertex j
.
Hence:
A
A
it with itself repeatedly until you get boredIt might be wise to first check whether G contains a cycle, because in this case it contains infinitely many paths. In order to detect cycles, set all edge weights to -1 and use Bellman-Ford.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With