0% found this document useful (0 votes)
15 views60 pages

Chapter 8 Graphs

The document discusses different types of graphs and graph terminology. It defines graphs, simple graphs, multigraphs, pseudographs, directed graphs and mixed graphs. It also defines graph terminology like adjacent vertices, degree of a vertex, in-degree and out-degree of vertices in directed graphs. The document further discusses special types of graphs like regular graphs, complete graphs, cycles, wheels and bipartite graphs.

Uploaded by

jimsadnan
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)
15 views60 pages

Chapter 8 Graphs

The document discusses different types of graphs and graph terminology. It defines graphs, simple graphs, multigraphs, pseudographs, directed graphs and mixed graphs. It also defines graph terminology like adjacent vertices, degree of a vertex, in-degree and out-degree of vertices in directed graphs. The document further discusses special types of graphs like regular graphs, complete graphs, cycles, wheels and bipartite graphs.

Uploaded by

jimsadnan
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/ 60

Heaven’s light is our guide”

Rajshahi University of Engineering & Technology


Department of Computer Science & Engineering

Discrete Mathematics
Course No. : CSE 2101
Chapter 8: Graphs
Prepared By : Julia Rahman
8.1 Graphs and Graphs Models

Julia Rahman, Dept. CSE, RUET 02


8.1 Graphs and Graphs Models
DEFINITION 1(Graph):
 A graph G=(V,E)
 consists of:
 V , a nonempty set of vertices, points or nodes of G
 E , a set of edges of G
 Each edge has either one or two vertices associated with it, called
endpoints.
 An edge is said to connect its endpoints.
 Example:

v1 v5 G=(V, E), where


V={v1,v2,…, v7}
v3 v4 E={{v1,v2}, {v1,v3}, {v2,v3}
v6
{v3,v4}, {v4,v5}, {v4,v6}
{v4,v7}, {v5,v6}, {v6,v7}}
v2 v7
Julia Rahman, Dept. CSE, RUET 03
8.1 Graphs and Graphs Models
The set of vertices V of a graph G may be infinite. A graph with an infinite vertex
set is called an infinite graph.
A graph with a finite vertex set is called a finite graph.
Simple graph:
 Graph in which each edge connects two different vertices and
 No two edges connect the same pair of vertices.
Multi graph:
May have multiple edges connecting the same vertices.
Pseudo graph:
Like a multi graph, but edges connecting a node to itself are allowed.
Trivial graph:
The finite graph with one vertex and no edges that is a single point is called trivial
graph. Example:
v5
Undirected graphs:
Edges are not directed. v4
v6
Figure 2: Simple and undirected graph
Julia Rahman, Dept. CSE, RUET v7 04
8.1 Graphs and Graphs Models
v1 v5 i
h
v3 v4
v6 a
g
j
v2 Figure 3: Multi graph
v7
Figure 4: Pseudo graph
Directed graph:
 A directed graph (V,E) consists of a set of vertices V and a set of directed
edged E.
 Each directed edges is associated with an ordered pair of vertices.
 The directed edge associated with the ordered pair.

 is allowed in a directed graph


Mixed graph:
Graph with both directed and undirected edge.
Julia Rahman, Dept. CSE, RUET 05
8.1 Graphs and Graphs Models
Graph Terminology:
Type Edges Multiple Edges Loops
(simple) graph Undirected  
Multigraph edge: {u,v}  
Pseudograph  
Directed graph directed  
Directed multi graph edge: (u,v)  
Graph models:
1) Influence graph
2) Hollywood graph
3) Round robin tournaments
4) Call graph
5) The web graph
6) Roadmaps
Julia Rahman, Dept. CSE, RUET 06
8.2 Graph Terminology and
Special Types of Graphs

Julia Rahman, Dept. CSE, RUET 07


8.2 Graph Terminology and Special Types of Graphs
Definition – 1(adjacent):
 G = (v,e) : undirected graph
 if u --e-- v ==>
 u and v are adjacent (or neighbors)
 Edge e is incident with u (& v). v
 e connects u and v.
u e
 u and v are end points of e.
Definition – 2(degree):
 Let G be an undirected graph, v  V a vertex.
 The degree of v, deg(v), is its number of incident edges. (Except that any self-
loops are counted twice.)
 A vertex with degree 0 is isolated.
 A vertex of degree 1 is pendant.
