You are on page 1of 73

UNIT-V

Graph Theory –
Basic Concept of Graph Theory,
Euler’s Path & Circuits,
Hamiltonian Path & Circuits,
Partially Ordered Sets-
Lattices,
Finite Boolean Functions -
Boolean Polynomials,
Trees-
Minimal Spanning Trees
Unit 5: Part I
Graph Theory –
• Basic Concept of Graph Theory,
• Euler’s Path & Circuits,
• Hamiltonian Path & Circuits,
Graphs
Def: A graph G = (V,E, ) consists of a non-
empty set V of vertices (or nodes) and a finite
set of objects E called as edges and a function
 that assigns to each edge a subset of
vertices.
Eg. Let V= {1,2,3,4} and E={e1,e2,e3,e4,e5}, Let 
be defined by  (e1) =  (e5) ={1,2},  (e2) ={3,4},
 (e3) ={1,3),  (e4) ={2,4}. e 1

1 e5 2
e3
e4
3 4
e2
Basic Types of Graphs
1. Undirected graph 2. Directed graph

loop

G=(V,E)
isolated vertex

multiple
edges

adjacent
Unordered pair of edges Ordered pair of edges

degree of a vertex: number of edges connected by the end points


(indegree, outdegree in case of directed graph)

A loop contributes 2 to the degree of a vertex, whereas isolated vertex degree is 0.


Simple & Multigraph
• A graph which has neither loops nor multiple
edges is called a simple graph.
• A graph which has loops as well as multiple
edges is called a multigraph.

a b
d
a b d
c

c
simple graph multi graph
• Ex. Draw the graph G=( V,E, ), where V= {a, b,
c, d, e} , E= {e1,e2,e3,e4,e5,e6} and
(e1)= (e5)={a ,c}, (e2)={a, d} , (e3)={e, c},
(e4)={b, c}, (e6)={e, d}.
Ex. Draw the graph G=( V,E, ), where V= {a, b, c,
d, e} , E= {e1,e2,e3,e4,e5,e6} and (e1)= (e5)={a
,c}, (e2)={a, d} , (e3)={e, c}, (e4)={b, c},
(e6)={e, d}.
a
a e2
e1 e5
c d
b
e4 e3
e6
e
Handshaking Theorem
Statement : Let G={V,E} be undirected graph with e
edges , then the sum of degrees of the vertices in
an undirected graph is even.
I.e.  deg(v) =2e for all vV.

Note : As every edge is connected with exactly two


vertices, so each edge is counted twices at each
of its end. This implies that the sum of the
degree is equal twice the number of eges.
A B

E C

Vertex Deg no of edges = 6


A2 total no. of deg =12
B4 so  deg (v) =2e
C1
D3
E2
Ex. Give the degree of each vertices of the following
graph and hence show that  deg (v) =2e.

a b d

c
Vertex degree
a 1
b 3
c 2+1=3
d 1
Total  deg(v)= 8 = (2(e)) , where no. of edges
(e)=4.
Ex. How many edges are there in a graph with 10
vertices each of degree six?
Solution : 10 vertices each of degree 6 => total
no of deg. ie  deg(v)= 10(6) =60.

Using Handshaking theorem we have


 deg(v)= 2e where e is the no. of edges
So 60=2e => e=30.

Ans: There are total 30 edges in the given graph.


Walk
A walk u-v in a graph G is the loop-free finite alternative
sequence u=v0,e1,v1,e2,v2,e3,….vn-1,en,vn , where vn=v.
Note :
A walk is a sequence of vertices and edges that begins at v i and
travel along edges to vj so that no edge appears more than
once .
However , a vertex may appear more than once.
A walk is said to be closed walk if it is possible that a walk begins
and end at the same vertices. ie vi=vj., otherwise it is called as
the open walk .
Eg. 1-2-3-4 1-2-4-5-2-3
2 4
2

1 3 5
1 3
4
Path
• A Elementary path is a walk through sequence u=v0,v1,..,vn of
vertices, each adjacent to the next, without any repetition of
vertices.
• A simple path from u-v is the one in which no edge is repeated in
the path.
• If first vertex equal to last vertex then path is called a closed path
and if first vertex not equal to last vertex then path is called an
open path.
• Length of path : The number of edges in a path is called the length
of the path.
• Note : An edge which is not a loop is a path of length one.
• A loop can be included in a walk but not in a path.
2

1
3
Simple Path Not a elementary path since, 2 is repeated Closed path
Circuit
• A circuit is a path that begins and ends at the
same vertex that contains no repeated edge.
Example : 1-2-3-4-5-6-1
1 2
1 1

6 3

