
## Section9.3Connectivity

This section is devoted to a question that, when posed in relation to the graphs that we have examined, seems trivial. That question is: Given two vertices, $s$ and $t\text{,}$ of a graph, is there a path from $s$ to $t\text{?}$ If $s = t$, this question is interpreted as asking whether there is a circuit of positive length starting at $s\text{.}$ Of course, for the graphs we have seen up to now, this question can be answered after a brief examination.

### Subsection9.3.1Preliminaries

There are two situations under which a question of this kind is nontrivial. One is where the graph is very large and an “examination” of the graph could take a considerable amount of time. Anyone who has tried to solve a maze may have run into a similar problem. The second interesting situation is when we want to pose the question to a machine. If only the information on the edges between the vertices is part of the data structure for the graph, how can you put that information together to determine whether two vertices can be connected by a path?

###### Note9.3.1Connectivity Terminology

Let $v$ and $w$ be vertices of a directed graph. Vertex $v$ is connected to vertex $w$ if there is a path from $v$ to $w\text{.}$ Two vertices are strongly connected if they are connected in both directions to one another. A graph is connected if, for each pair of distinct vertices, $v$ and $w\text{,}$ $v$ is connected to $w$ or $w$ is connected to $v\text{.}$ A graph is strongly connected if every pair of its vertices is strongly connected. For an undirected graph, in which edges can be used in either direction, the notions of strongly connected and connected are the same.

(Indirect): Suppose $u$ is connected to $w\text{,}$ but the shortest path from $u$ to $w$ has length $m\text{,}$ where $m>n$. A vertex list for a path of length $m$ will have $m + 1$ vertices. This path can be represented as $\left(v_0,v_1,\ldots, v_m\right)$, where $v_0=u$ and $v_m= w$. Note that since there are only $n$ vertices in the graph and $m$ vertices are listed in the path after $v_0$, we can apply the pigeonhole principle and be assured that there must be some duplication in the last $m$ vertices of the vertex list, which represents a circuit in the path. This means that our path of minimum length can be reduced, which is a contradiction.

The main advantage of the adjacency matrix method is that the transitive closure matrix can answer all questions about the existence of paths between any vertices. If $G^+$ is the matrix of the transitive closure, $v_i$ is connected to $v_j$ if and only if $\left(G^+\right)_{i j }=1$. A directed graph is connected if $\left(G^+\right)_{i j }=1$ or $\left(G^+\right)_{j i}=1$ for each $i\neq j$. A directed graph is strongly connected if its transitive closure matrix has no zeros.

A disadvantage of the adjacency matrix method is that the transitive closure matrix tells us whether a path exists, but not what the path is. The next algorithm solve this problem

### SubsectionExercises for Section 9.3

###### 1

Apply Algorithm 9.3.8 to find a path from 5 to 1 in Figure 9.3.11. What would be the final value of $V\text{?}$ Assume that the terminal vertices in edge lists and elements of the depth sets are put into ascending order, as we assumed in Example 9.3.10.

$\begin{array}{ccccccc} k & 1 & 2 & 3 & 4 & 5 & 6 \\ V[k].\text{found} & T & T & T & F & F & T \\ V[k].\text{from} & 2 & 5 & 6 & * & * & 5 \\ \text{Depth} \text{Set} & 2 & 1 & 2 & * & * & 1 \\ \end{array}$ $\text{(*} = \text{undefined})$

###### 2

Apply Algorithm 9.3.8 to find a path from $d$ to $c$ in the road graph in Example 9.1.9 using the edge list in that example. Assume that the elements of the depth sets are put into ascending order.

###### 3

In a simple undirected graph with no self-loops, what is the maximum number of edges you can have, keeping the graph unconnected? What is the minimum number of edges that will assure that the graph is connected?

If the number of vertices is $n\text{,}$ there can be $\frac{(n-1)(n-2)}{2}$ vertices with one vertex not connected to any of the others. One more edge and connectivity is assured.

###### 4

Use a broadcasting algorithm to determine the shortest path from vertex $a$ to vertex $i$ in the graphs shown in the Figure 9.3.12 below. List the depth sets and the stack that is created.

###### 5

Prove (by induction on $k$) that if the relation $r$ on vertices of a graph is defined by $v r w$ if there is an edge connecting $v$ to $w\text{,}$ then $r^k$, $k \geq 1$, is defined by $v r^kw$ if there is a path of length $k$ from $v$ to $w\text{.}$

Basis: $(k=1)$ Is the relation $r^1$, defined by $v r^1 w$ if there is a path of length 1 from $v \text{ to } w$? Yes, since $v r w$ if and only if an edge, which is a path of length $1\text{,}$ connects $v$ to $w\text{.}$
Induction: Assume that $v r^k w$ if and only if there is a path of length $k$ from $v$ to $w\text{.}$ We must show that $v r^{k+1} w$ if and only if there is a path of length $k+1$ from $v$ to $w\text{.}$ $v r^{k+1} w \Rightarrow v r^k y \textrm{ and } y r w\textrm{ for some vertex } y$
By the induction hypothesis, there is a path of length $k$ from $v \textrm{ to } y$. And by the basis, there is a path of length one from $y$ to $w$. If we combine these two paths, we obtain a path of length $k+1$ from $v$ to $w\text{.}$ Of course, if we start with a path of length $k+1$ from $v$ to $w\text{,}$ we have a path of length $k$ from $v$ to some vertex $y$ and a path of length 1 from $y$ to $w\text{.}$ Therefore, $v r^k y \textrm{ and } y r w \Rightarrow v r^{k+1} w$.