You are on page 1of 3

62  ◾  Software Testing

4.2.4 Paths and Semipaths


Direction permits a more precise meaning to paths that connect nodes in a directed graph. As a
handy analogy, you may think in terms of one-way and two-way streets.

Definition

A (directed) path is a sequence of edges such that, for any adjacent pair of edges ei, ej in the
sequence, the terminal node of the first edge is the initial node of the second edge.
A cycle is a directed path that begins and ends at the same node.
A chain is a sequence of nodes such that each interior node has indegree = 1 and outdegree = 1.
The initial node may have indegree = 0 or indegree > 1. The terminal node may have outde-
gree = 0 or outdegree > 1 (we will use this concept in Chapter 8).
A (directed) semipath is a sequence of edges such that for at least one adjacent pair of edges ei, ej
in the sequence, the initial node of the first edge is the initial node of the second edge or the
terminal node of the first edge is the terminal node of the second edge.

Our continuing example contains the following paths and semipaths (not all are listed):

A path from n1 to n6
A semipath between n1 and n3
A semipath between n2 and n4
A semipath between n5 and n6

4.2.5 Reachability Matrix
When we model an application with a digraph, we often ask questions that deal with paths that
let us reach (or “get to”) certain nodes. This is an extremely useful capability and is made possible
by the reachability matrix of a digraph.

Definition

The reachability matrix of a directed graph D = (V, E) with m nodes is an m × m matrix R = (r(i, j)),
where r(i, j) is a 1 if and only if there is a path from node i to node j; otherwise, the element is 0.
The reachability matrix of a directed graph D can be calculated from the adjacency matrix A as

R = I + A + A2 + A3 + … + Ak

where k is the length of the longest path in D, and I is the identity matrix. The reachability matrix
for our continuing example is as follows:

© 2010 Taylor & Francis Group, LLC


Graph Theory for Testers  ◾  63

n1 n2 n3 n4 n5 n6 n7

n1 1 1 0 1 1 1 0

n2 0 1 0 0 1 0 0

n3 0 0 1 1 0 1 0

n4 0 0 0 1 0 1 0

n5 0 0 0 0 1 0 0

n6 0 0 0 0 0 1 0

n7 0 0 0 0 0 0 1

The reachability matrix tells us that nodes n2, n4, n5, and n6 can be reached from n1; node n5
can be reached from n2; and so on.

4.2.6 
n-Connectedness
Connectedness of ordinary graphs extends to a rich, highly explanatory concept for digraphs.

Definition

Two nodes ni and nj in a directed graph are

0-connected iff no path exists between ni and nj


1-connected iff a semipath but no path exists between ni and nj
2-connected iff a path exists between ni and nj
3-connected iff a path goes from ni to nj and a path goes from nj to ni

No other degrees of connectedness exist.


We need to modify our continuing example to show 3-connectedness. The change is the addi-
tion of a new edge e6 from n6 to n3, so the graph contains a cycle.
With this change, we have the following instances of n-connectivity in Figure 4.3 (not all are
listed):

n1 and n7 are 0-connected


n2 and n6 are 1-connected
n1 and n6 are 2-connected
n3 and n6 are 3-connected

In terms of one-way streets, you cannot get from n2 to n6.

© 2010 Taylor & Francis Group, LLC


64  ◾  Software Testing

n1 e1 n2 e4 n5

e2

n3 e3 n4 n7

e6
e5

n6

Figure 4.3  Directed graph with a cycle.

4.2.7 Strong Components
The analogy continues. We get two equivalence relations from n-connectedness: 1-connected-
ness yields what we might call “weak connection,” and this in turn yields weak components.
(These turn out to be the same as we had for ordinary graphs, which is what should happen,
because 1-connectedness effectively ignores direction.) The second equivalence relation, based on
3-connectedness, is more interesting. As before, the equivalence relation induces a partition on the
node set of a digraph; however, the condensation graph is quite different. Nodes that previously
were 0-, 1-, or 2-connected remain so. The 3-connected nodes become the strong components.

Definition

A strong component of a directed graph is a maximal set of 3-connected nodes.


In our amended example, the strong components are the sets {n3, n4, n6} and {n7}. The conden-
sation graph for our amended example is shown in Figure 4.4.
Strong components let us simplify by removing loops and isolated nodes. Although this is not
as dramatic as the simplification we had in ordinary graphs, it does solve a major testing problem.
Notice that the condensation graph of a digraph will never contain a loop. (If it did, the loop
would have been condensed by the maximal aspect of the partition.) These graphs have a special
name: directed acyclic graphs, sometimes written as DAG.

n1 e1 n2 e4 n5

e2

S1 S2

Figure 4.4  Condensation graph of digraph in Figure 4.3.

© 2010 Taylor & Francis Group, LLC

You might also like