2
5 4
Subgraph
• A graph G′(V′,E′) is a subgraph of the graph
G(V,E) if V′⊆V and E′⊆E.

b b
a a

d c d
c

• Note : If reqiured we can delete vertex also


Subgraphs
• Draw two sub-graph with three vertices for
the graph shown below.
b

a
c

b b

a c a
c
Euler Path & Circuit
• Eulerian Path : An Eulerian path through a
graph is a path whose edge list contains each
edge of the graph exactly once.
• Eulerian Circuit: An Euler circuit is a path
through a graph, in which the initial vertex
appears 2nd time as the terminal vertex.
• Note: An Euler Circuit is always and Euler Path,
but an Euler Path may not be an Euler Circuit.
Euler’s Theorem, or Rules
• If a graph has more than two odd
vertices(degrees), then it does not have an
Euler path.
• If a graph has two or fewer odd
vertices(degrees), then it has at least one
Euler path.
• If a graph has any odd vertices(degrees), then
it cannot have an Euler circuit.
• If every vertex in a graph is even, then it has at
least one Euler circuit.
•A graph with 2 odd vertices and some even vertices contains an Euler path.
•A graph with all vertices being even contains an Euler circuit.
•A graph with more than 2 odd vertices does not contain any Euler path or circuit.

Graph Number of Number of What does the


odd even vertices path contain?
vertices

1 0 10 C
2 0 6 C
3 2 6 P
4 2 4 P
5 4 1 N
6 8 0 N

(Euler path = P; Euler circuit = C; Neither = N)


Hamiltonian Path & Circuit
• Hamiltonian Path: A Hamiltonian path through
a graph is a path whose vertex list contain
each vertex of the graph exactly once, [except
if path is a circuit].
• Hamiltonian Circuit: A Hamiltonian circuit is a
path in which the initial vertex appears a
second time as the terminal vertex.
.
• A Hamilton path is a path that goes through
each vertex of the graph once and only once.

F, A, B, E, C, G, D is a Hamilton
path
• A Hamilton circuit is a circuit that goes
through each vertex of the graph once and
only once (starting point and ending point is
the same)

F, B, E, C, G, D, A, F is a Hamilton
circuit
Example:

• Identify Euler path, Euler circuit, Hamilton


path, and/or Hamilton circuit

Euler Path (C=1,D=3) No Euler circuit or path

Hamilton Path : A-B-E-D-C Hamilton path :A-B-E-D-C

No Hamilton Circuit Hamilton circuit : A-B-E-C-D-A


Definition of Isomorphism
• Two graphs G and G’ are isomorphic if :

– There exists a one-to-one correspondence between


vertices in G and G’ , such that there is an edge between a
and b in G if and only if there is an edge between the
corresponding vertices and in G’ .
An approach to checking isomorphism:
 Count the vertices. The graphs must have an equal number.
 Count the edges. The graphs must have an equal number.
 Check vertex degree sequence. Each graph must have the same
degree sequence.
Note :
If these tests don’t help, and you suspect the graphs actually are
isomorphic, then try to find a one-to-one correspondence between
vertices of one graph and vertices of the other. Remember that a
vertex of degree n in the one graph must correspond to a vertex of
degree n in the other.
Example of isomorphic graphs
a b 1 2
3
f 4
e

d c 6 5

G G�
An isomorphism between G and G�:
a 6 (3) d 5 (4)
b 1 (4) e 2 (4)
c 3 (3) f 4 (4)
Note : we can take a 3 then c  6 , or b  5 or
2 or 4 similarly with d, e ,f.
Two non-isomorphic graphs

Vertices: 6
Vertices: 6
Edges: 7
Edges: 7
Vertex sequence: 4, 3, 3, 2, 2, 0.
Vertex sequence: 5, 3, 2, 2, 1, 1.
Example of Isomorphic Graph
Are these pairs of graphs isomorphic?
3
a e 1 5 Isomorphic:
a-1, b-5,
#1
c d c-4, d-3, e-2,
b f 6
f-6.
2

4
d
1 2 Not Isomorphic:
a b c 5 6 5 K3’s on left,
#2
7 4 K3’s on right.
e g 4 3
f

28
Check This for Isomorphic
b b

a c a c

e d e d

G G’
Unit 5: Part II
Partially Ordered Sets
• POSET
• Hasse Diagram
• Lattices
Recall
– An equivalence relation is a relation that is reflexive, symmetric, and
transitive

– Relation R is antisymmetric, If a,b A, if aRb and bRa then a=b.

– Recall that antisymmetric means that if (a,b)  R, then (b,a)  R unless


