5. For simplicity, we check each of the three topologies separately.
The adjacency matrix of a graph with the ring topology must be, of course,
symmetric, and each of its rows must have exactly two 1’s, both not on the
The following brute-force algorithm follows the 1’s in a given matrix indicating
twoedgesincidentwithavertex: onefortheedgeenteringitandtheother
leaving the vertex, making sure the cycle closes at the starting vertex only after
visiting all the other vertices of the graph.
Start by scanning row 0 to verify that it has exactly two 1’s in columns we
denote 1and −1so that 0
1
−1. If it is not the case, stop: the matrix
is not the adjacency matrix of a graph with the ring topology. If it is the case,
Thetimeefficiency of the algorithm is (2)because it checks all the ele-
ments of an ×matrix in the worst case.
Note: It is not difficult to prove that a graph has the ring topology if and only
if all its vertices have degree 2 while having no loops, and it is connected. Hence
8