b c
d

a e g
f
 In the figure deg(a) = 2, deg(b) = deg(c) = deg(f) = 4, deg(e) = 3, deg(d) = 1 and
deg(g) = 0. Julia Rahman, Dept. CSE, RUET 08
8.2 Graph Terminology and Special Types of Graphs
a b c

e d
In the figure deg(a)=4, deg(b)=6, deg(c)=1, deg(d)=5, deg(e)=6
Theorem 1:
Let G be an undirected (simple, multi-, or pseudo-) graph with vertex set V and
edge set E. Then

2e =deg ⁡( )
∈𝑉
 Note that this applies even if multiple edges and loops are present.
Example 3. How many edges are there in a graph with 10 vertices each of degree
six?
Solution: Because the sum of the degrees of the vertices is 6 · 1 0 = 60, it
follows that 2e = 60. Therefore, e = 30.
Julia Rahman, Dept. CSE, RUET 09
8.2 Graph Terminology and Special Types of Graphs
Theorem 2:
The number of vertices in a graph with odd degree is even.
Proof: and be the set of vertices of even degree and odd degree.
2e = = +
deg(v) is even for € V1, the first term in right-hand side of equality is even.
Hence the second term in the sum is also even. Because all the terms in this
sum are odd. Thus there are an even number of vertices of odd degree.
Definition-3:
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

Julia Rahman, Dept. CSE, RUET 10


8.2 Graph Terminology and Special Types of Graphs
Definition-4:
Let G be a directed graph, v a vertex of G.
 The in-degree of v, deg-(v), is the number of edges going to v or the
number of edges with as their terminal vertex.
 The out-degree of v, deg+(v) , is the number of edges coming from v or
the number of edges with as their initial vertex.
 The degree of v, deg(v) = deg-(v) + deg+(v) , is the sum of v’s in-degree
and out-degree.
Example 4: Find the in-degree and out-degree of each vertex in the graph G with
directed edges.
b
a c deg-(a)=2, deg+(a)=4
deg-(b)=2, deg+(b)=1
deg-(c)=3, deg+(c)=2
deg-(d)=2, deg+(d)=2
deg-(e)=3, deg+(e)=3
deg-(f )=0, deg+(f )=0
e d f
Julia Rahman, Dept. CSE, RUET 11
8.2 Graph Terminology and Special Types of Graphs
Theorem 3:
Let G = ( V , E) b e a graph with directed edges. Then
 deg
vV

(v )   deg 
(v )  E
vV
A simple graph G=(V, E) is called regular if every vertex of this graph has the
same degree. A regular graph is called n-regular if deg(v)=n , vV

is 3-regular.

Some Special Simple Graph


Complete Graph:
 The complete graph on n vertices, denoted by Kn, is the simple graph that
contains exactly one edge between each pair of distinct vertices.
 Kn is (n-1)-regular, |V(Kn)|=n, edge =

K1 K2 K3 K4
Julia Rahman, Dept. CSE, RUET 12
8.2 Graph Terminology and Special Types of Graphs
Cycles:
The cycle Cn, n3, consists of n vertices v1, v2, …, vn and edges {v1,v2}, {v2,v3},
…, {vn-1,vn}, {vn,v1}.

C6
C3 C4 C5
 Note Cn is 2-regular, |V(Cn)| = n, |E(Cn)| = n
Wheels:
For any n  3, a wheel Wn, is a simple graph obtained by taking the cycle Cn and
adding one extra vertex and n extra edges {{, }, {, },. . . . , { }}.

W3 W4 W5 W6

Julia Rahman, Dept. CSE, RUET 13


8.2 Graph Terminology and Special Types of Graphs
Bipartite Graphs:
A simple graph G=(V,E) is called bipartite if V can be partitioned into V1 and V2,
V1∩V2=, such that every edge in the graph connect a vertex in V1 and a vertex
in V2.
EXAMPLE 9:
v1 v2

v3 v4
C6
C6 is bipartite. Because
v5 v6

V1 V2
Example: Is C3 bipartite?
No, because there is no way to partition the vertices into two sets so that there
are no edges with both endpoints in the same set.

C3

