forked from iNeeds365/Algorithm-and-Data-Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFS_EX_2.tex
More file actions
92 lines (81 loc) · 2.06 KB
/
DFS_EX_2.tex
File metadata and controls
92 lines (81 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{float}
\usepackage[english, boxed]{algorithm2e}
\usepackage{algpseudocode}
\pagenumbering{gobble}
\textheight=9.5in
\textwidth=6.5in
\topmargin=-.8in
\headsep=0pt
\oddsidemargin=0truecm
\evensidemargin=0truecm
\footskip=0pt
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{problem}[theorem]{Problem}
\begin{document}
% Author's definitions
\newcommand{\DEF}[1]{{\em #1\/}}
\newcommand\chic{\chi_c}
\newcommand\C{\hbox{${\cal C}$}}
\newcommand{\RR}{\mbox{$\mathbb R$}}
\newcommand{\NN}{\mbox{$\mathbb N$}}
\newcommand{\ZZ}{\mbox{$\mathbb Z$}}
\newcommand{\eopf}{\raisebox{0.8ex}{\framebox{}}}
\newcommand{\dist}{\hbox{\rm d}}
\renewcommand\a{\alpha}
\renewcommand\b{\beta}
\renewcommand\c{\gamma}
\renewcommand\d{\delta}
\newcommand\D{\Delta}
\newcommand{\directedchi}{\mbox{$\vec{\chi}$}}
\newcommand{\directedE}{\mbox{$\vec{E}$}}
\newcommand{\directedG}{\mbox{$\vec{G}$}}
\newcommand{\directedK}{\mbox{$\vec{K}$}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{function}
{\bf Edge classification}\\
\underline{{\bf Function} DFS} $()$\\
\ForEach{$v$ {\bf in} $V$}{
visited[$v$] = $false;$\\
pre[$v$] = $null$;\\
post[$v$] = $null$;\\
}
\ForEach{$v$ {\bf in} $V$}{
\If{visited[$v$]==$false$}
{
explore($v$);\\
}
}
\hbox{}
\underline{{\bf Function} explore} $(z)$\;
pre[$z$] = clock ++; \\
visited[$z$] = true; \\
\ForEach{$(z,w)$ {\bf in} $E$}{
\If{visited[$w$]==false}{
print: (z,w) is a tree edge\\
explore($w$);\\
}
\ElseIf{pre[z] $<$ pre[w]}
{
print: (z,w) is a forward edge
}
\ElseIf{post[w] == null}
{
print: (z,w) is a back edge
}
\Else
{
print: (z,w) is a cross edge
}
}
post[$z$] = clock++;
\end{function}
\end{document}