0% found this document useful (0 votes)
75 views20 pages

1 Euler, Hamilton and Five Classical Puzzles: August 23, 2019

This document discusses five classical puzzles related to graph theory: tiling puzzles, the three commodities problem, the four color theorem, Konigsberg's bridge problem, and Hamilton's icosian game. It explains how these puzzles can be modeled as graphs, which are mathematical structures used to represent relationships. Graphs abstract away details like a puzzle's geometric representation and focus only on its nodes and connecting edges. This abstraction allowed Hamilton to market his icosian game commercially by representing the dodecahedron graph on a planar board.

Uploaded by

JuanFonseca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views20 pages

1 Euler, Hamilton and Five Classical Puzzles: August 23, 2019

This document discusses five classical puzzles related to graph theory: tiling puzzles, the three commodities problem, the four color theorem, Konigsberg's bridge problem, and Hamilton's icosian game. It explains how these puzzles can be modeled as graphs, which are mathematical structures used to represent relationships. Graphs abstract away details like a puzzle's geometric representation and focus only on its nodes and connecting edges. This abstraction allowed Hamilton to market his icosian game commercially by representing the dodecahedron graph on a planar board.

Uploaded by

JuanFonseca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

August 23, 2019

1 Euler, Hamilton and Five Classical Puzzles


We begin with the study of …ve classical puzzles that are closely related to the
origin of graph theory.
Let us begin with a classical puzzle related to tilings.
The two-dimensional grid is the set Z Z R2 . A cell of the grid is a square
determined by the four points (n; m) ; (n + 1; m) ; (n + 1; m + 1) and (n; m + 1) :
A …nite grid is a connected set of cells. If the …nite grid G is constituted by all the
cells that are located between the four nodes (n; m) ; (n + k; m) ; (n + k; m + r)
and (n; m + r) ; then we say that G is a rectangular grid of length k and height
r: Suppose that G is a …nite grid, a tiling of G is a way of covering the whole
set of cells that constitute G by means of dominos. Dominos are shapes formed
by the union of two unit squares meeting edge-to-edge. Two conditions must
be satis…ed:

1. Dominos cannot intersect the complement of G.


2. Dominos cannot overlap.

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:

Problem 2 Counting Tilings

Input: (n; k), where n and k are integers.


Problem: compute the number of di¤ erent tilings of the rectangular grid
of length n and height k.

Thus, we are interested in counting tilings of rectangular grids.

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.

Exercise 4 Solve at least one of the above …ve puzzles.

1.1 The Underlying Structure: Graphs


Recall the last exercise of the previous section: solve at least one of the …ve
classical puzzles studied in the chapter. I have to suppose that most of the
readers solved the …fth problem (The Icosian Game). The …rst four problems
are hard, while Hamilton’s puzzle is very easy. Actually, it was the reason
behind the commercial failure of Hamilton’s toy.
How was the game commercially distributed? Perhaps the reader thinks
that the game consisted of a solid dodecahedron and a token that could be
moved along the edges of the dodecahedron. This is of course a possibility, but
you have to take into account that it is easier to distribute a planar object, as
for example a checkerboard. Actually, the puzzle was distributed commercially
as a pegboard with holes at the nodes of the dodecahedral graph. What is the

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.

Notice that Hamilton’s question asks if the dodecahedral graph is Hamil-


tonian, and it also asks for the construction of a Hamiltonian circuit in this
graph. Thus, we have represented Hamilton’s problem as a graph problem (as
an instance of a graph problem, the problem of recognizing the Hamiltonian
graphs). It happens that the remaining four puzzles can also be represented as
graph problems.
Let us begin with The Konisberg Problem. The city of Konisberg (Kalin-
ingrad) is crossed by a river (see the …gure below). There are two small islands
in the middle of the river. Island I1 is connected to each one of the two banks by
two bridges, while island I2 is connected to each bank by a single bridge. More-
over, both islands are connected by a single bridge. We have a total amount of
seven bridges (edges). The question is wether there exists a trial that crosses
each one of the seven bridges exactly once. Thus, we have seven bridges con-
necting di¤erent sections of the city. Bridges connecting city-sections are the
same as edges connecting nodes. Which are the nodes of Konisberg graph? We
have four nodes: the left bank LB, the right bank RB, island I1 and island I2 .
And we have seven edges, namely:

