in Fig. 1, the nontree edge (v
2
;v
5
) is a cross edge with
respect to T
v
1
, but a back edge with respect to T
v
2
.
For each nontree edge e 2 E ÿ T , we define CROSSe
as the set of vertices v in V such that e is a cross edge with
respect to T
v
. Similarly, for each nontree edge e 2 E ÿ T ,
we define BACKe as the set of vertices v in V such that e
is a back edge with respect to T
v
. Note that for each
nontree edge e 2 E ÿ T , CROSSe\BACKe; and
CROSSe[BACKeV .
We have the following theorem.
Theorem 1. T is an unordered DFT tree of G if and only if
V ÿ
S
e2EÿT
CROSSe is not an empty set.
Proof. Suppose V ÿ
S
e2EÿT
CROSSe is not empty. Let s
be a vertex in V ÿ
S
e2EÿT
CROSSe. For each nontree
edge e 2 E ÿ T , s is not in CROSSe. Therefore, by
definition, all nontree edges in E ÿ T are back edges
with respect to T
s
. Consequently, T
s
is a DFS tree, and
thus, T is a DFS tree of G. The if-part of this theorem is
established.
Now, suppose that T is a DFS tree of G. Recall that T
is a DFS tree of G if and only if there is a vertex v 2 V
such that T
v
has no cross edge. Let s be a vertex in V
such that T
s
has no cross edge. Since T
s
has no cross
edge, s is not in CROSSe for every nontree edge
e 2 E ÿ T . Thus, s is in V ÿ
S
e2EÿT
CROSSe Therefore,
V ÿ
S
e2EÿT
CROSSe is not empty. The only-if part of
this theorem is established. tu
Theorem 1 is a necessary and sufficient condition for
recognizing DFS trees. According to it, our recognition
problem becomes the problem of determining whether V ÿ
S
e2EÿT
CROSSe is empty. In case V ÿ
S
e2EÿT
CROSSe
is not empty, T is a DFS tree of G and each vertex v in
V ÿ
S
e2EÿT
CROSSe is a candidate root of T .
The above discussion provides the base of our recogni-
tion algorithms. Later, in this section, we will give some
properties which are helpful for determining CROSSe for
a given nontree edge e. To speedup the computation of
V ÿ
S
e2EÿT
CROSSe, we need an efficient way to
represent the set V such that we can remove each set
CROSSe easily. In our algorithms, we will use an Euler
tour of T to represent the set V . Using this representation, as
we will show in Section 3, each CROSSe can be removed
from V by performing a constant number of weight
assignments together with a prefix sum computation.
Furthermore, the removal of
S
e2EÿT
CROSSe can be
done efficiently by performing On weight assignments
and a prefix sum computation. Section 3 will define Euler
tours and give a sequential implementation of the above
idea in detail. Most steps of the sequential algorithm
proposed in Section 3 are easily parallelized. However, a
straightforward parallel implementation will result in write
conflicts. Section 4 will provide some noble tricks to avoid
write conflicts and describe our parallel implementation.
First, in the remainder of this section, we give some
properties which are helpful for determining CROSSe
and BACKe for any nontree edge e.
Lemma 1. Let e v; w be a nontree edge in E ÿ T
and treepathv; wv; u
1
; ...;u
k
;w;k>0.Then,
CROSSeV ÿS
v
[ S
w
and BACKeS
v
[ S
w
,
where S
v
and S
w
denote, respectively, the subtree of T
attached to u
1
via the edge v; u
1
and the subtree of T attached
to u
k
via the edge w; u
k
.
Proof. Removing all edges in treepathv; w from T;
k 2 disjoint subtrees can be obtained. Denote
S
v
;S
1
;S
2
; ...;S
k
; and S
w
as the obtained subtrees
containing v; u
1
;u
2
; ...;u
k
, and w, respectively, as shown
in Fig. 2. Consider any vertex x in S
i
; 1 i k.Ifx is
the root of T , the edge v; w is a cross edge. Thus, all
vertices in S
i
; 1 i k, are in CROSSe. On the other
hand, consider any vertex x in S
v
and S
w
.Ifx is the
root of T,theedge(v; w) is a back edge. Thus,
CROSSe
S
1ik
S
i
and BACKeS
v
[ S
w
. Since
S
1ik
S
i
V ÿS
v
[ S
w
, the lemma holds. tu
In the algorithms we shall propose in the next two
sections, we will choose an arbitrary vertex r 2 V and then
orient T into a rooted tree T
r
. In the rooted tree T
r
,a
nontree edge e v; w is either a cross edge or a back edge,
as shown in Fig. 3a and 3b, respectively. Suppose e is a cross
edge in T
r
, as shown in Fig. 3a. In this case, treepathv; w
is the conjunction of the tree path from v up to lcav; w and
the tree path from w up to lcav; w, where lcav; w denotes
the lowest common ancestor of v and w. By comparing
Fig. 3a with Fig. 2, we obtain the following corollary from
Lemma 1 immediately .
Corollary 1. Let e v; w be a cross edge with respect to T
r
.
Then, CROSSeV ÿX
v
[ X
w
and
BACKeX
v
[ X
w
;
where X
v
and X
w
denote the two subtrees in T
r
rooted at v
and w, respectively.
On the other hand, suppose e is a back edge in T
r
,as
shown in Fig. 3b. Without loss of generality, assume v is an
ancestor of w. In this case, treepathv; w can be traced by
starting from w up to v directly. We define childv; w as the
child of v on treepathv; w. By comparing Fig. 3b with
Fig. 2, we obtain the following corollary from Lemma 1
immediately.
PENG ET AL.: RECOGNIZING UNORDERED DEPTH-FIRST SEARCH TREES OF AN UNDIRECTED GRAPH IN PARALLEL 561
Fig. 2. The subtrees S
v
;S
1
;S
2
; ...;S
k
, and S
w
for a nontree edge
e v; w. Subtrees containing vertices in CROSSe are shadowed.