b=a
– Thus, (a,a) is allowed to be in R
– But if it’s reflexive, all possible (a,a) must be in R
Partially Ordered Sets, (Poset)
Partial ordering examples
• Show that  is a partial order on the set of integers
– It is reflexive: a  a for all a  Z
– It is antisymmetric: if a  b then the only way that
b  a is when b = a
– It is transitive: if a  b and b  c, then a  c

• Note that ≥ is the partial ordering on the set of


integers so (Z, ≥) is also the partially ordered set,
or poset

33
Example of Posets

Example: Let S={x,y,z} and (P(S),⊆) , where |P(S)|=23 =8


P(S)={, {x}, {y}, {z}, {x, y}, {y, z}, {x,z}, {x,y,z}}
Now consider any set A,B, C in P(S)
1. Since every A ⊆A, hence it is reflexive.
2. If A ⊆B and B ⊆A, we have A=B.
Hence it is Antisymmetric
3. If A ⊆B and B ⊆C, then A ⊆C
Hence it is transitive
Therefore (P(S), ⊆) is a poset
Example of Posets

partially ordered set (poset)


defined by set S and partial order ·

Examples:
(P(S), ⊆)
(Z, )
(Z, divides)
Note : For divisibility we have if a,b  Z such that
a b then a|b.
Related Terms

Consider A={1,2,3,5,6,10,15,30} which is ordered by divisibility.


Determine all the comparable and non comparable pairs of element of A .

Sol : The comparable pairs of elements of A are :


{1,2},{1,3},{1,5},{1,6},{1,10},{1,15},{1,30},
{2,6},{2,10},{2,30},
{3,6},{3,15},{3,30},
{5,10},{5,15},{5,30},
{6,30},{10,30},{15,30},

The non- comparable pair of the element of A are


{2,3},{2,5},{2,15},
{3,5},{3,10},{5,6},{6,10},{6,15},{10,15}

Note : Existence of non comparable pairs avoids the linearly order set.
The set containing one element is always linearly ordered.
Ex: Consider the set A={1,2,3….} is ordered by
divisibility. Determine whether each of the
following subset of A are linearly ordered or not.
(i) B={2,4,8} (ii)C={3,6,9,11} (iii) D={1}
Sol :
(ii) Since 2|4, 2|8 as well 4|8 , every pair is
comparable. So B is linearly ordered.
(iii) Since 3 | 11 i.e. (3,11) is not comparable is
enough to say that C is not linearly ordered.
(iv) The set containing one element is always
linearly ordered.
Related Terms
Hasse Diagram
Hasse Diagram is a tool to describe the partial order.

Steps involved in drawing Hasse Diagram


1. Draw the diagraph of the given poset in bottom top sequence.
2. Eliminate all the reflexive , loops of the vertices.
3. Eliminate all the transitive edges in the diagraph
if (a,b) (b,c) and (a,c) then remove only edge (a,c)
4. Eliminate all the arrow pointers of the edges
5. Replace the circle of the vertices by dots.

The resulting diagram of the partial order, is called as the Hasse diagram
of poset.
Example of Hasse Daigram
• Consider the set A={4,5,6,7} and a relation 
on A. Draw the diagraph and the Hasse
diagram of R.
Sol : The relation  on A is given by
R={(4,4),(5,5),(6,6),(7,7), (4,5), (4,6), (4,7), (5,6),
(5,7), (6,7)}
7

5 6

4
Example of Hasse Diagram

6
5

7
4

5 6 7

6
4
5

4
Note : The Hasse diagrame of such form defines the given poset is
linearly order.
Hasse Diagrams
• Consider the graph for a finite poset
({1,2,3,4},≤)
• When we KNOW it’s a poset, we can simplify
the graph 4 4
4 4
Called the
3 3 3 3 Hasse
diagram
2 2 2 2

1 1 1 1
Example of Hasse Diagram
– Let S = {1, 2, 3} and A=P(S).
Draw the Hasse of the poset A
with the partial order  (set
inclusion)
Sol: A = {, {1}, {2}, {3}, {1,
2}, {2, 3}, {1, 3}, {1,2,3}} {1,2,3}
– Now (A,) is a poset, The
Hasse diagram of (A,) is {2,3} {1,3}
{1,2}
shown as.
{3}
{1}
{2}
– The Diagram itself implies that the
poset is not linearly order. 
Hasse Diagram
• For the poset ({1,2,3,4,6,8,12}, |)
Exercise for student
Ex: Consider the partial order of divisibility on
the set A={1,2,3,5,6,10,15,30}. Draw the Hasse
diagram of the poset and determine whether
it is linearly ordered .

See next slide:


