0% found this document useful (0 votes)
12 views

Chapter 4 Applications of Graph Theory

Chapter Four discusses the application of graph theory, focusing on Eulerian and Hamiltonian graphs, trees, forests, planar graphs, graph coloring, directed graphs, and weighted graphs. It explains the conditions for Euler circuits and trails, Hamilton paths and cycles, and the properties of trees and forests. Additionally, it covers spanning trees, minimal spanning trees, and algorithms like Kruskal's and Prim's for finding minimum spanning trees.

Uploaded by

kalkidanasdro11
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Chapter 4 Applications of Graph Theory

Chapter Four discusses the application of graph theory, focusing on Eulerian and Hamiltonian graphs, trees, forests, planar graphs, graph coloring, directed graphs, and weighted graphs. It explains the conditions for Euler circuits and trails, Hamilton paths and cycles, and the properties of trees and forests. Additionally, it covers spanning trees, minimal spanning trees, and algorithms like Kruskal's and Prim's for finding minimum spanning trees.

Uploaded by

kalkidanasdro11
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 71

Chapter Four

Application of graph Theory


4.1. Eulerian and Hamiltonian Graphs
1. Eulerian Graphs
Euler Trails and Circuits
Corollary: The number of vertices of odd degree must be even.

Def. Let G=(V,E) be an undirected graph or multigraph with no isolated vertices.


Then G is said to have an Euler circuit if there is a circuit in G that traverses
every edge of the graph exactly once.
If there is an open trail from a to b in G and this trail traverses each edge in G
exactly once, the trail is called an Euler trail.

Theorem:- Let G=(V,E) be an undirected graph or multigraph with no isolated vertices.


Then G has an Euler circuit if and only if
G is connected and every vertex in G has even degree.
a

All degrees are odd. Hence no Euler circuit


b d for the Konigsberg bridges problem.

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.

more than 2 There are no Euler Circuits or Euler Trails.


2. Hamilton Graphs
Hamilton Paths and Cycles a path or cycle that contain every vertex
Unlike Euler circuit, there is no known
necessary and sufficient condition for a
graph to be Hamiltonian.

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

4x's and 6y's, since x and y must


y y y interleave in a Hamilton path (or cycle),
x y the graph is not Hamiltonian

y
x x

The method works only for bipartite graphs.

The Hamilton path problem is still NP-complete when restricted


to bipartite graphs.
4.2. Trees and Forest

• A tree is a connected simple undirected graph


with no simple circuits.

• 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

G1 : This graph is a Tree because it is a connected


graph with no simple circuits
Example 2

a b

d
c

e
f

G2: is not a tree “ because there is a cycle a, b, e, d, a”


Example 3

b G3: is not a tree “because


a
it’s not connected”. In this
case it’s called forest in
c d which each connected
component is a tree.
Component 1: a, f
e f Component 2: c, e, b, d
Forest

• An undirected graph without simple circuits is


called a forest.

– You can think of it as a set of trees having disjoint


sets of nodes.
Rooted (Directed) Trees

• A rooted tree is a tree in which one node has


been designated the root and every edge is
directed away from the root.
• A binary tree is a rooted tree if every internal
vertex has at most two children
• A binary tree is a rooted tree if every internal
vertex has exactly two children
Definitions

[Node a is the root]


a

• Root: Vertex with in-degree 0


b d
c

f g
e
y
Example

b c

d e f g Binary tree
Full binary tree
4.3. Planar Graphs

Def. A graph (or multigraph) G is called planar if G can be drawn in the


plane with its edges intersecting only at vertices of G. Such a drawing of G
is called an embedding of G in the plane.

Example: K1,K2,K3,K4 are planar, Kn for n>4 are nonplanar.

K4
K5

applications: VLSI routing, plumbing,...


Continued…

Def. Bipartite graph and complete bipartite graphs (Km,n)

K4,4

K3,3 is not planar.


Therefore, any graph containing K5
or K4,4 is nonplanar.
Continued…
Planar Graphs

A planar graph divides the plane


R1 into several regions (faces), one
K4 R4 of them is the infinite region.
R2

v=4,e=6,r=4, v-e+r=2
R3

Theorem (Euler's planar graph theorem)

For a connected planar graph or multigraph:


v-e+r=2

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

a) e begins at u and ends at v.


