Академический Документы
Профессиональный Документы
Культура Документы
Graph Theory I
Valeria Fionda
KRDB Research Group
Faculty of Computer Science
Free University of Bozen-Bolzano
(Partially based on slides by Y. Peng)
Advanced Algorithms
1 / 30
Introduction
Introduction
Graph Theory was born in 1736 with Eulers paper on konigsberg
bridge problem.
Advanced Algorithms
2 / 30
Introduction
Introduction
Advanced Algorithms
3 / 30
Introduction
Introduction
After more than 100 years, a particular class of graphs, trees, was
introduced by Kirchhoff that developed a theory for electrical
networks and by Caylay in theoretical chemistry.
The term graph was introduced by Sylvester in a paper published in
1878.
The first book on graph theory was published in 1936 by Konig.
One of the most famous and productive problems of graph theory is
the four color problem, proposed in 1852:
Is it true that any map may have its regions coloured with four colors,
in such a way that any two regions having a common border have
different colors?
Many incorrect proofs have been proposed. It remained unsolved for
more than a century, when in 1969 Heinrich Heesch published a
method for solving the problem using computers.
Valeria Fionda (KRDB-FUB)
Advanced Algorithms
4 / 30
Graph representations
Introduction
Advanced Algorithms
5 / 30
Graph representations
Adjacency matrix
Let G = (V , E ) such that V = {v1 , ..., vn } and |V | = n, the
adjacency matrix is a nxn matrix each element of which is:
aij =
Cons:
The matrix requires O(n2 ) space, which is wasteful if the graph does
not have very many edges.
Advanced Algorithms
6 / 30
Graph representations
4
6
1
2
3
4
5
6
Valeria Fionda (KRDB-FUB)
1
0
1
1
1
0
0
2
1
0
0
0
1
0
3
1
0
0
1
1
1
4
1
0
1
0
0
0
Advanced Algorithms
5
0
1
1
0
0
0
6
0
0
1
0
0
0
7 / 30
Graph representations
Adjacency list
Cons:
Checking for a particular edge (u, v ) is no longer constant time,
because it requires sifting through us adjacency list.
Advanced Algorithms
8 / 30
Graph representations
4
6
1=
2=
3=
4=
5=
6=
Valeria Fionda (KRDB-FUB)
{2, 3, 4}
{1, 5}
{1, 4, 5, 6}
{1, 3}
{2, 3}
{3}
Advanced Algorithms
9 / 30
Graph representations
Advanced Algorithms
10 / 30
Connectivity
Connectivity
Advanced Algorithms
11 / 30
Connectivity
Connectivity
Advanced Algorithms
12 / 30
Connectivity
Connectivity
Example: Are the following graphs connected?.
Advanced Algorithms
13 / 30
Connectivity
Connectivity
Example: Are the following graphs connected?.
Advanced Algorithms
13 / 30
Connectivity
Connectivity
Example: Are the following graphs connected?.
Advanced Algorithms
13 / 30
Connectivity
Connectivity
Example: Are the following graphs connected?.
Advanced Algorithms
13 / 30
Connectivity
Connectivity
Advanced Algorithms
14 / 30
Connectivity
Connectivity
Advanced Algorithms
15 / 30
Connectivity
Connectivity
Advanced Algorithms
16 / 30
Connectivity
Connectivity
Example: Are the following directed graphs strongly or weakly
connected?
Advanced Algorithms
17 / 30
Connectivity
Connectivity
Example: Are the following directed graphs strongly or weakly
connected?
Strongly connected, because there are paths between all possible pairs
of vertices.
Valeria Fionda (KRDB-FUB)
Advanced Algorithms
17 / 30
Connectivity
Connectivity
Advanced Algorithms
18 / 30
Connectivity
Cut set
Advanced Algorithms
19 / 30
Connectivity
Advanced Algorithms
20 / 30
Connectivity
Connectivity
Advanced Algorithms
21 / 30
Connectivity
Connectivity
Example: In the star network the center vertex is a cut vertex. All
edges are cut edges.
Advanced Algorithms
22 / 30
Connectivity
Connectivity
Example: In the graphs G1 and G2 every edge is a cut edge. In the
union, no edge is a cut edge. Vertex e is a cut vertex in all graphs.
Advanced Algorithms
23 / 30
Connectivity
Complete graphs
The graphs for which k(G ) = |VG | 1 are said to be complete.
A complete graph is a graph in which every pair of distinct vertices is
connected by a unique edge.
The complete graph on n vertices has n(n 1)/2 edges and is
denoted by Kn
Advanced Algorithms
24 / 30
Connectivity
Connectivity
Advanced Algorithms
25 / 30
Euler Graph
Euler Graph
Euler Graph: If we can find a path (resp., circuit) in a graph that
involves all the edges of the graph, this path(resp., circuit) is called
an Eulerian path (resp., Eulerian circuit).
A graph having an eulerian circuit is called eulerian graph.
A connected graph G is an Eulerian graph iff all vertices in G have
even degree.
For the existence of Eulerian path it is necessary that no more than
two vertices have an odd degree.
If there are no vertices of odd degree, all Eulerian paths are circuits.
If there are exactly two vertices of odd degree, all Eulerian path starts
at one of them and end at the other.
Advanced Algorithms
26 / 30
Euler Graph
Fleurys algorithm
start with a vertex of odd degree (if the graph has none, start with any
vertex);
at each step we move across an edge whose deletion would not
disconnect the graph, unless we have no choice, then we delete that
edge.
at the end of the algorithm there are no edges left, and the sequence of
edges we moved across forms a Eulerian cycle if the graph has no
vertices of odd degree; or a Eulerian path if there are exactly two
vertices of odd degree.
Advanced Algorithms
27 / 30
Euler Graph
Fleurys algorithm
4
6
Advanced Algorithms
28 / 30
Euler Graph
Fleurys algorithm
4
6
Solutions:
(1, 2), (2, 5), (5, 3), (3, 4), (4, 1), (1, 3), (3, 6);
(1, 3), (3, 5), (5, 2), (2, 1), (1, 4), (4, 3), (3, 6);
(1, 3), (3, 4), (4, 1), (1, 2), (2, 5), (5, 3), (3, 6);
(6, 3), (3, 4), (4, 1), (1, 2), (2, 5), (5, 3), (3, 1);
...;
Valeria Fionda (KRDB-FUB)
Advanced Algorithms
28 / 30
Euler Graph
Hierholzers algorithm
Choose any starting vertex v, and follow a path of edges from v until
returning to v.
Note that it is not possible to get stuck at any vertex other than v,
because the even degree of all vertices ensures that, when the path
enters another vertex w there must be an unused edge leaving w.
The tour formed in this way is a closed tour, but may not cover all the
vertices and edges of the initial graph.
As long as there exists a vertex v that belongs to the current tour but
that has adjacent edges not part of the tour, start another path from v,
following unused edges until returning to v, and join the tour formed in
this way to the previous tour.
Advanced Algorithms
29 / 30
Euler Graph
Hierholzers algorithm
4
6
Advanced Algorithms
30 / 30
Euler Graph
Hierholzers algorithm
4
6
Solutions:
1 = (3, 5), (5, 2), (2, 1), (1, 4), (4, 3); 2 = (3, 1), (1, 5), (5, 6), (6, 3);
1 = (1, 3), (3, 5), (5, 2), (2, 1); 2 = (1, 4), (4, 3), (3, 6), (6, 5), (5, 1);
1 = (1, 3), (3, 5), (5, 1); 2 = (1, 4), (4, 3), (3, 6), (6, 5), (5, 1);
1 = (5, 6), (6, 3), (3, 5); 2 = (5, 2), (2, 1), (1, 5); 3 =
(1, 4), (4, 3), (3, 1);
Valeria Fionda (KRDB-FUB)
Advanced Algorithms
30 / 30