Corrections

This commit is contained in:
Antti H S Laaksonen 2017-02-18 15:14:04 +02:00
parent 5ab9105861
commit 37b767b135
1 changed files with 44 additions and 38 deletions

View File

@ -1,6 +1,6 @@
\chapter{Paths and circuits} \chapter{Paths and circuits}
This chapter focuses on two types of paths in a graph: This chapter focuses on two types of paths in graphs:
\begin{itemize} \begin{itemize}
\item An \key{Eulerian path} is a path that \item An \key{Eulerian path} is a path that
goes through each edge exactly once. goes through each edge exactly once.
@ -12,9 +12,9 @@ similar concepts at first glance,
the computational problems related to them the computational problems related to them
are very different. are very different.
It turns out that there is a simple rule that It turns out that there is a simple rule that
determines whether a graph contains an Eulerian path, determines whether a graph contains an Eulerian path
and there is also an efficient algorithm for and there is also an efficient algorithm to
finding a path if it exists. find a such path if it exists.
On the contrary, checking the existence of a Hamiltonian path is a NP-hard On the contrary, checking the existence of a Hamiltonian path is a NP-hard
problem and no efficient algorithm is known for solving the problem. problem and no efficient algorithm is known for solving the problem.
@ -154,16 +154,16 @@ so there is an Eulerian path between nodes 2 and 5,
but the graph does not contain an Eulerian circuit. but the graph does not contain an Eulerian circuit.
In a directed graph, In a directed graph,
we should focus on indegrees and outdegrees we focus on indegrees and outdegrees
of the nodes in the graph. of the nodes of the graph.
A directed graph contains an Eulerian path A directed graph contains an Eulerian path
if all the edges belong to the same strongly if all the edges belong to the same strongly
connected component and connected component and
\begin{itemize} \begin{itemize}
\item each node has the same indegree and outdegree \emph{or} \item in each node, the indegree equals the outdegree, \emph{or}
\item in one node, indegree is one larger than outdegree, \item in one node, the indegree is one larger than the outdegree,
in another node, outdegree is one larger than indegree, in another node, the outdegree is one larger than the indegree,
and all other nodes have the same indegree and outdegree. and all other nodes, the indegree equals the outdegree.
\end{itemize} \end{itemize}
In the first case, each Eulerian path in the graph In the first case, each Eulerian path in the graph
@ -223,11 +223,13 @@ from node 2 to node 5:
\index{Hierholzer's algorithm} \index{Hierholzer's algorithm}
\key{Hierholzer's algorithm} is an efficient \key{Hierholzer's algorithm} is an efficient
method for constructing an Eulerian circuit method for constructing
for an undirected graph. an Eulerian circuit.
The algorithm assumes that all edges belong to The algorithm consists of several rounds,
the same connected component, each of which adds new edges to the circuit.
and the degree of each node is even. Of course, we assume that the graph contains
an Eulerian circuit; otherwise Hierholzer's
algorithm cannot find it.
First, the algorithm constructs a circuit that contains First, the algorithm constructs a circuit that contains
some (not necessarily all) of the edges in the graph. some (not necessarily all) of the edges in the graph.
@ -236,22 +238,26 @@ step by step by adding subcircuits to it.
The process continues until all edges have been added The process continues until all edges have been added
to the circuit. to the circuit.
The algorithm extends the circuit by always choosing The algorithm extends the circuit by always finding
a node $x$ that belongs to the circuit but has a node $x$ that belongs to the circuit but has
some edges that are not included in the circuit. an outgoing edge that is not included in the circuit.
The algorithm constructs a new path from node $x$ The algorithm constructs a new path from node $x$
that only contains edges that are not in the circuit. that only contains edges that are not yet in the circuit.
Since the degree of each node is even, Sooner or later,
the path will return to the node $x$ sooner or later, the path will return to the node $x$,
which creates a subcircuit. which creates a subcircuit.
If the graph contains two odd-degree nodes, If the graph only contains an Eulerian path,
Hierholzer's algorithm can also be used to we can still use Hierholzer's algorithm
construct an Eulerian path by adding an to find it by adding an extra edge to the graph
extra edge between the odd-degree nodes. and removing the edge after the circuit
After this, we can first construct an Eulerian circuit has been constructed.
and then remove the extra edge, For example, in an undirected graph,
which yields an Eulerian path in the original graph. we add the extra edge between the two
odd-degree nodes.
Next we will see how Hierholzer's algorithm
constructs an Eulerian circuit in an undirected graph.
\subsubsection{Example} \subsubsection{Example}
@ -282,7 +288,7 @@ Let us consider the following graph:
\end{samepage} \end{samepage}
\begin{samepage} \begin{samepage}
Suppose the algorithm first creates a circuit Suppose that the algorithm first creates a circuit
that begins at node 1. that begins at node 1.
A possible circuit is A possible circuit is
$1 \rightarrow 2 \rightarrow 3 \rightarrow 1$: $1 \rightarrow 2 \rightarrow 3 \rightarrow 1$:
@ -486,9 +492,9 @@ is at least $n$,
the graph contains a Hamiltonian path. the graph contains a Hamiltonian path.
\end{itemize} \end{itemize}
A common feature in these theorems and other results is A common property in these theorems and other results is
that they guarantee that a Hamiltonian path exists that they guarantee the existence of a Hamiltonian
if the graph has \emph{a lot} of edges. if the graph has \emph{a large number} of edges.
This makes sense, because the more edges the graph contains, This makes sense, because the more edges the graph contains,
the more possibilities there is to construct a Hamiltonian graph. the more possibilities there is to construct a Hamiltonian graph.
@ -522,7 +528,7 @@ It is possible to implement this solution in $O(2^n n^2)$ time.
A \key{De Bruijn sequence} is a string that contains A \key{De Bruijn sequence} is a string that contains
every string of length $n$ every string of length $n$
exactly once as a substring, for a fixed exactly once as a substring, for a fixed
alphabet that consists of $k$ characters. alphabet of $k$ characters.
The length of such a string is The length of such a string is
$k^n+n-1$ characters. $k^n+n-1$ characters.
For example, when $n=3$ and $k=2$, For example, when $n=3$ and $k=2$,
@ -537,7 +543,7 @@ corresponds to an Eulerian circuit in a graph.
The idea is to construct the graph so that The idea is to construct the graph so that
each node contains a combination of $n-1$ characters each node contains a combination of $n-1$ characters
and each edge adds one character to the string. and each edge adds one character to the string.
The following graph corresponds to the example case: The following graph corresponds to the above example:
\begin{center} \begin{center}
\begin{tikzpicture} \begin{tikzpicture}
@ -559,10 +565,10 @@ The following graph corresponds to the example case:
\end{tikzpicture} \end{tikzpicture}
\end{center} \end{center}
An Eulerian path in this graph produces a string An Eulerian path in this graph corresponds to a string
that contains all strings of length $n$. that contains all strings of length $n$.
The string contains the characters in the starting node The string contains the characters of the starting node
and all character in the edges. and all characters in the edges.
The starting node has $n-1$ characters The starting node has $n-1$ characters
and there are $k^n$ characters in the edges, and there are $k^n$ characters in the edges,
so the length of the string is $k^n+n-1$. so the length of the string is $k^n+n-1$.
@ -613,13 +619,13 @@ For example, here is an open knight's tour on a $5 \times 5$ board:
\end{center} \end{center}
A knight's tour corresponds to a Hamiltonian path in a graph A knight's tour corresponds to a Hamiltonian path in a graph
whose nodes represent the squares of the board, whose nodes represent the squares of the board
and two nodes are connected with an edge if a knight and two nodes are connected with an edge if a knight
can move between the squares according to the rules of chess. can move between the squares according to the rules of chess.
A natural way to construct a knight's tour is to use backtracking. A natural way to construct a knight's tour is to use backtracking.
The search can be made more efficient by using The search can be made more efficient by using
\key{heuristics} that attempts to guide the knight so that \key{heuristics} that attempt to guide the knight so that
a complete tour will be found quickly. a complete tour will be found quickly.
\subsubsection{Warnsdorff's rule} \subsubsection{Warnsdorff's rule}