§ Number of paths in a DAG
Given the adjacency matrix A of a DAG, this must be nilpotent. This is because
Ak[i][j] will tell us the number of paths from i to j with k edges in the path.
In a DAG, since there are no cycles, there is an upper bound on the number of edges
a path can have: the longest path is ∣V∣−1, when the DAG is a straight line. Thus,
we must have that A∣V∣=0.
- Let An=0.
- Now, we know that (I−A)−1=I+A+A2+…which will terminate as a finite sum, with (I−A)−1=I+A+A2+⋯+An−1.
- But note that (I+A+A2+…An−1)[i][j] will count number of paths from i to j with 0 edges, 1 edge, 2 edges, etc. so we will get the total number of paths from i to j!.