0

The same question was asked almost 7 years ago. It turned out to be a matter of terminology in different textbooks between the terms "path" and "walk". While the answers addressed the OP's question, who meant to say "walk" instead, I am hoping for an answer for (actual) paths, that has no repeating vertex/edge visits.

Let's say I always reset the diagonal to zero after each power $A^k = A^{k-1} A$, $ \text{Diag}(A^k) := 0 $ to ban repeated visits to the same vertices. How to go about reasoning mathematically the correctness of this approach? Or if a more "proper" solution exists other than this hack?

I am aware that, if we are looking instead for $k$-lengthed shortest path, the first time an entry $a^k_{i,j}$ switches from 0 to >0 gives the number of shortest paths of length $k$ between two vertices $i$ and $j$. Because it is "too short" for loops to have occurred. But this isn't the total number of $k$-lengthed paths, which includes less efficient loopless paths as well.

Moobie
  • 103

1 Answers1

1

Resetting the diagonals to $0$ after every step will not correctly exclude walks with repeated vertices; it will only exclude walks that revisit their starting vertex. A walk that revisits a vertex it did not start with will still be counted.

You will not find a simple recurrence for the matrix that counts paths, not walks; no matrix multiplication with some short correction to be done after every step. (Or if you find it, it's worth a million dollars.) If you could, then you could use it to count the number of Hamiltonian paths (by going up to paths of length $n-1$ in an $n$-vertex graph). In particular, you could solve the NP-complete problem of determining if there are any Hamiltonian paths.

Misha Lavrov
  • 159,700