Concept of Poset(Sn,D)
For any integer n, Sn denotes the set of all 30
divisors of n and D denotes the division
15
operation. 10
6
Eg : if n=30, then Sn={1,2,3,5,6,10,15,30}
5
So the Hasse diagram is given by 2 3

( Hint : for previous problem) 45


1

15
9
Eg : if n=45, then Sn={1,3,5,9,15,45}
So the Hasse diagram is given by 3 5

1
Lattices
Defination : A lattice L is a poset in which every pair of elements has a LUB
and GLB.

Let L be a set of all non negative real numbers. Then


(L,) is a poset, where  denotes the usual less than
or equal to relation. Let a,b  L. Now max{a,b}  L
and min{a,b}  L. It is easy to see that max{a,b} is
the LUB of {a,b} and min{a,b} is the GLB of {a,b}.

e.g. A poset (L,) is called a lattice if ab and ab exist in L for all a,b  L.

Consider max{2,6} =6 =26 and min{2,6}=2 = 26.

Hence (L,  ) is a lattice.


Note : In divisibility : lcm(2,6) =6 : (lub) and gcd(2,6)=2 : (glb)
L1 =({1,2,3,4,5,6,7,8,9,10,11,12},|)
L2=({1,2,3,4,6,9},|)

2v7 =lcm(2,7) =14 L1 , so L1 is not a Lattice


4v6=lcm(4,6) = 12L2, so L2 is not a Lattice
Isomorphic Lattices
Let L1&L2 be two lattices and f: L1L2, if f is one to one
correspondence such that a,bL1 we have
f(ab) =f(a)f(b) and f(ab)=f(a)f(b).

Ex :Show that L={1,2,3,6} under divisibility relation and the


lattice (P(S),), where S={a,b} are isomorphic.
Sol : Let f: LP(S) , where hasse diagram of L and P(s) is
6
{a,b}
3
2 {b}
{a}
1

Let us define f(1) = , f(2) ={a}, f(3)={b} and f{6} ={a,b}.
So f is one one and on to .
To prove that Lattice {L,|} and Lattice {(P(S),)} are
isomorphic
i.e. if a, b  L then
f(avb)=f(a)vf(b) and f(ab)=f(a)  f(b)
For example
Consider (2,3)
f(2V3)=lcm(2,3)=6, f(2)={a} , f(3)={b} so f(2)vf(3) =>{a}{b}
={a,b} , we have f(6)->{a,b}.
Also
f(2  3)=gcd(2,3)=1, f(2)={a} , f(3)={b} so f(2)  f(3)
=>{a}{b} =, we have f(1)->  .

This is true for such pairs a,b L. , so Lattice {L,|} and
Lattice {(P(S),)} are isomorphic .
Unit 5: Part IV
Minimum Spanning Tree (MST)
• Basic Terms
• Kruskal’s Algorithm for MST
• Prism’s Algorithm for MST
• Matrix Version of Prism’s Algorithm
Basic Terms
• A tree is a connected undirected graph with no
simple circuits.

• A spanning tree of a simple graph G is a


subgraph of G that is a tree containing every
vertex of G.

• Given a weighted graph G (V, E, w), the


minimum spanning tree problem is to find a
spanning tree in G that has the smallest weight.
Kruskal’s Algorithm
Steps involved in Kruskal’s Algorithm

1. Consider the given connected, weighted graph


G with n vertices , whose minimum spanning
tree T, is to be determine.
2. Order all the edges of the graph G according to
their increasing weights.
3. Initialize T with all the vertices but do not
include any edges.
4. Add edge of the graph G in T which does not
form a circuit unit n-1 edges are added.
Example of Krushal’s Algorithm
• Determine the MST of the weighted graph show below.

Sol : Given n=6 vertices and e=9 edges in G.


we have
Sr. no. Edges Weights Forms Added or Not
Circuit ?
1 (B,E) 2 No Added
2 (C,D) 3 No Added
3 (A,D) 4 No Added .So required MST is
4 (C,F) 4 No Added
5 (B,C) 5 No Added
6 (E,F) 5 -- Not Added
7 (A,B) 6 -- Not Added
8 (D,E) 6 -- Not Added
9 (A,F) 7 -- Not Added
The minimum weight of
spanning tree is 18 .
MST may not be unique
• Determine the MST of the weighted graph show below.

Sol : Given n=6 vertices and e=9 edges in G.


we have
Sr. no. Edges Weights Forms Added or Not
Circuit ?
1 (B,E) 2 No Added
2 (C,D) 3 No Added
3 (A,D) 4 No Added .So another MST is
4 (C,F) 4 No Added
5 (E,F) 5 No Added
6 (B,C) 5 -- Not Added
7 (A,B) 6 -- Not Added
8 (D,E) 6 -- Not Added
9 (A,F) 7 -- Not Added