Julia Rahman, Dept. CSE, RUET 14


8.2 Graph Terminology and Special Types of Graphs
EXAMPLE 11: Is the graph G bipartite?

a b a
c

g
c e
b

f
f d d
g
e

Julia Rahman, Dept. CSE, RUET 15


8.2 Graph Terminology and Special Types of Graphs
THEOREM 4:
A simple graph is bipartite if and only if it is possible to assign one of two
different colors to each vertex of the graph so that no two adjacent vertices are
assigned the same color.
Complete bipartite graph:
 The complete bipartite graph Km,n is the graph that has its vertex set
partitioned into two subsets of m and n vertices, respectively.
 Two vertices are connected if and only if they are in different subsets.

K3,2 K3,4

Julia Rahman, Dept. CSE, RUET 16


8.2 Graph Terminology and Special Types of Graphs
Definition 6:
A subgraph of a graph G=(V, E) is a graph H=(W, F) where W  V and F  E.
Example 14: A subgraph of K5

a a

e b e b

d c subgraph of K5 c
K5

Julia Rahman, Dept. CSE, RUET 17


8.2 Graph Terminology and Special Types of Graphs
Definition 7:
The union of two simple graphs G1=(V1, E1) and G2=(V2, E2) is the simple graph
G1∪G2=(V1∪V2, E1∪E2)
Example 15:
a b c a b c

G1 G2

d e d f
a b c

G1∪G2

d e f
Julia Rahman, Dept. CSE, RUET 18
8.3 Representing Graphs and
Graph Isomorphism

Julia Rahman, Dept. CSE, RUET 19


8.3 Representing Graphs and Graph Isomorphism
Adjacency list:
 A table with 1 row per vertex, listing its adjacent vertices.
 Which specify the vertices that are adjacent to each vertex of the graph.
 In directed graph listing the terminal nodes of each edge incident from that
node.
Example 1: Use adjacency lists to describe the simple graph given below.
b
Vertex Adjacent Vertices

a c a b,c,e
b a
c a,d,e
e d
d c,e
e a,c,d

Julia Rahman, Dept. CSE, RUET 20


8.3 Representing Graphs and Graph Isomorphism
Example 2: Represent the directed graph by listing all the vertices that are the
terminal vertices of edges starting at each vertex of the graph.
Initial vertex Terminal vertices
a b,c,d,e
b b,d
c a,c,e
d
e b,c,d

Adjacency Matrices:
 G=(V, E) : simple graph, V={v1,v2,…,vn}.
 A matrix A is called the adjacency matrix of G
if A=[aij]nn , where aij = 1, if {vi,vj}E,
0, otherwise.

Julia Rahman, Dept. CSE, RUET 21


8.3 Representing Graphs and Graph Isomorphism
Example 3: Use an adjacency matrix to represent the graph shown in Figure.
a b c d b d c a
a b a 0 1 1 1  b 0 1 1 1 
1 0 1 1 d 1 
b
A1    0 0 1
A2  c  
c 1 1 0 0 1 0 0 1
 
c d
d 1 1 0 0 a 1 1 1 0
Note:  
1. There are n! different adjacency matrices for a graph with n vertices.
2. The adjacency matrix of an undirected graph is symmetric.
Example 5: Use an adjacency matrix to represent the pseudograph.
b a b c d
a
a 0 3 0 2
b
3 0 1 1 
A 
c 0 1 1 2
d  
c d 2 1 2 0
Julia Rahman, Dept. CSE, RUET 22
8.3 Representing Graphs and Graph Isomorphism
Example 6:
If A=[aij] is the adjacency matrix for the directed graph, then
1 , if
aij = vi vj
0 , otherwise

Incidence Matrices:
 Let G = (V, E) be an undirected graph. The vertices and edges of G are listed
in arbitrary order as v1, v2, …, vn and e1, e2, …, em, respectively.
 The incidence matrix of G with respect to this listing of the vertices and