(LB; I1 ) ; (LB; I1 ) ; (RB; I1 ) ; (RB; I1 ) ; (LB; I2 ) ; (RB; I2 ) ; (I1 ; I2 ) :

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).

Notice that Konisberg Puzzle is equivalent to ask wether The Konisberg


Graph is Eulerian. Notice that, once again, we could represent one of our
puzzles as a problem about graphs.
Now, we consider The Three Commodities Problem.
We have a graph that represents the problem in a natural way. The graph
have six nodes: houses h1 ; h2 and h3 ; as well as factories C1; C2 and C3: The

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?

Exercise 12 Represent the remaining two puzzles as graph problems.

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

Problem 13 Recognizing Eulerian Graphs


Input: G; where G is a …nite graph.
Problem: decide if G is Eulerian.

The above problem admits a naive brute-force solution:


Let G be a graph with n nodes and m edges. The naive algorithm works,
on input G, as follows:

It constructs a list containing all the m-sequences of edges. A m-sequence


is a sequence
e1 ; :::; em
such that for all e 2 E there exists a single i m for which the equality
e = ei holds.

7
It checks if the constructed list contains a path in G:

It is easy to perform the …rst step of the computation. To do the latter, it


su¢ ces if one linearly orders the set of edges of G: Notice that any linear order
of E (G) determines a natural bijection between the set of m-sequences and the
set of permutations of f1; :::; mg :
It is also easy to perform the second step of the above procedure. Given a
m-sequence
e1 ; :::; em ;
checking if it is a path in G reduces to check if for all i m 1 the equality
jei \ ej j = 1 holds.
The soundness of the above algorithm relies on the following theorem

Theorem 14 A graph G is Eulerian, if and only if, at least one of its m-


sequences is 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.

Thus, the naive algorithm is an exponential time algorithm. Exponential


time algorithms are unfeasible, and it means that we have not solved the recog-
nition problem for Eulerian graphs.
Most graph problems admit naive brute-force solutions. Most of those so-
lutions are unfeasible c. And, on the other hand, e¢ cient solutions use to be
non-naive. Non-naive solutions are based on non-trivial theorems. The latter
means that, if we want to e¢ ciently solve the recognition problem for Eulerian
graphs, then we will have to look for non-trivial theorems relating the Eulerian
property with some other property that is very much easier to check.

De…nition 16 Let G be a graph, and let v be a node of G: The degree of v is


equal to jfe 2 E : v 2 egj :

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.

Theorem 18 A graph G is Eulerian, if and only if, it is connected and the


number of odd degree nodes is either zero or two.

Euler’s theorem is a recognition algorithm.

Exercise 19 Use Euler’s theorem to design an e¢ cient algorithm solving the


checking problem.

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:

Either u =6 v and fu ; v g is equal to the set of odd degree nodes of


graph (V ; E ) :
Or u = v and all the nodes in (V ; E ) have even degree.

The construction can be seen as a sequence of con…gurations, the initial


con…guration is C0 = (V; E; u; v) and given Ci = (Vi ; Ei ; ui ; vi ) the con…guration
Ci+1 is constructed from Ci in the following way:

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)

If we choose e without any care we get that the 4-tuple

Ce = (Vi+1 ; Ei+1 ; ui+1 ; vi+1 )

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:

Exercise 20 Let G be a graph, show that the number of odd-degree nodes in G


is an even number.

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

i0 = min fi n : (Yei ; Zn fei g) is connected g

4. If ei0 = fx; wg and x = s; set T = T fs; wg ; X = X + 1; Y = Yei0 ;


Z = Zn fei0 g ; x = w; y = y; and go back to steep three.

We observe that if X = m; the string T encodes an Eulerian trail of G: We


also notice that the procedure can be executed, provided that we know how

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

Matrix MG is a full description of the graph G; and it can be used as the


input-data describing G: Actually the function G 7! MG is the standard encod-
ing for graphs.

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

Problem 24 Checking Connectivity

Input: G, where G is a …nite graph.

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 26 Describe the above algorithm.

The main algorithmic step of the aforementioned procedure is the computa-


n 1
tion of MG n 1 . How fast can it be done? If one wants to compute MG ; he
2
can proceed naively: he computes MG MG , then he computes MG MG and
so on until the power n 1 is reached. If one proceeds in this way, he has to
compute n 2 matrix multiplications. The product of two n n matrices can
n 1
be computed in time O n3 . Altogether, matrix MG can be computed in
4
time O n : Thus, we can use the algebra of adjacency matrices to design an
e¢ cient solution to the connectivity problem.

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.

