Skip to content

Commit

Permalink
Update 22.3.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Chen committed Jun 13, 2019
1 parent 7e653da commit 3a52755
Showing 1 changed file with 53 additions and 26 deletions.
79 changes: 53 additions & 26 deletions docs/Chap22/22.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ According to Theorem 22.7, there are 3 cases of relationship between interval of

- For Directed Graph:

1. $\text{BLACK}$ to $\text{BLACK}$ and $\text{WHITE}$ to $\text{WHITE}$ works with everything, we omit this two later.
2. For Cross Edge $(u, v)$, we must have $v.d < v.f < u.d < u.f$, then it could be $\text{WHITE}$ to $\text{BLACK}$, $\text{WHITE}$ to $\text{GRAY}$ and $\text{GRAY}$ to $\text{BLACK}$.
3. For Tree Edge and Forward Edge $(u, v)$, we must have $u.d < v.d < v.f < u.f$, then it could be $\text{GRAY}$ to $\text{WHITE}$, $\text{GRAY}$ to $\text{GRAY}$ and $\text{GRAY}$ to $\text{BLACK}$.
4. For Back Edge $(u, v)$, we must have $v.d < u.d < u.f < v.f$, then it could be $\text{WHITE}$ to $\text{GRAY}$, $\text{GRAY}$ to $\text{GRAY}$ and $\text{BLACK}$ to $\text{GRAY}$.

$$
\begin{array}{c|ccc}
from\backslash to & \text{BLACK} & \text{GRAY} & \text{WHITE} \\\\
\hline
\text{BLACK} & \text{Allkinds} & \text{Back} & - \\\\
\text{GRAY} & \text{Tree, Forward, Cross} & \text{Tree, Forward, Back} & \text{Tree, Forward} \\\\
\text{WHITE} & \text{Cross} & \text{Cross, Back} & \text{Allkinds}
\end{array}
$$
1. $\text{BLACK}$ to $\text{BLACK}$ and $\text{WHITE}$ to $\text{WHITE}$ works with everything, we omit this two later.
2. For Cross Edge $(u, v)$, we must have $v.d < v.f < u.d < u.f$, then it could be $\text{WHITE}$ to $\text{BLACK}$, $\text{WHITE}$ to $\text{GRAY}$ and $\text{GRAY}$ to $\text{BLACK}$.
3. For Tree Edge and Forward Edge $(u, v)$, we must have $u.d < v.d < v.f < u.f$, then it could be $\text{GRAY}$ to $\text{WHITE}$, $\text{GRAY}$ to $\text{GRAY}$ and $\text{GRAY}$ to $\text{BLACK}$.
4. For Back Edge $(u, v)$, we must have $v.d < u.d < u.f < v.f$, then it could be $\text{WHITE}$ to $\text{GRAY}$, $\text{GRAY}$ to $\text{GRAY}$ and $\text{BLACK}$ to $\text{GRAY}$.

$$
\begin{array}{c|ccc}
from\backslash to & \text{BLACK} & \text{GRAY} & \text{WHITE} \\\\
\hline
\text{BLACK} & \text{Allkinds} & \text{Back} & - \\\\
\text{GRAY} & \text{Tree, Forward, Cross} & \text{Tree, Forward, Back} & \text{Tree, Forward} \\\\
\text{WHITE} & \text{Cross} & \text{Cross, Back} & \text{Allkinds}
\end{array}
$$

- For Undirected Graph, starting from Directed Chart, we remove the Forward Edge and Cross Edge, and when a Back Edge exist, we add Tree Edge; when a Tree Edge exist, we add Back Edge. This is correct for following reason:

1. Theorem 22.10: In a depth-first search of an undirected graph $G$, every edge of $G$ is either a tree edge or a back edge. So Tree edge and back edge only.
2. If $(u, v)$ is a Tree edge from $u$'s perspective, $(u, v)$ is also a Back Edge from $v$'s perspective.
1. Theorem 22.10: In a depth-first search of an undirected graph $G$, every edge of $G$ is either a tree edge or a back edge. So Tree edge and back edge only.
2. If $(u, v)$ is a Tree edge from $u$'s perspective, $(u, v)$ is also a Back Edge from $v$'s perspective.

$$
\begin{array}{c|ccc}
from\backslash to & \text{BLACK} & \text{GRAY} & \text{WHITE} \\\\
\hline
\text{BLACK} & \text{Tree, Back} & \text{Tree, Back} & - \\\\
\text{GRAY} & \text{Tree, Back} & \text{Tree, Back} & \text{Tree, Back} \\\\
\text{WHITE} & - & \text{Tree, Back} & \text{Tree, Back}
\end{array}
$$
$$
\begin{array}{c|ccc}
from\backslash to & \text{BLACK} & \text{GRAY} & \text{WHITE} \\\\
\hline
\text{BLACK} & \text{Tree, Back} & \text{Tree, Back} & - \\\\
\text{GRAY} & \text{Tree, Back} & \text{Tree, Back} & \text{Tree, Back} \\\\
\text{WHITE} & - & \text{Tree, Back} & \text{Tree, Back}
\end{array}
$$

## 22.3-2

Expand Down Expand Up @@ -98,7 +98,34 @@ By Theorem 22.10, every edge of an undirected graph is either a tree edge or a b

> Rewrite the procedure $\text{DFS}$, using a stack to eliminate recursion.
See the algorithm $\text{DFS-STACK}(G)$. Note that by a similar justification to 22.2-3, we may remove line 8 from the original $\text{DFS-VISIT}$ algorithm without changing the final result of the program, that is just working with the colors white and gray.
```cpp
DFS(G, s)
for each vertex u ∈ G.V
u.color = WHITE
u.π = NIL
time = 0
S = Ø
for each vertex u ∈ G.V
if u.color == WHITE
S.PUSH(u)
while !S.EMPTY()
u = S.TOP()
if u.color == WHITE
u.color = GRAY
time = time + 1
u.d = time
for each v ∈ G.Adj[u].REVERSE()
if v.color == WHITE
v.π = u
S.PUSH(v)
else if u.color == GRAY
u.color = BLACK
time = time + 1
u.f = time
S.POP()
else if u.color == BLACK
S.POP()
```
## 22.3-8
Expand Down

0 comments on commit 3a52755

Please sign in to comment.