Unit - V &VI Graph Theory
Unit - V &VI Graph Theory
Graph theory
Representation of Graphs
Graph G
(V, E, )
V Set of vertices
E Set of edges
Function that assigns vertices {v, w} to each edge
(e) = {v, w}
e Edge between vertices v and w
Example 1:
V = {1, 2, 3, 4}
E = {e1, e2, e3, e4, e5}
(e1) = {1, 2}
(e2) = {4, 3}
(e3) = {1, 3}
(e4) = {2, 4}
(e5) = {2, 1}
1 2
4 3
Degree of a vertex
No. of edges at a vertex
Loop
Edge from a vertex to itself
Degree is 2
Example 2:
1
2
3
4
Vertex Degree
1 3
2 3
3 4
4 2
Vertex with degree 0
Adjacent vertices
Pair of vertices that determine an edge
Path π in a graph G
Pair (Vπ , Eπ) of sequences
Vπ : v1, v2, … , vk Vertex sequence
Eπ: e1, e2, ..., ek – 1 Edge
sequence
Circuit
Path that begins and ends at the same vertex.
Simple path
No vertex appears more than once in the vertex
sequence
Simple circuit
v1 = vk
Connected graph
Path from any vertex to any other
vertex
Example:
Connected Graph
Disconnected graph
Not connected graph
Components of the graph
Various connected pieces in the disconnected graph
Example:
2 5
3 4
1 6
2
1
4
3
Adjacency Matrix representation for the graph G
1 2 3 4
1 0 1 1 0
2 1 0 01
3 0 0 0 1
4 0 0 00
A tree is a simple graph G such that there is a unique simple path
between each pair of vertices.
A rooted tree is a tree in which there is one designated vertex,
called a root.
A rooted tree is a directed tree if there is a root from which there is a
directed path to each vertex.
The level of a vertex v in a rooted tree is the length of the path to v
from the root.
A tree T with only one vertex is called a trivial tree; otherwise T is
nontrivial tree.
If a graph G is connected and e is an edge such that G-e is not
connected , then e is said to be a bridge or a cut edge. If v is a
vertex of G such that G-v is not connected ,then v is a cut vertex.
Theorems
A simple nondirected graph G is a tree iff G is connected and
contains no cycles.
In every nontrivial tree there is at least one vertex of degree 1.
A tree with n vertices has exactly n-1 edges.
If G is a nontrivial tree then G contains at least 2 vertices of degree
1.
If 2 nonadjacent vertices of a tree T are connected by adding an
edge , then the resulting graph will contain a cycle.
A graph G is a tree if and only if G has no cycles and |E| = |V| - 1.
In general, if G is a connected graph with n vertices and m edges, a
spanning tree of G must have n – 1 edges.
Hence, the number of edges must be removed before a spanning
tree is obtained must be m-(n-1)=m-n+1.
This number is frequently called the circuit rank of G.
Theorem: A nondirected graph G s connected if and only if G
contains a spanning tree. If we successively delete edges of cycles
until no further cycles remain, then the result s a spanning tree of G
Planar Graphs:
A planar graph is a graph G that can be drawn on a plane without
crossovers. Otherwise G is said to be non planar.
(or)
A graph which can be represented by at least on plane drawing in
which the edges meet only at the vertices
Plane Graph:
If a planar graph is drawn in the plane so that no two edges cross
over.
Note:
1. Order means no. of nodes in the graph.
2. Size means no. of edges in the graph
Exercises
1. Derive all possible spanning trees for the graph shown below.
2. Derive all possible spanning trees for the graph shown below
5. Find DFS and BFS spanning trees for the graph given below.
Q
A B P
D C S R
Fig: X Fig: Y
A ↔ P, B ↔ Q , C ↔ R , D ↔ S
Similarly one-to-one correspondence between the edges of the graphs X and y are
as follows:
{A,B} ↔ {P,Q},
{B,C} ↔ {Q,R},
{C,D} ↔ {R,S},
{D,A} ↔ {S,P},
{A,C} ↔ {P,R},
{B,D} ↔ {Q,S}
A A1
B C B1 C1
Fig: X Fig: Y
B C B1 C1
Fig: X Fig: Y
D C S R
Fig: X Fig: Y
A ↔ P, B ↔ R , C ↔ Q , D ↔ S
Similarly one-to-one correspondence between the edges of the graphs X and y are
as follows:
{A,C} ↔ {P,Q},
{B,C} ↔ {Q,R},
{B,D} ↔ {R,S},
{D,A} ↔ {S,P},
Null / Discrete graph
Nn
Graph with n vertices and no edges
Disconnected
Exactly n components.
Examples:
N2 N4
Complete graph
Kn
An edge {vi, vj} for every i and j
Every vertex is connected to every other
vertex
Euler Circuit and Euler Trails:
consider a graph G, and if there is a circuit in G that contains all the edges of
G, then that circuit is called Euler Circuit
(Circuit
Path that begins and ends at the same vertex.
in a circuit no edge can appear more than once but the vertex can appear
more than once)
Example:
A e4 B
e5
e1 e3
e7
C e2 D e6 E
if there is a trail in G that contains all the edges of G, then that trail is called
Euler trail.
e1 e4
e5
B C
e2 D e3
other.
3. If a graph G has more than two vertices of odd degree, then there can be
no Euler path in G.
The graph has exactly two vertices of odd degree.
Hence there is no Euler circuit, but there must be an Euler path.
A B
1)
C
E D
A B
C
E D
2) A B C
I K D
J
H G F E
A B C
I K D
J
H G F E
A
F B
E D C
F B
E D C
A
A
F B
F B
C
E C
E
D
D
Hamilton cycles and Hamilton paths:
1. Each vertex must be visited only once except the first (starting) for cycle
2. A Hamilton cycle in a graph of n vertices consists of exactly n edges
3. Hamilton cycle may not include all edges of a graph
A path in a connected graph which includes every vertex of the graph is called
Hamilton path.
A B
D C
In the above graph, the cycle is shown in thick lines is Hamilton cycle
A B
D C
In the above graph, the path shown in thick lines is Hamilton path
A B C
D E F
G I
H
In the above graph the Hamilton path is ABCFEDGHI. And there is no Hamilton
Cycle as shown below
A B C
E F
D
G I
H
Graph Coloring and Chromatic Numbers:
Graph coloring:
For a given graph G, if we assign colors to its vertices in such a way that no two
adjacent vertices have the same color, then the graph is called properly
colored graph.
Note:
1. A graph can have more than one proper coloring
2. Two non-adjacent vertices in a properly colored graph can have the same color
G B
B
R G R
B R R
G G Y
B B
R
The chromatic number of a graph is the minimum number of colors with which
the graph can be properly colored
OR
A rooted tree is a tree in which there is one designated vertex, called a root
A rooted tree is a directed tree if there is a root from which there is a directed
path to each vertex.
The level of a vertex v in a rooted tree is the length of the path to v from the
root.
A tree T with only one vertex is called a trivial tree ; otherwise T is a nontrivial
tree.
Trees
Theorems:
Theorems:
3. If v = v1, the tree T is the spanning tree for the order specified.
1. Assign the first vertex v1 and insert this vertex in the queue Q
and initialise T as the tree consisting of this vertex as the root.
Plane Graph:
If a planar graph is drawn in the plane so that no two edges cross
over.
Note:
1. Order means no. of nodes in the graph.
2. Size means no. of edges in the graph
Euler’s formula for connected plane graph
If G is a connected plane graph, then |V| – |E| +|R| = 2.
where
V No. of vertices
E No. of edges
R No. of regions
Proof (by mathematical induction):
Assume that Connected plane graph G has k + 1 regions, where k ≥ 1.
Delete an edge common to the boundary of two separate regions.
The resulting graph G’ has the same no. of vertices, one fewer edge
and also one fewer region as two previous regions have been
consolidated by the removal of the edge.
No. of vertices in G’ = |V’| = |V|.
No. of edges in G’ = |E’| = |E| – 1.
No. of regions in G’ = |R’| = |R| – 1.
But |V| – |E| + |R| = |V’| – |E’| + |R’|.
|V’| – |E’| + |R’| = 2, by inductive hypothesis.
|V| – |E| +|R| = 2.
Dual of a plane graph
Corresponding to each region r of G there is a vertex r* of G*, and
corresponding to each edge e of G there is an edge e* of G*; two
vertices r* and s* are joined by the edge e* in G* iff their
corresponding regions r and s are separated by the edge e in G.
A loop is added at a vertex r* of G* for each cut–edge of G that
belongs to the boundary of the region r.
Dual of a plane graph
Corresponding to each region r of G there is a vertex r* of G*, and
corresponding to each edge e of G there is an edge e* of G*; two
vertices r* and s* are joined by the edge e* in G* iff their
corresponding regions r and s are separated by the edge e in G.
A loop is added at a vertex r* of G* for each cut–edge of G that
belongs to the boundary of the region r.