edges is the nm zero-one matrix with 1 as its (i, j) entry when edge ej is
incident with vi, and 0 otherwise.
1 , if edge ej is incident with vi
mij = 0 , otherwise
Example 6: Using
v2 an eincidence matrix, represent the following
e1 e2 e3 e4 eundirected
5 e6
v1 v
graph: 6 3 v1  1 1 0 0 0 0 
e 0
2
v2 0 1 1 0 1
e4  
e5 0 0 0 0 1 1
e1 e3 v3  
v4 1 0 1 0 0 0
v4 v5 Julia Rahman, Dept. CSE, RUET
0 1 0 1 1 0  23
v
8.3 Representing Graphs and Graph Isomorphism
Isomorphism of Graph
Definition 1:
The simple graphs G1 = (V1,E1) and G2 = (V2,E2) are isomorphic if there is a
one-to-one and onto function f from V1 to V2 with the property that a and b are
adjacent in G1 if and only if f(a) and f(b) are adjacent in G2, for all a and b in V1.
Such a function f is called an isomorphism.
Necessary condition for G1 = (V1,E1) to be isomorphic to G2 = (V2,E2):
 V1 = V2, and E1 = E2
 The number of vertices with degree n is the same in both graphs.
 For every proper subgraph g of one graph, there is a proper subgraph of the
other graph that is isomorphic to g..
Exampleu8: Show thatu2 the graphs vG1 = (V,E) and H =v2 (W,F) are isomorphic.
1

u3 u4 v3 H v4
G
Solution: The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, f(u4) = v2 is a one-to-one
correspondence between V and W. f(u1) = v1 and f(u2) = v4, f(u1) = v1 and f(u3) = v3,
f(u2) = v4 and f(u3) = v3, and f(u1) = vJulia
1 and f(uDept.
Rahman, 4) = v2 RUET
CSE, are adjacent in H. 24
8.3 Representing Graphs and Graph Isomorphism
Example 9: Show that G and H are not isomorphic.

G H

Solution: Both G and H have five vertices and six edges. However, H has a
vertex of degree one, namely, e , whereas G has no vertices of degree one. It
follows that G and H are not isomorphic .
Example 10: Determine whether G and H are isomorphic.
a b s t
w x
e
f
g z y
h
d c v u
Solution: G and H are not isomorphic. Because deg(a) = 2 in G, a must
correspond to either t, u , x , or y in H, because these are the vertices of degree
Julia Rahman, Dept. CSE, RUET 25
8.3 Representing Graphs and Graph Isomorphism
two in H . However, each of these four vertices in H is adjacent to another
vertex of degree two in H, which is not true for a in G.
Another way to see that G and H are not isomorphic is to note that the
subgraphs of G and H made up of vertices of degree three and the edges
connecting them must be isomorphic if these two graphs are isomorphic.
Example 11: Determine whether the graphs G and H are isomorphic.
G v1 H v3
u1 u2
u5 v2
u6
v6
u4 u3 v5
v4

Solution: f(u1)=v6, f(u2)=v3, f(u3)=v4, f(u4)=v5, f(u5)=v1, f(u6)=v2


Yes

Julia Rahman, Dept. CSE, RUET 26


8.3 Representing Graphs and Graph Isomorphism
Example: Determine whether the graphs G and H are isomorphic.

G H
u1 v1
u2 v8 v2
u8

u3 v3
u7 v7

u6 u4 v6 v4
u5 v5
Solution: Yes

Julia Rahman, Dept. CSE, RUET 27


8.4 Connectivity

Julia Rahman, Dept. CSE, RUET 28


8.4
Path: Connectivity
 A path is a sequence of edges that begins at a vertex of a graph and travels
from vertex to vertex along edges of the graph.
 Let n be a nonnegative integer and G an undirected graph.
 A path of length n from u to v in G is a sequence of n edges e1, e2, …, en of G
such that f(e1) = {x0, x1}, f(e2) = {x1, x2}, …, f(en) = {xn-1, xn}, where x0 = u
and xn = v.
 When graph is simple, path is denoted by its vertex sequence x0, x1, …, xn.
 The path is a circuit if it begins and ends at the same vertex, that is, if u = v,
and has length greater than zero.
 The path or circuit is said to pass through the vertices x1, x2, …, xn-1 or
traverse the edges e1, e2, …, en.
 A path or circuit is simple if it does not contain the same edge more than
once. v w
Example: path: u, v, y
u cycle: u, v, y, x, u

x y Julia Rahman, Dept. CSE, RUET 29


