First, the summary
Deep search strategy: In the deep search process, for the latest discovery of the vertex, if it also has a starting point of the non-detected edge, along this side continue to probe down. When all the edges of Vertex v have been probed, the search goes back to those edges where the vertex v has a starting point.
Timestamp: When Vertex v is first discovered, the first timestamp d[v] is recorded, and the second timestamp f[v] is recorded when the adjacency table of V is checked. V is white before d[v], in the moment D[v] and F[v] is gray, after the moment f[v] is black.
Bracket theorem, nesting of descendant intervals, white path theorem
Side classification: (1) Tree Edge (2) Reverse Edge (3) Forward Edge (4) Cross Edge
For a deep search of the graph G, each edge of G is either a tree edge or a reverse edge.
Two, code 1.link_graph.h https://code.csdn.net/mishifangxiangdefeng/ Exerciseforalgorithmsecond/tree/master/src/chapter22/section22_3.cpp
2.main.cpp https:// Code.csdn.net/mishifangxiangdefeng/exerciseforalgorithmsecond/tree/master/tst/chapter22/section22_3test.cpp
3. Test Data book P335, figure 22-6 Q s
s v
v w
W s
Q w
Q T&N Bsp
T y
y q
T x
x z
Z x
u y
R y
r u
4. Output Results See 22.3-2
Third, exercise 22.3-1 The key is "any moment"
A map of the direction
|
White |
GRAY |
BLACK |
| White |
Tbfc |
Bc |
C |
| GRAY |
Tf |
TFB |
TFC |
| BLACK |
|
B |
Tfbc |
Graph without direction
|
White |
GRAY |
BLACK |
| White |
TB |
TB |
|
| GRAY |
TB |
TB |
TB |
| BLACK |
|
TB |
TB |
22.3-2Q:1 r:17 s:2 7 t:8 u:18 6 V:3 5 w:4 x:9 y:13: Tree side z:10: Tree side q->s: Forward side q->t: Tree side R >y: Cross-border s->v: Tree edge t->x: Tree side t->y: Tree side u->y: Cross edge v->w: Tree edge w->s: Reverse side x->z: Tree edge y->q: Reverse edge z->x: Reverse Edge
22.3-3(U (V (y (xx) y) v) u) (W (ZZ)) W)
22.3-6Introduction to Algorithms -22.3-6-using stacks to implement DFS
22.3-7Refer to the answer given on the 1 floor: v={w,u,v} e={(W,u), (U,w), (W,V)} has a path from u to V, U->w->v DFS in order W,u,u,v,v,w,d[u]=2,d[v]=4,d[u]<d[v] The resulting forest, both U and V are descended from W
22.3-8As shown in the figure, (1) There is a path from u to V
22.3-9Doesn't seem to change.
22.3-10
22.3-11The number of Unicom branches is indicated by Ceil, and the code is modified as follows:
void Link_graph::D fs ()
{
int u, ceil = 0;
Initialize for each vertex for
(U = 1, u <= n; u++)
{
v[u].color = white;
V[U].P = NULL;
}
Timestamp initialization time
= 0;
The vertex in V is retrieved sequentially, and when the white vertex is found, call Dfs_visit to access the vertex for
(U = 1; u <= n; u++)
{
if (V[u].color = =
) { ceil++;
Dfs_visit (U, ceil);
}}} void Link_graph::D fs_visit (int u, int ceil)
{
int v;
Edge *e;
Set U to grey
V[u].color = Gray;
Make the global variable time increment
time++;
The new value of time is recorded as the discovery
v[u].d = times;
e = V[u].head;
while (e)
{
v = e->end;
If the vertex is white if
(V[v].color = =)
{
////recursive access vertex
v[v].p = u;
Dfs_visit (V, ceil);
Tree Edge
e->type = tree;
}
else if (V[v].color = = GRAY)
{
//reverse edge
e->type = back;
}
else if (V[v].color = = BLACK)
{
//forward Edge
if (V[U].D < V[V].D)
e->type = FORWARD;
Cross Edge
else
e->type = crosses;
}
E = e->next;
}
After all the edges starting with u are explored, the V[u].color is black
.
V[u].ceil = Ceil;
And the completion time is recorded in f[u]
time++;
V[U].F = time;
}
22.3-12Single connected graph has no forward edge