0% found this document useful (0 votes)
98 views

Depth First Examples

The document discusses depth-first search (DFS) on digraphs (directed graphs). It provides examples of DFS on a sample digraph using different node selection methods. It also defines key DFS concepts like discovery time, finish time, and the active interval of nodes. Finally, it classifies the different types of edges that can exist in a DFS tree: tree edges, forward edges, back edges, and cross edges.

Uploaded by

starsiege2005
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Depth First Examples

The document discusses depth-first search (DFS) on digraphs (directed graphs). It provides examples of DFS on a sample digraph using different node selection methods. It also defines key DFS concepts like discovery time, finish time, and the active interval of nodes. Finally, it classifies the different types of edges that can exist in a DFS tree: tree edges, forward edges, back edges, and cross edges.

Uploaded by

starsiege2005
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Depth-first Search in Digraphs — examples

denotes a tree edge.

d(v), f(v) appears above or below each node v:


d(v) = discovery time of node v. The time at which node v is
first reached. The time of preorder processing.
f(v) = finish time of node v. The time at which node v is exited
for the last time. The time of postorder processing.
For a node v, active(v) = time interval d(v) to f(v) (inclusive).

Example 1: In this particular depth-first search, the alphabeti-


cally-first node is chosen, whenever an arbitrary choice is made.
2,29
B 3,12
1,34 D 4,11 5,10
A 30,33 31,32 N O
F C
13,28 Q
14,27 M 24,25 P
8,9
E I 6,7
15,26
H 17,22
G L
16,23
19,20
K
J 18,21
Example 2: Depth-first search of the same digraph. The alpha-
betically-last node is chosen, whenever an arbitrary choice is
made.
4,33
B 9,10
26,31 D 6,11 7,8
A 27,30 28,29 N O
F C
5,32 Q
24,25 M 12,23 P
1,34
E I 2,3
20,21
H 16,17
G L
15,18
14,19
K
J 13,22
Example 3: Depth-first search of the same digraph. In choosing
among adjacent vertices not yet discovered, the alphabetically-
first vertex is chosen. However, we choose H as the starting
vertex, and when the stack becomes empty (which didn’t occur
in Example 1 or 2), we choose E, then P, and then D as the next
vertex to discover.
21,30
B 17*,34
23,28 D 18,33 19,32
A 24,27 25,26 N O
F C
22,29 Q
13*,14 M 10,11 P
20,31
E I 15*,16
1*,12
H 3,8
G L
2,9
5,6
K
J 4,7
Depth-first Search in Digraphs — edges classified

Edge (u,v) is
a tree edge if active(u) ⊃ active(v), and there is no vertex
x with active(u) ⊃ active(x) ⊃ active(v),
a forward edge if active(u) ⊃ active(v), but (u,v) is not a
tree edge,
a back edge if active(u) ⊂ active(v),
a cross edge if active(u) ∩ active(v) = ∅ (in which case
active(v) entirely precedes active(u).

denotes a tree edge.


denotes a back edge. In an undirected graph,
these two types are not
denotes a forward edge. distinguishable
denotes a cross edge.
Here depth-first search of Example 1, with edges classified.

1,28
B 2,11
0,33 D 3,10 4,9
A 29,32 30,31 N O
F C
12,27 Q
13,26 M 23,24 P
7,8
E I 5,6
14,25
H 16,21
G L
15,22
18,19
K
J 17,20

You might also like