8.4
Connectedness: Connectivity
 An undirected graph is connected if and only if there is a path between
every pair of distinct vertices in the graph.
 Two computers in the network can communicate if and only if this network
is connected.
Example 5: The graph in Figure is connected, because for every pair of
distinct vertices there is a path between them (the reader should verify this).
However, the graph in Figure is not connected. For instance, there is no path in
between vertices a and d.

a b a b

f
c c

d d e

g e
𝐺2
𝐺1 Julia Rahman, Dept. CSE, RUET 30
8.4
Theorem 1: Connectivity
There is a simple path between every pair of distinct vertices of a connected
undirected graph.
Connected component: connected subgraph
Example 6: What are the connected components of the graph H?

𝐻1 𝐻2 f
b 𝐻3
d e
a c h g
H

Solution: The graph H is the union of three disjoint connected subgraphs , ,


and . These three subgraphs are the connected components of H .

Julia Rahman, Dept. CSE, RUET 31


8.4
Definition: Connectivity
 A cut vertex separates one connected component into several components if
it is removed.
 A cut edge separates one connected component into two components if it is
removed.
Example 8: Find the cut vertices and cut edges in the graph G.
a d f g
G
b c e h
Solution: cut vertices: b, c, e & cut edges: {a, b}, {c, e}
Definition 4:
A directed graph is strongly connected if there is a path from a to b for any two
vertices a, b.
Definition 5:
A directed graph is weakly connected if there is a path between every two
vertices in the underlying undirected graphs.
Julia Rahman, Dept. CSE, RUET 32
8.4
Connectivity
Example 9: Are the directed graphs G and H strongly connected or weakly
connected? a b a b

G c H c
e d e d
Solution: G is strongly connected because there is a path between any two
vertices in this directed graph. Hence, G is also weakly connected.
The graph H is not strongly connected. There is no directed path from a to b in
this graph. However, H is weakly connected, because there is a path between
any two vertices in the underlying undirected graph of H.
Example 6: What are the connected components of the graph H?

Solution: G and H are not isomorphic. Because deg(a) = 2 in G, a must


correspond to either t, u , x , or y in H, because these are the vertices of degree

Julia Rahman, Dept. CSE, RUET 33


8.4
Paths and Isomorphism: Connectivity
 Note that connectedness, and the existence of a circuit or simple circuit of
length k are graph invariants with respect to isomorphism.
 Paths and circuits can help determine whether 2 graphs are isometric
 The existence of a simple circuit (or cycle) of a particular length is a useful
invariant to show that 2 graphs are not isomorphic
Example 12: Determine whether the graph G and H are isomorphic.
u1 v1
u2 u6 v2 v6

u3 u5 v3 v5
G H v4
u4
Solution: Both G and H have 6 vertices and 8 edges. Each has 4 vertices of degree 3,
and 2 vertices of degree 2. However, H has a simple circuit of length 3, namely, v 1,
v2, v6, v1 whereas G has no simple circuit of length 3, as can be determined by
inspection (all simple circuits in G have length at least four). G and H are not
isomorphic. Julia Rahman, Dept. CSE, RUET 34
8.4
Connectivity
Example 13. Determine whether the graphs G and H are isomorphic.

u2 v1
G H
u1 u3 v5 v2
u5 u4 v4 v3
Solution: Both G and H have 5 vertices, 6 edges, two vertices of deg 3, three
vertices of deg 2, a 3-cycle, a 4-cycle, and a 5-cycle.  G and H may be
isomorphic.
The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, f(u4) = v2 and f(u5) = v5 is a one-
to-one correspondence between V(G) and V(H).  G and H are isomorphic.
Counting Paths between Vertices
Theorem 2:
Let G be a graph with adjacency matrix A with respect to the ordering v1, v2, …,
vn (with directed or undirected edges, with multiple edges and loops allowed).
The number of different paths of length r from vi to vj, where r is a positive
35
integer is equals to the (i, j)th entry of Ar.
8.4
Example 14: Connectivity
How many paths of length 4 are there from a to d in the simple
graph G? a b

G
d c
Solution: The adjacency matrix of G
a b c d
0
a 1 1 0 8 0 0 8
 0 0
b 1 0 0 1 8 8
A   A4  
0
8
c 1 0 0 1 8 8 0
   
