CMPSCI 250 Discussion #9: Paths and Matrices
David Mix Barrington
24/26 April 2006
We put a directed multigraph on the board with five nodes {1,2,3,4,5} and
eight edges {a from 1 to 2, b from 1 to 2, c from 2 to 4, d from 3 to 5,
e from 4 to 3, f from 4 to 5, g from 5 to 1, and h from 5 to 4}.
- Question 1: Find all four-step paths out of vertex 1:
aced, acfg, acfh, bced, bcfg, and bcfh. Find all
four-step paths from vertex 5 to itself: gach, gbch,
hfhf.
- Question 2: Write the matrix A of naturals for this, compute
A^{4}, and compare the answer to Question 1.
A = 0 2 0 0 0 A^2 = 0 0 0 2 0 A^4 = 2 0 0 2 2
0 0 0 1 0 0 0 1 0 1 1 2 1 1 1
0 0 0 0 1 1 0 0 1 0 1 0 0 3 1
0 0 1 0 1 1 0 0 1 1 1 2 1 3 2
1 0 0 1 0 0 2 1 0 1 1 2 3 1 3
The first row of A^{4} adds to 6, which matches the six paths
out of vertex 1 found in Question 1. The lower-right corner of A^{4},
the entry A_{5,5}, is 3, which matches the three paths from vertex 5
to itself found in Question 1.
How many total four-step paths are in the graph?
The sum of all 25 entries in the matrix A^{4}, which is 36.
- Question 3: Determine the path relation for G, that is, for which
pairs of vertices i and j is there a path (of any length)
from i to j? Can you justify your
conclusion without listing all the paths?
There is a path from i to j for every pair i and j. There are several
ways to see this:
- The graph has cycles that visit all vertices, such as the paths
acedg or bcdeg. You can get from any vertex to any other vertex simply by
following this cycle for long enough.
- The matrix A^{4} has only four zero entries. This means that
there is a four-step path from i to j unless the pair (i,j) is
(1,2), (1,3), (3,2), or (3,3). So we can just find paths for these four pairs:
a, ace, dga, and λ, and we know paths for all 25 pairs exist.
- It turns out that A^{5} has no nonzero entries. So not
only is there a path of some length from every i to every j, there is always
a path of length 5.
- The calculation in Question 4 also shows that paths with all possible
start and finish vertices exist.
- Question 4: Let B be the boolean adjacency matrix of G,
where the entry B_{i,j} is 1 if there is at least one edge from i to
j and is 0 if there is not (except that we set B(i,i) to 1 for each i -- thus
"B" is the matrix called "B+I" in lecture).
Write down B and compute B^{4} using boolean matrix multiplication,
where 1 + 1 = 1. How does your answer relate to Question 3?
B = 1 1 0 0 0 B^2 = 1 1 0 1 0 B^3 = B^4 = 1 1 1 1 1
0 1 0 1 0 0 1 1 1 1 1 1 1 1 1
0 0 1 0 1 1 0 1 1 1 1 1 1 1 1
0 0 1 1 1 1 0 1 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
We can think of the matrix B^{k} as indicating whether there is
a path of length exactly k from i to j in the graph made from G by adding a
loop at each vertex. This is true if and only if there is a path in G of
length k or less. Thus our matrix of all ones matches our conclusion
in Question 3 that the path relation is always true. The fact that
B^{3} = B^{4} for this graph means that here, there is always
a path of length at most three from i to j. In any graph of n vertices, as
we discussed in lecture, there is a path from i to j at all if and only
if there is a path of length at most n-1.
Last modified 27 April 2006