Chapter 4 Applications of Graph Theory
Chapter 4 Applications of Graph Theory
c
Continued…
A Euler Trails is a
snowplow problem
where a snow plow
needs to plow every
street once.
Start and finish
Euler circuits is a
Trails that ends at the
same vertex it started
# of ODD Vertices Implication (for a connected graph)
0 There is at least one Euler Circuit.
1 THIS IS IMPOSSIBLE! Can’t be drawn
2 There is no Euler Circuit but at least 1 Euler Trails.
Ex.
a b c
There is a Hamilton path, but no
Hamilton cycle.
d e f
g h
i
Hamilton Paths and Cycles
Example
x start labeling from here
y
x x
• Properties:
o There is a unique simple path between any 2
of its vertices.
o No loops.
o No multiple edges.
Example 1
●a
●b
c● ●d
e● ●f
a b
d
c
e
f
f g
e
y
Example
b c
d e f g Binary tree
Full binary tree
4.3. Planar Graphs
K4
K5
K4,4
v=4,e=6,r=4, v-e+r=2
R3
number number
of vertices number of regions
of edges
4.4. Graph Coloring
Def. If G=(V,E) is an undirected graph, a proper coloring of G occurs when we color
the vertices of G so that if ab is an edge in G, then a and b are colored with
different colors.
The minimum number of colors needed to properly color G is called
the chromatic number of G and is written (G).
a
3 colors are needed.
e a: Red
b b: Green (Kn)=n
c: Red
d: Blue (bipartite graph)=2
e: Red
d
c
4.5. Directed Graphs
• Definition:- A directed graph G or digraph (or simply graph) consists of two
things:
a) A set V whose elements are called vertices, nodes, or points.
b) A set E of ordered pairs (u, v) of vertices called arcs or directed edges or simply
edges.
• Suppose e = (u, v) is a directed edge in a digraph G. Then the following
terminology is used:
u e v
vV
2 vV
• Note that the degree of a node is unchanged by
whether we consider its edges to be directed or
undirected.
Subgraphs of a Digraph
• A subgraph of a graph G=(V,E) is a graph
H=(U,F) where UV and FE.
• H1, H2 are subgraph of G and H3 is not a
subgraph of G
Paths and Connectivity in Directed Graphs
Let G be a directed graph.
1. A (directed) walk P in G is an alternating sequence of
vertices and directed edges, say, P = (v0, e1, v1, e2, v2, … ,
en, vn) such that each edge ei begins at vi−1 and ends at vi . If
there is no ambiguity, we denote P by its sequence of
vertices or its sequence of edges.
2. A path is a walk with distinct vertices.
3. A trail is a path with distinct edges.
4. The length of the path P is n, its number of edges.
5. A closed path has the same first and last vertices.
6. A spanning path contains all the vertices of G.
7. A cycle (or circuit) is a closed path with distinct vertices
Connectivity in Directed Graphs
• There are three types of connectivity in a directed
graph G:
1. G is strongly connected or strong if, for any pair of vertices
u and v in G, there is a path from u to v and a path from v
to u, that is, each is reachable from the other.
2. G is unilaterally connected or unilateral if, for any pair of
vertices u and v in G, there is a path from u to v or a path
from v to u, that is, one of them is reachable from the
other.
3. G is weakly connected or weak if there is a semi-path
between any pair of vertices u and v in G. Let G’ be the
(non-directed) graph obtained from a directed graph G by
allowing all edges in G to be non-directed. Clearly, G is
weakly connected if and only if the graph G’ is connected.
Directed Connectedness
Real
Tree
L23 33
Trees
A very important type of graph in CS is called a
tree:
Real
Tree transformation
L23 34
Trees
A very important type of graph in CS is called a
tree:
Real
Tree transformation
L23 35
Trees
A very important type of graph in CS is called a
tree:
Real
Abstract transformation
Tree
L23
Tree36
Trees and Spanning Trees
• Connected graph without cycles is called a tree
• Any tree with more than one vertex has at least one
vertex of degree 1.
• Any tree with n vertices has n – 1 edges.
• If a connected graph with n vertices has n – 1 edges,
then it is a tree.
Brinleigh 5 Cornwell
3
6 4
8
8
Avonford Fingley Donster
7
5
4 2
Edan
We model the situation as a network, then the problem
is to find the minimum connector for the network
B 5 C
3
6 4
8
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
List the edges in
order of size:
B 5 C ED 2
AB 3
3 AE 4
4
8 6 CD 4
BC 5
8 EF 5
A F D CF 6
7 AF 7
5 BF 8
4 CF 8
2
E
Kruskal’s Algorithm
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4 (or AE 4)
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8
A F D
7
5
4 2
E
Kruskal’s Algorithm
Select the next shortest
edge which does not
B 5 C
create a cycle
ED 2
3 AB 3
4
8 6 CD 4
AE 4
8 BC 5 – forms a cycle
A F D EF 5
7
5
4 2
E
Kruskal’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 ED 2
4
8 6 AB 3
CD 4
8 AE 4
A F D EF 5
7
5
4 Total weight of tree: 18
2
E
Prim’s Algorithm
Select any vertex
B 5 C
A
8 AB 3
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 AE 4
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 ED 2
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 DC 4
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
Select the shortest
edge connected to
B 5 C
any vertex already
connected.
3 EF 5
4
8 6
8
A F D
7
5
4 2
E
Prim’s Algorithm
All vertices have been
connected.
B 5 C The solution is
3 AB 3
4
8 6 AE 4
ED 2
8 DC 4
A F D EF 5
7
5
4 Total weight of tree: 18
2
E
Some points to note
b 2 c
2 4 1
2 3
d e z
a
4
1 3 7
6
f 5 g
b 2 c
2 4 1
2 3
d e z
a
4
1 3 7
6
f 5 g
continued
Initialisation
= temporary
Inf score
b 2 c Inf
2 4 1
2 3
0 Inf
d e Inf z Inf
a
4
1 3 7
6
f 5 g Inf
Inf
continued
First Iteration = permanent
score
2 = changed
b 2 c Inf
temporary
2 4 1
2 3
0
Inf
d e Inf z Inf
a
4
1 3 7
6
f 5 g Inf
1
continued
Second Iteration
2
b 2 c Inf
2 4 1
2 3
0
4
d e Inf z Inf
a
4
1 3 7
6
f 5 g 6
1
continued
Third Iteration
2
b 2 c 4
2 4 1
2 3
0
4
d e 6 z Inf
a
4
1 3 7
6
f 5 g 6
1
continued
Fourth Iteration
2 4
b 2 c
2 4 1
2 3
0
4
d e 6 z 5
a
4
1 3 7
6
f 5 g 6
1 Could have chosen
‘d’ instead.
continued
Fifth Iteration
2 4
b 2 c
2 4 1
2 3
0 4
d e 6 z 5
a
4
1 3 7
6
f 5 g 6
1 Choosing ‘d’ is a
waste of time.
continued
Sixth (and final) Iteration
2 4
b 2 c
2 4 1
2 3
0 4
d e 6 z 5
a
4
1 3 7
6
Finished!
f 5 g 6 Shortest path
1 from ‘a’ to
‘z’ is length 5.
Exercise:- Using Dijkstra’s Algorithm to Find a
Shortest Path from a to z.
End of Chapter 4