d 0 1 1 0 8 0 0 8
there are exactly eight paths of length four from a to d. By inspection of the
graph, we see that a , b, a , b, d; a , b, a , c, d; a , b, d, b, d; a , b, d, c, d; a , c,
a , b, d; a , c, a , c, d; a , c, d, b, d; and a , c, d, c, d are the eight paths from a
to d. (ordering as a, b, c, d) is

Julia Rahman, Dept. CSE, RUET 36


8.5 Euler & Hamilton Paths

Julia Rahman, Dept. CSE, RUET 27


8.5 Euler & Hamilton Paths
The Seven Bridges of Konigsberg:
 In Konigsberg, Germany, a river ran through the city such that in its center
was an island, and after passing the island, the river broke into two parts.
Seven bridges were built so that the people of the city could get from one
part to another.
 Is it possible to walk through the city that would cross each bridge once and
only once?
c
C

D
a d
A

b
B Fig-2: multigraph model of the
Fig-a: the seven bridges of konigsberg town of konigsberg
Julia Rahman, Dept. CSE, RUET 38
8.5 Euler & Hamilton Paths
Definition 1:
 An Euler circuit in a graph G is a simple circuit containing every edge of G.
 An Euler path in G is a simple path containing every edge of G.
Example 1: Which of the following graphs have an Euler circuit or an Euler
path? a a b G3
a b b

G1 e G2 e

d c d c c d e

Solution: is Euler circuit, for example, a , e, c, d, e, b, a. and are not an Euler


circuit. However, has an Euler path, namely, a , c, d, e, b, d, a , b. does not
have an Euler path.
Necessary and sufficient conditions for Euler path and Euler circuit
Theorem 1: A connected multigraph has a Euler circuit if and only if each of its
vertices has an even degree.
Theorem 2: A connected multigraph has a Euler path but not an Euler circuit if and
only if it has exactly two vertices of odd degree.
Julia Rahman, Dept. CSE, RUET 39
8.5 Euler & Hamilton Paths
Definition 2:
 A Hamilton path is a path that traverses each vertex in a graph G exactly
once.
 A Hamilton circuit is a circuit that traverses each vertex in G exactly once.
Example 5: Which of the following graphs have a Hamilton circuit or a
Hamilton path? a b g
a b a b
G1 G2
e c
d c d c e f
d G3
Solution: has a Hamilton circuit: a , b, c, d, e, a . There is no Hamilton circuit
in(this can be seen by noting that any circuit containing every vertex must
contain the edge {a , b} twice), but does have a Hamilton path, namely, a , b, c,
d. has neither a Hamilton circuit nor a Hamilton path, because any path
containing all vertices must contain one of the edges {a, b}, {e, f}, and {c, d}
more than once.
Julia Rahman, Dept. CSE, RUET 40
8.5 Euler & Hamilton Paths
Theorem 3:
If (but not only if) G is a simple graph with n3 vertices such that the degree of
every vertex in G is at least n/2, then G has a Hamilton circuit.
Example: b a

g
c

f
d
e
each vertex has deg  n/2 =3.5
Hamilton circuit exists: a, c, e, g, b, d, f, a

Julia Rahman, Dept. CSE, RUET 41


8.5 Euler & Hamilton Paths
Theorem 4:
If G is a simple graph with n3 vertices such that deg(u)+deg(v)  n for every pair
of nonadjacent vertices u and v, then G has a Hamilton circuit.
Example: b a

g
c

f
d
e
each nonadjacent vertex pair has deg sum  n = 7
Hamilton circuit exists: a, d, f, e, c, b, g, a

Julia Rahman, Dept. CSE, RUET 42


8.6 Shortest-Path Problems

Julia Rahman, Dept. CSE, RUET 43


8.6 Shortest-Path Problems
Definition:
 Graphs that have a number assigned to each edge are called weighted
graphs.
 The length of a path in a weighted graph is the sum of the weights of the
