I am exploring a way to compute a path matrix from an adjacency matrix (say, AM1).
The path matrix of the graph G with n vertices is a Boolean n * n-matrix, the elements of which can be defined as:
p[i][j]=1(if there is a path from i to j) p[i][j]=0(otherwise)
And the steps that I learned are as follows:
If we multiply the adjacency matrix A [] [] by ourselves, we get A ^ 2 (say, AM2), each vertex A [i] [j] basically represents the number of paths of length 2 from i to j.
Similarly, if we multiply the adjacency matrix 3 times, i.e. we get A ^ 3 (say, AM3), each vertex A [i] [j] basically represents the number of paths of path length 3 from i to j .. and so on.
Now we define a matrix X such that:
X = AM1 + AM2 + AM3 ... AMn (where n is the number of vertices)
From this X-matrix, we compute the path / reach capability matrix, replacing all nonzero vertices with 1.
What I cannot understand is how replacing all nonzero vertices with 1 gives us the path matrix. And why do we calculate or add the whole matrix to AMn.?.
I understand that X [i] [j] symbolizes the number of paths, the path length is n or less than n, from i to j, But why do we only calculate to n, no more or less?
Please explain!