The minimum weight of spanning tree is 18


Ex. Find a MST of the following graph using
Kruskal’s Algorithm :

B
A
7
7 3

C 5 D
4
6 8 4
9
E F
Sol : Given n=6 vertices and e=9 edges in G.
we have
Sr. no. Edges Weights Forms
Circuit ?
Added or Not
So. MST is
1 (B,D) 3 No Added (1)
2 (A,E) 4 No Added (2)
3 (F,D) 4 No Added (3)
4 (B,F) 5 YES NOT Added
5 (C,E) 6 No Added (4)
6 (C,B) 7 No Added (5)
7 (A,C) 7 Yes Not Added The minimum weight of
spanning Tree is 24.
8 (A,F) 8 -- Not Added
9 (B,E) 9 -- Not Added
Prim’s Algorithm
T = a spanning tree containing a single node s;
E = set of edges adjacent to s;
while T does not contain all the nodes
{
remove an edge (v, w) of lowest cost from E
if w is already in T then discard edge (v, w)
else {
add edge (v, w) and node w to T
add to E the edges adjacent to w
}
}
Steps involved in Prim’s Algorithm
1. Consider the given connected, weighted graph G with n vertices ,
whose minimum spanning tree T, is to be determine.
2. Select an edge of the graph G having minimum weight and
consider any vertex of this edge.
3. Among all the edges incident (connected) with the selected
vertex select an edge with minimum weight which do not form a
circuit .Include it in T.
4. At each stage, select an edge with minimum weight joining a
vertex already included in T and a vertex which is yet to be
included.
5. Repeat this process for n-1 time or un-till all the vertices of G are
not included in T .
Example of Prim’s Algorithm
• Find the minimal spanning tree of the
following graph using Prim’s Algorithm
b 6.3 c
a
4.8
8.3 2.0
12.5

d
f 5.0 e
b 6.3

4.8
8.3 2.0
12.5

d
f 5.0

• Let us select edge (e, c) having minimum weight


among all the edges i.e . =2 and also select the vertex
c.
• There two edges incident to vertex
c
c ie (c,d) and (c,b) .

2.0

• Minimum weight {(c,d),(c,b)} =min {4.8,6.3} =4.8


include cd edge , where d vertex is included in T.
b 6.3 c
a
4.8
8.3 2.0
12.5

d
f 5.0 e

b 6.3 c
a
4.8
2.0
12.5

d
f 5.0 e

The minimum weight =2+4.8+6.3+5.0+12.5=30.6


Sol : The MST of the given graph is , where in (1)& (2) Min. weight
= 10. and in (3) Min. weight = 11.

(1) (2) (3)


So choose Min weight =10.
MATRIX FORM OF PRIM’S ALGORITHM

20 19

D 12
B
10 15
12 13

F C
8 E 14
This network may be described using a Distance Matrix

A B C D E F
A - 19 20 - -
-
B 19 - 13 12 - -
C - 13 - 15 14 -
D 20 12 15 - 12 10
E - - 14 12 - 8
F - - - 10 8 -
Step 1: Choose a starting vertex and delete all elements
in that vertex’s row and arrow its column

Step 2: Neglecting all deleted terms, scan all arrowed


columns for the lowest available element and circle that
element
Step 3: Delete the circled element’s row and arrow its
column

Step 4: Repeat steps 2 and 3 until all rows deleted

Step 5: The spanning tree is formed by the circled arcs


Now
Start
wewith
haveA vertex C
B
EFD
1 2 6 3 5 4 Scan all
Delete its arrowed
These
row & arcs, in this order, will provide a minimum spanning tree columns
arrow its and find
column A B C D E F lowest
element
A - 19 20 - - -
B 19 - 13 12 - -
C - 13 - 15 14 -
D 20 12 15 - 12 10
E - - 14 12 - 8
F - - - 10 8 - Write down the
arcs in the
AB BD DF FE BC order you
select them
A

20 19
AB BD DF FE BC
D 12
B
19 12 10 8 13
10 15
12 13

F C
8 E 14

The minimum spanning tree is

The minimum weight is =62


Sol : A B C D
A  4 3 
B  4  5 3 
M
C 3 5  2
 
D  3 2 
1 4 2 3

A B C D
A  4 3 
B  4  5 3 
M
C 3 5  2
 
D  3 2 

AC CD DB
3 2 3

So the MST is given by

The minimum weight is = 8


Sol :The MST is given by

The minimum weight = 5


End of Unit V

You might also like