Respuesta :
I'm assuming that by "turning the graph into a matrix" you're referring to the adjacency matrix associated with a given directed graph, which encodes a connection between two vertices [tex]v_i[/tex] and [tex]v_j[/tex] by the number [tex]a_{ij}=1[/tex] if there's an edge beginning at [tex]v_i[/tex] and terminating at [tex]v_j[/tex] and 0 otherwise. Here [tex]a_{ij}[/tex] is the entry of the adjacency matrix [tex]\mathbf A[/tex] in the [tex]i[/tex]th row and [tex]j[/tex]th column.
[tex]a_{ij}=\begin{cases}1&\text{if }v_i\to v_j\\0&\text{otherwise}\end{cases}[/tex]
Let's consider a simple example of a graph [tex]G(V,E)[/tex] on three vertices [tex]V=\{v_1,v_2,v_3\}[/tex], where the edge set is [tex]E=\{v_1v_2,v_1v_3,v_3v_1\}[/tex]. (image below)
The corresponding adjacency matrix is
[tex]\mathbf A=\begin{bmatrix}0&1&1\\0&0&0\\1&1&0\end{bmatrix}[/tex]
and squaring this gives the matrix
[tex]\mathbf B=\mathbf A^2=\begin{bmatrix}1&1&0\\0&0&0\\0&1&1\end{bmatrix}[/tex]
Let's think about what the entry [tex]b_{11}[/tex] is saying. We obtained it by computing the vector product,
[tex]b_{11}=a_{1j}\cdot a_{i1}=\begin{bmatrix}0&1&1\end{bmatrix}\begin{bmatrix}0\\0\\1\end{bmatrix}=0\cdot0+1\cdot0+1\cdot1=1[/tex]
We can interpret each term as counting the number of two-step paths we can take starting from [tex]v_1[/tex] and ending up back on [tex]v_1[/tex]. We'll require that staying in place is not an option, that a path from one vertex to itself must involve leaving the first vertex.
The first term is then 0, since there is no path from [tex]v_1[/tex] to itself: [tex]a_{1,1}\cdot a_{1,1}=0[/tex]
The second term is also 0, since we can take a step from [tex]v_1[/tex] over to [tex]v_2[/tex], but we can't go back: [tex]a_{1,2}\cdot a_{2,1}=0[/tex]
The third term is 1, because we can take a step from [tex]v_1[/tex] to [tex]v_3[/tex], and we can then undo that step by going backwards from [tex]v_3[/tex] to [tex]v_1[/tex]: [tex]a_{1,3}\cdot a_{3,1}=1[/tex]
And so on. We can make the claim that [tex]b_{ij}[/tex] (the [tex](i,j)[/tex]th element of [tex]\mathbf A^2[/tex]) will give you the number of 2-edge paths from [tex]v_i[/tex] to [tex]v_j[/tex].
And more generally, [tex]\mathbf A^n[/tex] will give the number of paths consisting of [tex]n[/tex] steps.
[tex]a_{ij}=\begin{cases}1&\text{if }v_i\to v_j\\0&\text{otherwise}\end{cases}[/tex]
Let's consider a simple example of a graph [tex]G(V,E)[/tex] on three vertices [tex]V=\{v_1,v_2,v_3\}[/tex], where the edge set is [tex]E=\{v_1v_2,v_1v_3,v_3v_1\}[/tex]. (image below)
The corresponding adjacency matrix is
[tex]\mathbf A=\begin{bmatrix}0&1&1\\0&0&0\\1&1&0\end{bmatrix}[/tex]
and squaring this gives the matrix
[tex]\mathbf B=\mathbf A^2=\begin{bmatrix}1&1&0\\0&0&0\\0&1&1\end{bmatrix}[/tex]
Let's think about what the entry [tex]b_{11}[/tex] is saying. We obtained it by computing the vector product,
[tex]b_{11}=a_{1j}\cdot a_{i1}=\begin{bmatrix}0&1&1\end{bmatrix}\begin{bmatrix}0\\0\\1\end{bmatrix}=0\cdot0+1\cdot0+1\cdot1=1[/tex]
We can interpret each term as counting the number of two-step paths we can take starting from [tex]v_1[/tex] and ending up back on [tex]v_1[/tex]. We'll require that staying in place is not an option, that a path from one vertex to itself must involve leaving the first vertex.
The first term is then 0, since there is no path from [tex]v_1[/tex] to itself: [tex]a_{1,1}\cdot a_{1,1}=0[/tex]
The second term is also 0, since we can take a step from [tex]v_1[/tex] over to [tex]v_2[/tex], but we can't go back: [tex]a_{1,2}\cdot a_{2,1}=0[/tex]
The third term is 1, because we can take a step from [tex]v_1[/tex] to [tex]v_3[/tex], and we can then undo that step by going backwards from [tex]v_3[/tex] to [tex]v_1[/tex]: [tex]a_{1,3}\cdot a_{3,1}=1[/tex]
And so on. We can make the claim that [tex]b_{ij}[/tex] (the [tex](i,j)[/tex]th element of [tex]\mathbf A^2[/tex]) will give you the number of 2-edge paths from [tex]v_i[/tex] to [tex]v_j[/tex].
And more generally, [tex]\mathbf A^n[/tex] will give the number of paths consisting of [tex]n[/tex] steps.
