1 Euler, Hamilton and Five Classical Puzzles: August 23, 2019
1 Euler, Hamilton and Five Classical Puzzles: August 23, 2019
There are …nite grids that cannot be tiled this way. We have, for instance,
that if the number of cells is odd, then the grid cannot be tiled. We can consider
di¤erent problems about tilings, the …rst one is related to the existence of tilings.
In this problem, we are given a …nite grid, and we have to decide if the grid has
at least one tiling. There exist, as usual, easy instances of the latter problem: if
the grid is odd (the number of its cells is odd), then it cannot be tiled. However,
there also some instances that are very much harder than those odd instances.
Consider the following example:
Exercise 1 Let G be a rectangular grid, and let G be the grid that is obtained
from G after removing the northwest and the southeast corners of G. Can the
grid G be tiled?
After solving the above exercise the reader can try to answer a more de-
manding question: does there exist an (e¢ cient) algorithm that given an even
grid as input determines wether it can be tiled? After some though the reader
will …gure out the requested algorithm. Thus, it seems that tiling problems are
easy. Is the latter true? We can consider some problems related to tilings and
which are of a very di¤erent nature.
1
Let G be a rectangular grid, and let # (G) be the number of cells in G. If
# (G) is even, the grid G can be easily tiled. Moreover, if height and length are
both larger than 1; the grid G can be tiled in many di¤erent ways, using in each
one of those tilings a total amount of #(G)
2 tiles. Given n; m 2 N, what is the
number of tilings of the n m grid? The latter question (counting problem)
seems to be a hard one. We can consider many hard problems related to tilings.
Let T be a tiling, we use the symbol # (T ) to denote the number of tiles that
are vertically displayed. Which is the minimum value of # (T ) that can reached
by a tiling of G? The latter question seems to be even harder than the former.
This is a typical optimization question, and optimization questions use to be
hard. Things can become even harder. It happens if, for instance, we decide to
ask for the minimal value of # (T ) as well as for a tiling achieving this minimal
value. The latter problem corresponds to a typical construction problem. So far
we have considered four di¤erent types of algorithmic problems about tilings:
recognition, counting, optimization and construction problems. Consider the
following counting problem:
Exercise 3 Let n 1, prove that the number of tilings of the rectangular grid
of length n and height 2 is equal to Fn , where Fn is the n-th Fibonacci number.
The counting of tilings is an old and deep problem, an odd and deep math-
ematical puzzle that becomes an important problem of statistical mechanics
because it is related to the partition function of the dimer model (see below).
A second puzzle is The Three Commodities Problem. Suppose we have a
two-dimensional town with just three houses, and suppose also that there are
three di¤erent commodities that are produced at di¤erent points (factories) in
the plane, and which must be carried out to each one of the three houses in
town. Thus, given a factory x and a house y; those two points in the plane must
be connected by a planar curve that begins at x and ends at y: If we choose
three houses, three factories and nine curves connecting factories and houses, we
get a POT. We say that the chosen POT is planar, if and only if, the following
condition is satis…ed:
Two curves meet at point s, if and only if, s is either the common origin or
the common end of both curves.
The question is the following one: can one choose the six points and the nine
curves in such a way that he gets a planar POT?
2
Thus, we have an existential problem, which can be seen as a single instance
of a recognition problem: recognize the con…gurations that can be represented
in the plane in such a way that the non-crossing condition is satis…ed. We will
be back with those questions in the near future.
Let us continue with the third puzzle of our list. This is the very famous four
colors problem, which can be understood as an optimization problem. Suppose
that one has to color a map. It is better if he uses as few colors as possible. On
the other hand, he is forced to use as many colors as necessary. Notice that if the
map is non-trivial (it contains at least two countries with a common border) one
color is not enough. It happens because a valid coloring (a coloring that does
not displease the teacher) must satisfy the following constraint: two countries
having a common border cannot be colored with the same color. It is natural
to ask: given a map M , which is the minimal number of colors required to color
M properly? It was conjectured for long time that four colors is enough, and
this conjecture was proved to be true after a very long time. The proof is some
kind of brute force check that requires the employment of computers. We will
be back with this problem in short time.
To …nish with this introductory lecture we have to introduce the remaining
two puzzles, which, as a matter of fact, are closely related.
The fourth puzzle is the famous Konisberg Puzzle. This puzzle asks if there is
a way of walking across Konisberg downtown, (Kaliningrad downtown), in such
a way that one crosses each one of its seven bridges exactly once. Thus, the
puzzle asks for the existence of a path with certain combinatorial properties.
We observe that this latter question is very similar to the question proposed
by Sir William Rowan Hamilton and his Icosian Game. The icosian game is
a mathematical game invented in 1857 by Sir William. The game’s object
is …nding a cycle along the edges of a dodecahedron such that every vertex is
visited just once. The puzzle was distributed commercially and was subsequently
marketed in Europe in many forms. Unfortunately, for Sir William, the game
was not successful.
3
dodecahedral graph? The dodecahedron is made of vertex, edges and faces.
Notice that Hamilton’s game has no relation with faces. Notice also that if you
forget the faces you have a relational structure constituted by vertex and edges
that can be easily represented in the plane:
Choose twelve points in the plane to represent the vertex of the dodecahe-
dron. Connect two of those points with the corresponding line segment, if and
only if, those two points represent vertex of the dodecahedron that are connected
by an edge.
Moreover, the twelve points can be chosen in such a way that the line seg-
ments representing edges of the dodecahedron satisfy the non-crossing condition
introduced above (see The Three Commodities Problem). That is: the dodeca-
hedron graph is a graph admitting a planar representation.
Exercise 5 Construct a planar representation of the dodecahedron graph.
The icosian game was distributed as a checkerboard containing a planar
representation of the dodecahedron graph. Then, the question was to look for
a trajectory in the graph that visits all the nodes at most once, except for the
initial node that is visited twice, at the end and at the beginning.
What is a graph? Graphs are the most simple non-trivial relational struc-
tures
De…nition 6 A graph is a pair G = (V; E), such that V is a set, and E
P 2 (V ) : Recall that P 2 (V ) is the set fA 2 P (V ) : jAj 2g :
We say that V is the set of nodes of G; and we say that E is the set of edges
of G:
De…nition 7 We say that G is a …nite graph, if and only if, the set V is …nite.
Notice that any …nite graph can be graphically represented in the plane:
Let G be a …nite graph. We can choose jV j points in the plane and de…ne
a bijection between V and the chosen set of points. Then, given fu; vg 2 E; we
choose a planar curve connecting the point that represents the node u and the
point that represents the node v: We make the same thing with all the edges of
G:
If we work without care, then we will have that, with a high probability,
the chosen curves meet each other at points that are di¤erent to their com-
mon end-nodes (if those edges have common end-nodes). This means that most
graphical representations do not satisfy the non-crossing condition introduced
above. Actually, there are graphs that cannot be represented in the plane with-
out crossings. Those graphs are called nonplanar graphs.
Exercise 8 Look for a good candidate to be a nonplanar graph.
Given a graph G; a path on G is a connected sequence of edges, say
fv1 ; v2 g ; fv2 ; v3 g :::; fvn 1 ; vn g 2 E:
We say that the path is a circuit, if and only if, v1 = vn . We say that the
path e1 ; :::; en visits node v, if and only if, there exists j n such that v 2 ej :
4
De…nition 9 A graph G is Hamiltonian, if and only if, there exists a circuit
on G; say fv1 ; v2 g ; fv2 ; v3 g :::; fvn 1 ; vn g, which visits each node exactly once,
except the node v1 = vn that is visited twice.
The …rst and second edges, as well as the third and fourth edges, seem to be
equal. However, those two pairs of edges must be considered as di¤erent. Then,
they must be represented as two di¤erent curves connecting the same pair of
points in the plane.
The above …gure seems to correspond well to the notion of graph: we have
sites connected by bridges. However, it is important to stress that it exhibits
a special feature that does not …t well with the de…nition of graph: it contains
two di¤erent edges connecting the same pair of nodes.
Exercise 10 Propose a notion of graph such that The Konisberg Graph becomes
a model of this Theory.
De…nition 11 We say that graph G is Eulerian, if and only if, there exists a
path, say e1 ; :::; em ; such that for all e 2 E there exists a single j m for which
the equality e = ej holds (i.e. each edge of G is crossed exactly once).
5
set of edges of this graph is equal to f(hi ; Cj ) : i; j 2 f1; 2; 3gg : The question is
the following one: is the latter graph a non-planar graph?
6
2 Euler on Konisberg
Leonhard Euler is famous for many things, one of them the solution of The
Konisberg Puzzle. The latter, solving this very speci…c puzzle, is a minor con-
tribution. However, it hides a major contribution of Euler: the introduction of
Graph Theory. Euler discovered that there was a general underlying structure
behind the formulation of the puzzle. Moreover, he was able of abstracting from
the problem the de…nition of graph as we know it today.
Graphs are the most simple combinatorial structures. Notice that a graph is
a set endowed with a binary relation (the adjacency relation). Simpler structures
are sets endowed with a …nite number of unary relations. Notice that the latter
type of structures are somewhat trivial: they cannot be used to model interesting
problems, and they do not have interesting substructures. It is not the case with
graphs, which could contain paths, circuits, cliques, independent sets etc.
Most of the time we will be studying problems related to graph-substructures.
Most of those problems have an algorithmic formulation:
Either decide if the input graph contains a substructure of a certain type,
Or construct, if possible, a certain type of substructure of the input graph,
Or compute an optimal substructure (according to a certain criterion of
optimallity) of the input graph,
Or count the substructures of a certain type occurring in the input graph.
One solves one of those algorithmic problems, if and only if, he can exhibit
an e¢ cient algorithm solving the corresponding task. We assume the standard
convention: an algorithm is e¢ cient, if and only if, its running time is polynomial
with respect to the size of the input. The size of a graph, given as input, is equal
to the number of its nodes.
Consider the following problem
7
It checks if the constructed list contains a path in G:
Notice that the above theorem is quite trivial. Therefore, we say that the
algorithm is naive: because it is based on a trivial theorem.
All algorithms are based on theorems (there is a certain kind of bijective cor-
respondence), and naive algorithms are based on trivial theorems. The problem
with naive algorithms is that they use to be unfeasible. What is the running
time of our brute force algorithm? Observe that the running time is lower-
bounded by the size of the list that must be constructed in the …rst step. The
size of this list is equal to m! > 2m : Moreover, given n 4, there exists a graph
with n nodes containing more than n edges. We use the symbol rt (n) to denote
the running time of the algorithm. We have that rt (n) 2 (2n ) :
Conclusion 15 Are you familiar with asymptotic notation? I hope yes, other-
wise you have to give a fast check to this topic.
De…nition 17 A graph G is connected, if and only if, any two nodes are con-
nected by a path.
8
Notice that any Eulerian graph is connected. Euler proved a non-trivial
theorem about Eulerian graphs.
The theorem can also be used to solve the construction problem, but to this
end we need to study the proof of the theorem
Proof. The proof proceeds in the following way: we try to construct an Eulerian
trail edge by edge, to this end we de…ne the way the successive edges are chosen,
we show that if the input graph satis…es the conditions in the statement of
the theorem, then the procedure can be happily put to an end (all edges are
traversed)
Let us suppose that the input graph is connected and contains exactly two
nodes of odd degree, say the nodes u and v: In this case we construct an Eulerian
path going from u to v: Notice that the choice of the starting node does not
matter: if we construct an Eulerian path from u to v, we also construct an
Eulerian path from v to u (it is enough to reverse the direction of the constructed
path).
A con…guration is a 4-tuple (V ; E ; u ; v ) such that V V; E E, the
pair (V ; E ) is a connected graph and u ; v 2 V : Moreover, we have that if
(V ; E ; u ; v ) is a con…guration, then:
Choose e 2 Ei such that there exists ai+1 2 Vi for which e = fui ; ai+1 g :
Set Ei+1 = Ei n feg, ui+1 = ai+1 ; vi+1 = vi ; Vi+1 = Ve , where
8 9
< [ =
Ve = v 2 Vi : v 2 f :
: ;
f 2(Ei nfeg)
satis…es:
9
Vi+1 V; Ei+1 E, the pair (Vi+1 ; Ei+1 ) is a graph and ui+1 ; vi+1 2 Vi+1 :
Either ui+1 6= vi+1 and fui+1 ; vi+1 g is equal to the set of odd degree nodes
of graph (Vi+1 ; Ei+1 ) ; or ui+1 = vi+1 and all the nodes in (Vi+1 ; Ei+1 ) are
even degree nodes.
Thus, we have that (Vi+1 ; Ei+1 ; ui+1 ; vi+1 ) is almost a con…guration. How-
ever, we have to observe that we have not guaranteed that (Vi+1 ; Ei+1 ) is a
connected graph. If we want to ful…ll the remaining condition we will have to
choose edge e carefully.
Claim. If (Vi ; Ei ; ui ; vi ) is a con…guration, there exists e 2 Ei such that Ce
is a con…guration.
(Proof of the claim) Let C = (V; E; u; v) be a con…guration. Let us suppose
that u 6= v, we have to prove that there exists an edge e such that u 2 e and
(Ve ; En feg) is connected. Let Hu be the graph that is obtained from (V; E)
after eliminating node u; and all the edges that are incident with u: Suppose
that Hu is connected, in this case we can choose any e. Now suppose that Hu
is disconnected. Then, there exists a connected component of Hu , say C, for
which there exist at least two edges connecting it to node u: We can choose any
of the edges connecting u and C:
We would like to observe that the proof of Euler’s Theorem provide us with
a procedure for the construction of Eulerian trails. The algorithm works, on
input (V; E; u; v), as follows:
1. Compute m = jEj :
2. Set X = 0; Y = V , Z = E; x = u, y = v and T = , where is the empty
string.
3. If X = m halt and output the string T , otherwise compute the edges in
Z that are incident with x: Let e1 ; :::; en be the computed list. Look for an
i n such that (Yei ; Zn fei g) is connected. If no i can be found halt and
reject the input, otherwise compute
10
to detect the pairs (Y; Z) that are connected (provided we can recognize the
connected graphs). We will solve this latter problem in the next lecture, in the
meantime we can suppose that we have access to an oracle which can answer in
one time unit any query concerning graph connectivity. If we make so, we get
that the above procedure runs in polynomial time (provided oracle access).
Remark 21 Most reader could think that using oracles (in algorithmics) is
bizarre. However, the reader must take into account that we are using the oracle
idea to indicate that, if we solve the remaining task, then we immediately gets
a polynomial time algorithm solving the original problem.
11
3 Graph Problems
We are becoming more and more algorithmically. Thus, it is good idea to
consider the following question: how can a graph G be encoded as the input-
data of an algorithm that runs on an electronic computer?
If you was born after the awakening of tactile technology, then you could be
tempted to think that the best way is to draw a graphical representation of the
structure on the computer screen. Nowadays, it is a possibility.
It is also possible to introduce a list with the names of the nodes, and a
second list constituted by all the unordered pairs of nodes that are edges of the
graph. Notice that the latter encoding is the encoding that directly emerges
from the de…nition of graph. However, neither the latter nor the former are
standard encodings for graphs.
Let G be a …nite graph with n nodes. Electronic computers are well suited
to deal with numerical objects. Thus, to begin with, we suppose that the set of
nodes is equal to f1; :::; ng :
Remark 22 From now on, if we are given a graph G with n nodes, we will
automatically suppose that the set of nodes is equal to f1; :::; ng.
We say that a variable is …nite, if and only if, it ranges over a …nite set.
Matrices are numerical objects that were introduced to describe the interactions
between pairs of …nite variables. Thus, matrices are well suited to describe
binary relations.
Suppose that G is equal to (f1; :::; ng ; E). We use the symbol MG to denote
the adjacency matrix of G: Matrix MG is the n n matrix de…ned by
1, if fi; jg 2 E
MG [i; j] =
0, otherwise
Remark 23 Notice that the size of MG is n2 , nevertheless we say that the size
of G is equal to n. We can do the latter because a running time function is
polynomial in n, if and only if, it is polynomial in n2 :
Matrix MG is used as the input data, notice that all the combinatorial
(structural) information about G can be extracted from it. Can we use the
matrix (algebraic) structure of MG to answer questions about G? Consider the
following problem
12
Problem: check if G is connected.
Notice that u and v are connected by a path, if and only if, there exists a
path of length 1 connecting them or there exists a path of length 2 connecting
them or... or there exists a path of length n 1 connecting them.
On the other hand, we have that MG [u; v] = 1, if and only if, there exists a
path of length 1 connecting nodes u and v: Thus, the adjacency matrix encodes
all the information regarding the existence of paths of length 1: Does there exist
a similar matrix encoding the existence of paths of length 1 or 2?
2
Exercise 25 Suppose that MG [u; v] = c, what is the quantity c?
A good answer to the above question contains the germ of an e¢ cient algo-
rithm for checking connectivity of graphs.
Exercise 27 You have to improve the above algorithm, that is: you have to de-
sign and analogous algorithm that runs in time O log (n) n3 (Hint: Use Fast
Exponentiation). How much can the former algorithm be improved? Investigate
about Strassen’s Conjecture.
13
Input: (G; u; v), where G is a directed graph and u; v 2 V (G) :
Problem: compute a shortest path connecting those two nodes.
The latter exercise allows us to develop an algorithm that solves the above
problem. Consider the following algorithm.
The algorithm works, on input (G; u; v), as follows.
2 n 1
1. Compute the matrices MG ; MG ; :::; MG : Compute kmin; which is the
minimum i such that
i
M (G) [u; v] 6= 0:
2. The shortest paths connecting the nodes u and v have length kmin : We use
backtracking to construct a path of length kmin , to this end we proceed as
follows:
Edge (xkmin ; v) is the last edge of the path that we want to construct.
(b) Compute a neighbor of xkmin , say xkmin 1, such that
kmin 2
MG [u; xkmin 1] 6= 0:
Remark 30 The weights of the edges, that were set to 1, are supposed to rep-
resent the average time that is employed by a vehicle when crossing those edges
(streets). It is very unrealistic to suppose that all the streets require the same
amount of time to be crossed.
14
An application like Waze assigns to each street a weight, and this weight is
computed taking into account the statistics that are computed by the applica-
tion (using the information that can be retrieved from the interaction with the
wazers that are on the road). Thus, those weights are assigned dynamically.
However, when a wazer makes a query, asking for the shortest path connecting
two nodes, the application computes this path on the weighted graph that was
constructed just before the query. Thus, it can be said that the algorithmic
core of this application corresponds to an algorithm that e¢ ciently solves the
following problem:
We know that the adjacency matrix of G can be of big help, and we want
to use it once again. However, we have to use a di¤erent matrix, a matrix that
describes the whole structure included the weight function.
De…nition 33 Let (G; w) be a weighted directed graph, the adjacency matrix of
graph (G; w) is de…ned as follows
w (i; j) , if (i; j) 2 E (G) ;
MG [i; j] =
0, otherwise.
Let ((G; w) ; u; v) be an instance of our problem. We would like to use the
powers of MG , and backtracking, to construct the requested path. To do the
latter we will have to change, a little bit, the de…nition of matrix multiplication.
Given two matrices M and N , we use to compute the ij-entry of M N
as hFi (M ) j Cj (N )i ; where Fi (M ) is the i-th row of M and Cj (N ) is the j-
th column of N: To compute the inner product hFi (M ) j Cj (N )i we use the
sum and the multiplication of the ring (R; +; ). We could use any other ring
with universe R. We could use, for instance, the tropical ring (R; min; +) (see
reference [1]). The tropical inner product of (a1 ; :::; an ) and (b1 ; :::; bn ) is de…ned
as
h(a1 ; :::; an ) j (b1 ; :::; bn )iT = min fa1 + b1 ; :::; an + bn g ;
and the tropical matrix product of M and N is de…ned as
M T N = hFi (M ) j Cj (N )iT i;j n
:
T (m) T (m)
Exercise 34 Let MG be the m-th tropical power of MG , prove that MG [u; v]
is equal to the length of the shortest path with m edges connecting the nodes u
and v: Use the latter to develop a polynomial time algorithm solving the shortest
path problem (with weights).
Exercise 35 Investigate about the tropical ring and tropical geometry.
15
References
[1] M. Gross. Tropical geometry and mirror symmetry. Providence, R.I.: Pub-
lished for the Conference Board of the Mathematical Sciences by the Amer-
ican Mathematical Society with support from the National Science Founda-
tion, 2010
16
4 Trees
De…nition 36 A tree is a graph G; such that for any pair of its nodes there
exists exactly one simple path in G connecting those two nodes.
Exercise 39 A graph with n nodes is a tree, if and only if, it is connected and
it has exactly n 1 edges.
The above theorem encodes a non-trivial theorem about trees. It also en-
codes an e¢ cient algorithm for the recognition of trees.
Now that we know how to recognize trees e¢ ciently, we are ready to cope
with the corresponding construction problem.
Notice that G has spanning subtrees, if and only if, G is connected. Consider
the following problem:
17
Input: G, where G is a connected graph.
Problem: construct a spanning subtree of G:
It is not hard to solve the above problem. The basic idea is the following
one:
If the number of edges is larger than n 1; then delete one edge whose
omission does not destroy the connectivity of the graph. Continue in this way
until the set of edges is reduced to n 1 edges.
Trees have many nice properties. We have, for instance, that all those graphs
can be easily traversed. There exists a conventional way of traversing trees,
which is very economical from the point of view of the total traversing length.
Let G be an Eulerian graph with m edges. One can traverse graph G in
time m if he computes (…rst) an Eulerian trail of G: It is clear that it is the
optimal traversing time for a graph with m edges. However, most graphs are
not Eulerian.
Exercise 44 Most trees are not Eulerian. Characterize the trees that are Eulerian.
It is also true that most graphs are not trees. However, any interesting
(connected) graph contains at least one spanning subtree. Thus, if one has
to visit the n nodes of a certain connected graph, he can compute a spanning
subtree of it, and then he can navigate the computed subtree. If he proceeds in
this way, he will be able to guarantee that all the nodes of the original graph
are visited (we say that the graph is navigated or searched). Moreover, we have
that the navigation time is bounded above by 2n 3: To achieve this navigation
time, it su¢ ces if one navigates the spanning subtree using the so called depth
…rst search procedure (see below).
De…nition 45 Given a node v, we say that the pair (T; v) is a rooted tree.
Given the rooted tree (T; v) and given two nodes a and b, we say that a is the
mother of b, if and only if, given the unique path in T connecting v and a, the
sequence fa; bg is the unique path in T connecting v and b (and in this case
we say that b is a child of a).
Let T be a tree with n nodes. One can choose any node of T , say v, as
the root, and use this root to label the nodes of T according to the following
procedure:
Assign to v the label : If label wa has been assigned to node a; and b1 ; :::; bn
are the children of a, then assign to bi the label wa i:
18
Notice that we have assigned to any node a of T a string wa 2 f1; :::; kg ,
where
k = max fdeg (a) : a 2 V (T )g :
Notice also that the label wa is a full description of the unique path con-
necting v and a: We can use this labeling to navigate the tree:
We begin at the root. When we reach a node a we do the following: we look
for the …rst children of a that we have not visited yet, and we go to this child,
if we have already visited all the childrens of a we go to the mother of a:
The above navigation (search) procedure is the so called Depth First Search
Algorithm (DFS, for short).
Exercise 47 Let T be a tree with n nodes, prove that the navigation time of
DFS on T is bounded above by 2n 3:
The problem with the above algorithm is that, being it naive, its running
time is exponential in the size of the input graph. The latter fact follows from:
Exercise 48 Prove that there exists c > 1 such that for all n 2 there exists
a graph with n nodes that contains cn di¤ erent spanning subtrees.
Conclusion 49 Can you …gure out a sampling algorithm for spanning subtrees?
19
There exists a sixth (and last?) type of graph problems, the listing problems.
Given a graph property ; the listing problem related to consists in, given a
graph G, listing all the subgraphs of G for which property holds. Notice that
for most graph properties their corresponding listing problems require exponen-
tial time (why?). Therefore, when analyzing listing problems we have to use a
di¤erent and more ‡exible notion of feasible computations. The standard in the
…eld is the notion of polynomial delay time (see [1] and the references therein)
References
[1] L. Goldberg. E¢ cient Algorithms for Listing Combinatorial Structures.
Cambridge University Press, Cambridge UK 1993.
20