edges of this path.
Shortest path Problem:
Determining the path of least sum of the weights between two vertices in a
weighted graph.
L=4 b
Example 1: What is the length of a shortest path between a and z in the weighted
c L=0 (2) a
graph
b G?3 (1) a L=2 (3) 4
2 Solution: 2
4 a
d
z 2
a 3
b b d
2 1
4 (5) 4 L=6
G d 3 e
(4) a z
a
2 L=5 2 1
d 3 e d 3 e
Julia Rahman, Dept. CSE, RUET length=6 44
8.6 Shortest-Path Problems
Dijkstra’s Algorithm: (find the length of a shortest path from a to z)
Procedure Dijkstra(G: weighted connected simple graph, with
all weights positive)
{G has vertices a = v0, v1, …, vn = z and weights w(vi, vj)
where w(vi, vj) =  if {vi, vj} is not an edge in G}
for i := 1 to n
L(vi) := 
L(a) := 0
S := 
while z  S
begin
u := a vertex not in S with L(u) minimal
S := S ∪ {u}
for all vertices v not in S
if L(u) + w(u, v) < L(v) then L(v) := L(u) + w(u, v)
end {L(z) = length of a shortest path from a to z}
Julia Rahman, Dept. CSE, RUET 45
8.6 Shortest-Path Problems
Example 2: Use Dijkstra’s algorithm to find the length of a shortest path
between a and z in the weighted graph.
b 5 d
4 6
8
a 1 z
2
2 3
Solution: c 10 e
3(c) 10(c)
  4(a
b 5 d b 5 d b 5 d
)
4 6 4 6 4 6
0 8 0 8 0 8
a 1 2
z  a 1 z  a 1 2
z
 2  
2 3 2 3 2 3
c  10 e c 10 e c 10 e
  2(a) 12(c)
2(a)

Julia Rahman, Dept. CSE, RUET 46


8.6 Shortest-Path Problems
3(c) 8(b) 3(c) 8(b)
3(c) 8(b)
b 5 d b 5 d b 5 d
4 6 4 6 4 6
0 8 0 8 14(d)
a 1 z  a0 8
z 14  1
a z
 2
2  1 2 (d)
2
3 2 3 2 3
c 10 e c 10 e c 10 e
2(a) 12(c) 2(a) 10(d) 2(a) 10(d)

3(c) 3(c) 8(b)


8(b)
b 5 d b 5 d
4 6 4 6
0 8 0 8
z 13(e)  a z 13(e)
 a 1 2
1 2
2 3 2 3
c 10 e c 10 e
2(a) 10(d) 2(a) 10(d)
 path: a, c, b, d, e, z
length: 13
Julia Rahman, Dept. CSE, RUET 47
8.6 Shortest-Path Problems
Theorem 1:
Dijkstra’s algorithm finds the length of a shortest path between two vertices in a
connected simple undirected weighted graph.
Theorem 2:
Dijkstra’s algorithm uses O(n2) operations (additions and comparisons) to find the
length of a shortest path between two vertices in a connected simple undirected
weighted graph with n vertices.
The Traveling Salesman Problem:
A traveling salesman wants to visit each of n cities exactly once and return to his
starting point. In which order should he visit these cities to travel the minimum
total distance?
Example (starting point D)
113 S
G 137
147 142 98
DTKGS D: 458
167 DTSGKD: 504
56 D
135 DTSKGD: 540
58
K 133 48
T Julia Rahman, Dept. CSE, RUET
8.7 Planar Graphs

Julia Rahman, Dept. CSE, RUET 49


8.7 Planar Graphs
Definition 1:
 A graph is called planar if it can be drawn in the plane without any edge
crossing.
 Such a drawing is called a planar representation of the graph.
Example 1: Is K4 planar?
Solution: K4 is planar because it can be drawn without crossings, as shown in
Figure

K4

Example 2: Is Q3 planar?
Solution: Q3 is planar, because it can be drawn without any edges crossing.

Q3
Julia Rahman, Dept. CSE, RUET 50
8.7 Planar Graphs
Example 3: Show that K3,3 is nonplanar.
a b c

d e f
Solution: Not possible to drawing without crossing.
a R1 e a e

R2 c
f
d b d b

Julia Rahman, Dept. CSE, RUET 51


8.7 Planar Graphs
Euler’s Formula:
A planar representation of a graph splits the plane into regions, including an
unbounded region.
Example: How many regions are there in the following graph?
R4
R2 R3
R1 R5

