SIAM J. COMPUT.
Vol. 1, No. 2, June 1972
Abstract. The value of depth-first search or "bacltracking" as a technique for solving problems is
illustrated by two examples.
version of an algorithm for finding the strongly connected
components of a directed graph and ar algorithm for finding the biconnected components of an un-
direct graph are presented. The space and time requirements
of both algorithms are bounded by
for some constants kl, k2, and k
where Vis the number ofvertices and E is the number
of edges of the graph being examined.
Key words. Algorithm, backtracking, biconnectivity, connectivity, depth-first, graph, search,
spanning tree, strong-connectivity.
Introduction. Consider a
graph G, consisting of a set of vertices
The graph may either be directed
(the edges are ordered pairs (v, w)
of vertices; v is the tail and w is the head of the edge) or undirected (the edges are
unordered pairs of vertices, also represented as (v, w)). Graphs form a suitable
abstraction for problems in many areas; chemistry, electrical engineering, and
sociology, for example. Thus it is important to have the most economical algo-
rithms for answering graph-theoretical questions.
In studying graph algorithms we cannot avoid at least a few definitions.
These definitions are more-or-less standard in the literature. (See Harary ,
for instance.) If G
graph, a path p’v
w in G is a sequence ofvertices
and edges leading from v to w.
is simple if all its vertices are distinct.
v is called a closed path.
closed path p’v
v is a cycle if all its
distinct and the only vertex to occur twice in p is v, which occurs exactly twice.
which are cyclic permutations of each other are considered to be the
cycle. The undirected version of a directed graph
the graph formed by
converting each edge of the directed graph into an undirected edge and removing
undirected graph is connected if there is a path between every
pair of vertices.
A (directed rooted)
a directed graph whose undirected version is
connected, having one vertex which
the head of no edges (called the root),
and such that all vertices except the root are the head of exactly one edge. The
relation "(v, w) is an
edge of T"
v- w. The relation "There is a
path from v to
w in T" is denoted
of w and w is a
son of v. If v
w, v is an ancestor of w and w is a descendant of
ancestor and a descendant of itself. If v is a vertex in a tree
is the subtree of T
having as vertices all the descendants of v in T. If G is a directed graph, a tree T
is a spanning tree of G if
subgraph of G and T contains all the vertices of G.
If R and S