b) u is the origin or initial point of e, and v is the destination or terminal point of e.
c) v is a successor of u.
d) u is adjacent to v, and v is adjacent from u.
If u= v, then e is called a loop. The set of all successors of a vertex u is important; it is
denoted and formally defined by
succ(u) = {v ∈ V | there exists an edge (u, v) ∈ E}
Directed Graphs
The edges e2 and e3 are said to be parallel
since they both begin at B and end at A.
The edge e7 is a loop since it begins and ends
at B.
Edge Multiple Self-
Term type edges ok? loops ok?
Simple graph Undir. No No
Multigraph Undir. Yes No
Pseudograph Undir. Yes Yes
Directed graph Directed No Yes
Directed multigraph Directed Yes Yes

A vertex with degree 0 is called isolated.


A vertex of degree 1 is called pendant.
Corollary: Any undirected graph has an even number of vertices of
odd degree.
Directed Adjacency
• Let G be a directed (possibly multi-) graph, and
let e be an edge of G that is (or maps to) (u,v).
• Then we say:
– u is adjacent to v, v is adjacent from u
– e comes from u, e goes to v.
– e connects u to v, e goes from u to v
– the initial vertex of e is u
– the terminal vertex of e is v
Directed Degree
• Let D be a directed graph, v a vertex of D.
– The in-degree of v, deg(v), is the number of
edges going to v.
– The out-degree of v, deg(v), is the number
of edges coming from v.
– The degree of v(the degree of undirected
graph v), deg(v):deg(v) + deg(v), is the
sum of v’s in-degree and out-degree.
Directed Handshaking Theorem
• Let D be a directed (possibly multi-) graph with
vertex set V and edge set E.
• Then:
1

vV
deg (v)  deg (v)   deg(v)  E

vV

2 vV
• 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 UV and FE.
• 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

• A directed graph is strongly connected iff there is


a directed path from a to b for any two verts a
and b.
• It is weakly connected iff the underlying
undirected graph (i.e., with edge directions
removed) is connected.
• Note strongly implies weakly but not vice-versa.
Adjacency Matrix in Directed Graph
• Let G(V, E) be a simple directed graph, that is,
a graph without parallel edges.
• the adjacency matrix A = [𝑎𝑖𝑗 ] of G is the n × n
matrix defined as follows:
4.6. Weighted Graph
A weighted graph has values
(weights)assigned to its edges.
Trees
A very important type of graph in CS is called a
tree:

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.

• A subgraph T of a graph G is called a spanning tree


when T is a tree and contains all vertices of G.
• Every connected graph has a spanning tree.
• Any two spanning trees have the same number of
edges.
Spanning Trees
A spanning tree of a graph G is a tree that
touches every node of G and uses only
edges from G

Every connected graph has a spanning tree


Spanning Trees
• A minimal spanning tree (MST) is a spanning tree
with the least total weight of its edges

Finding Minimal Spanning Tree


• Kruskal’s algorithm
• Prim’s algorithm
Minimum spanning trees

Kruskal’s algorithm Prim’s algorithm

1. Select the shortest edge in a 1. Select any vertex


network
2. Select the shortest edge
2. Select the next shortest edge connected to that vertex
which does not create a cycle
3. Select the shortest edge
3. Repeat step 2 until all vertices connected to any vertex
have been connected already connected

4. Repeat step 3 until all


vertices have been
connected
Example

A cable company want to connect five villages to their network which


currently extends to the market town of Avonford. What is the minimum
length of cable needed?

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

Select the shortest


edge in the network
B 5 C
ED 2
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
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

Select the shortest


3 edge connected to
4
8 6 that vertex

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

•Both algorithms will always give solutions with the


same length.

•They will usually select edges in a different order –


you must show this in your workings.

•Occasionally they will use different edges – this


may happen when you have to choose between
edges with the same length. In this case there is
more than one minimum connector for the
network.
Exercises
1. If all edges in a graph have different weights,
does this graph have a unique MST?
2. Find the MST of the following graphs using
both algorithms
Example Weighted Graph

b 2 c

2 4 1
2 3

d e z
a
4
1 3 7
6
f 5 g

Problem: Find the shortest path from vertex a to vertex z.


Shortest Path Problem
 Finding the Shortest Path
• The length of a path = the sum of the
weights of the edges in the path
– w(i,j) = weight of edge (i,j)

• The shortest path between two verticies =


the path having the minimum length.
Edsger Wybe Dijkstra In 1997,
aged 67
Dijkstra’s Shortest Path Algorithm
• Assign scores to verticies:
– S(v) = score of vertex v (some integer)
– there are temporary and permanent scores
– all verticies start with a temporary score of infinity
(Inf)
• The algorithm uses a set T, which
contains all the nodes with temporary
scores
– initially that is all n nodes
• When the score of a vertex v is
made permanent, it is also the
length of the shortest path from
Processing the Example
Find a shortest path from a to z

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

You might also like