Solution: 6
Theorem 1: (Euler’s Formula)
Let G be a connected planar simple graph with e edges and v vertices. Let r be the
number of regions in a planar representation of G. Then r = e-v +2.
Example 4: Suppose that a connected planar graph has 20 vertices, each of degree
3. Into how many regions does a representation of this planar graph split the plane?
Solution: v = 20, 2e = 320 = 60, e = 30
r = e-v+2 = 30-20+2 = 12

Julia Rahman, Dept. CSE, RUET 52


8.7 Planar Graphs
Corollary 1:
If G is a connected planar simple graph with e edges and v vertices, where v  3,
then e  3v - 6.
Example 5: Show that K5 is nonplanar
Solution: v= 5, e = 10, but 3v - 6 = 9.
Corollary 2:
If G is a connected planar simple graph, then G has a vertex of degree  5.
Proof: Let G be a planar graph of v vertices and e edges.
If deg(v)  6 for every vV(G)
  deg( v )  6v
vV ( G )

 2e  6v  (e  3v - 6)
Corollary 3:
If a connected planar simple graph has e edges and v vertices with v  3 and no
circuits of length three, then e  2v - 4.

Julia Rahman, Dept. CSE, RUET 53


8.7 Planar Graphs
Example 6: Show that K3,3 is nonplanar by Cor. 3.
Solution: Because K3,3 has no circuits of length three, and v = 6, e = 9, but e = 9
> 2v - 4.
a b c

d e f
Kuratowski’s Theorem:
If a graph is planar, so will be any graph obtained by removing an edge {u, v} and
adding a new vertex w together with edges {u, w} and {v, w}.
u v

Such an operation is called an elementary subdivision.


Two graphs G1 = (V1, E1), G2=(V2, E2) are called homeomorphic if they can be
obtained from the same graph by a sequence of elementary subdivisons.

Julia Rahman, Dept. CSE, RUET 54


8.7 Planar Graphs
Example 7: Show that the graphs G1, G2, and G3 are all homeomorphic.
a b a b a b
h i k
f
j
g g
c d e c d e c d e
Solution: all three can be obtained from G1

Theorem 2: (Kuratowski Theorem)


A graph is nonplanar if and only if it contains a subgraph homeomorphic to K3,3 or
K5.

Julia Rahman, Dept. CSE, RUET 55


8.7 Planar Graphs
Example 9: Show that the Petersen graph is not planar.

Solution:
7

1 6
It is homeomorphic to K3,3.
5 8 1 2 3
2 3
8
4 9

9 7
4 5 6
Julia Rahman, Dept. CSE, RUET 56
8.8 Graph Coloring

Julia Rahman, Dept. CSE, RUET 57


8.8 Graph Coloring
Definition 1:
A coloring of a simple graph is the assignment of a color to each vertex of the
graph so that no two adjacent vertices are assigned the same color.
Example: 2 1 2 3

1 2 1 1
5
1
4 3 3 2
Definition 2:
The chromatic number of a graph is the least number of colors needed for a
coloring of this graph. (denoted by c(G))
Example 2: c(K5)=5
1 2

5 3
Note: c(Kn)=n
Julia Rahman, Dept. CSE, RUET 58
4
8.8 Graph Coloring
Example: c(K2,3) = 2.
1 1

2 2 2
Note: c(Km,n) = 2
Note: If G is a bipartite graph, c(G) = 2.
Example 1: What are the chromatic numbers of the graphs G and H?
2 3

1 1 1 a g

3 2 H
Solution: G has a 3-cycle Solution: any 3-coloring for
 c(G)3 H-{(a,g)} gives the same color to a and g
G has a 3-coloring  c(H)>3
 c(G)3 4-coloring exists  c(H)=4
 c(G)=3 Julia Rahman, Dept. CSE, RUET 59
8.8 Graph Coloring
Example 4: c(Cn) =
{ 2 if n is even,
3 if n is odd. 1 2

Cn is bipartite when n is even. 3 1

Theorem 1: (The Four Color Theorem)


The chromatic number of a planar graph is no greater than four.
Corollary:
Any graph with chromatic number > 4 is nonplanar.
Applications of graph coloring:
1) Scheduling final exam
2) Frequency assignment
3) Index registering

Julia Rahman, Dept. CSE, RUET 60

You might also like