3.1 Algorithmic Tasks Behind Waze


The notion of graph is very versatile. The versatility of this notion allows us
to use it to model many di¤erent problems. Think in the road network of a
city, it is a graph whose nodes are the corners and whose edges are the streets
that connect pair of corners. Now think in an application like Waze. You are
located at a speci…c place in the city, and you want to compute the shortest
path from your actual location, denoted by u, to some other place in the city,
denoted by v: Let us suppose that u and v are corners, and let us assign to each
edge the same weight, say the weight 1: The shortest path connecting u and v is
the path with the smallest total weight. Thus, solving our navigation problem
is the same as solving the following graph problem:

Problem 28 Shortest Paths

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.

We know that the powers of MG can be of big help.


m
Exercise 29 Let a be equal to MG [i; j] ; prove that a is equal to the number of
paths of length m that connect nodes i and j:

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:

(a) Compute a neighbor of v, say xkmin , such that


kmin 1
MG [u; xkmin ] 6= 0:

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:

Edge (xkmin 1 ; xkmin ) is the next edge of our construction. We con-


tinue in this way until the edge fu; x2 g is added.

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.

Sometimes we need additional structure to correctly model a given problem.


This additional structure could come as a decoration (a function from the set
of nodes (edges) to some other set).

De…nition 31 A weighted graph is a pair (G; w), where G is a graph and w


is a function from E (G) to Q : Recall that Q denotes the set of non-negative
rationals. The length of a path on (G; w) is equal to the sum of the weights that
are assigned its edges.

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:

Problem 32 Shortest Path with Weights


Input: ((G; w) ; u; v), where (G; w) is a directed weighted graph and u; v 2
V (G) :
Problem: compute a shortest path connecting those two nodes.

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

Let us consider an algorithmic problem about graph-substructures that is related


to the notion of tree.

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.

Can we use the pure de…nition of tree to design a recognition algorithm?


With some e¤ort the reader can …gure out an algorithm for the recognition of
trees, and which is completely based on the previous de…nition. However, we
can say in advance that such an algorithm is a naive one, and that it is very
likely that it becomes unfeasible.
We have, by de…nition, that any tree is connected. We say that a graph is
acyclic, if and only if, there are not cycles included in G:

Exercise 37 Prove that any tree is acyclic.

We have, from the above exercise that

Theorem 38 A graph G is a tree, if and only if, it is connected and acyclic.

Now, we count with a non-trivial theorem characterizing trees. It could be


used to design a better recognition algorithm. However, we think that it is not
deep enough to be the basis of an e¢ cient algorithm.
Trees are, in some sense, minimal.

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.

Exercise 40 Design a polynomial time algorithm for the recognition of trees.


Estimate, as accurately as possible, the running time of your algorithm.

Now that we know how to recognize trees e¢ ciently, we are ready to cope
with the corresponding construction problem.

De…nition 41 Given G a graph with n nodes, and given H a subgraph of G;


we say that H is a spanning subtree of G, if and only if, H is a tree and it has
n nodes.

Notice that G has spanning subtrees, if and only if, G is connected. Consider
the following problem:

Problem 42 Construction of spanning subtrees

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.

Exercise 43 Write a detailed description of the above algorithm.

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:

Remark 46 The symbol denotes the empty string.

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:

There is a …fth category of algorithmic problems that we call sampling prob-


lems. Consider the problem of sampling uniformly at random the set of spanning
subtrees of G. An algorithmic solution to the latter problem is a procedure that
ful…lls the following condition:
If H is any of the k spanning subtrees of G, then H is the output of this
algorithm with a probability that is (almost) equal to k1 :
Notice that, once again, there is a naive solution to the sampling problem:

1. Construct a list of all the spanning subtrees of G:


2. Assign a linear order to the previously computed list, and compute the
length of the list.
3. Let k be the number computed in steep 2, choose uniformly at random a
number s 2 f1; :::; kg :
4. Output the s-th item of the ordered list computed in step 2:

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.

The task of constructing e¢ cient sampling algorithms use to be highly non-


trivial. The main di¢ culty being that the sample space use to be of exponential
size. Thus, the naive strategy (list the elements of the sample space, store them
into a black-bag, introduce a fair hand and pick one item from the bag) yields,
most of the time, exponential time algorithms.

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

You might also like