66
1 Graphs Theory Graphs Theory UNIT IV UNIT IV

1 Graphs Theory UNIT IV. 2Contents Basic terminology, Multi graphs and weighted graphs Paths and circuits Shortest path in weighted graph Hamiltonian

Embed Size (px)

Citation preview

Page 1: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

1

Graphs TheoryGraphs Theory

UNIT IVUNIT IV

Page 2: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

2

ContentsContents

Basic terminology, Basic terminology, Multi graphs and weighted graphsMulti graphs and weighted graphsPaths and circuitsPaths and circuitsShortest path in weighted graphShortest path in weighted graphHamiltonian and Euler paths and circuitsHamiltonian and Euler paths and circuitsPlaner graphPlaner graphTravelling salesman problem.Travelling salesman problem.

Page 3: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

3

Introduction to GraphsIntroduction to Graphs

Definition: A graph Definition: A graph is collection of points is collection of points called called vertices vertices & collection of lines called & collection of lines called edges edges each of which joins either a pair of each of which joins either a pair of points or single points to itself.points or single points to itself.

Mathematically graph G is an ordered pair of Mathematically graph G is an ordered pair of (V, E)(V, E)

Each edge eEach edge eijij is associated with an ordered pair is associated with an ordered pair of vertices (Vof vertices (Vii,V,Vjj).).

Page 4: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

4

Introduction to GraphsIntroduction to GraphsFor Example,For Example,

In Fig. G has graph 4 verticesIn Fig. G has graph 4 vertices

namely v1, v2, v3, v4& 7 edges namely v1, v2, v3, v4& 7 edges

Namely e1, e2, e3, e4, e5, e6, e7 Namely e1, e2, e3, e4, e5, e6, e7

Then e1=(v1, v2) Similarly for other Then e1=(v1, v2) Similarly for other

edges.edges.

In short, we can represent G=(V,E) where In short, we can represent G=(V,E) where

V=(v1, v2, v3, v4) & E=(e1, e2, e3, e4, e5, e6,e7 )V=(v1, v2, v3, v4) & E=(e1, e2, e3, e4, e5, e6,e7 )

v1v1

v2v2

v3v3

v4v4

ee11ee

22

e4e4ee55

ee33

e6e6e7e7

Graph GGraph G

Page 5: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

5

Self Loops & Parallel EdgesSelf Loops & Parallel EdgesDefinition: Definition: If the end vertices VIf the end vertices Vii & V & Vjj of any edge of any edge eeijij are same, then edge eij called as are same, then edge eij called as Self Loop.Self Loop.

For Example, For Example, In graph G, the edge eIn graph G, the edge e66 =(v =(v33, v, v33) is ) is self loop.self loop.

Definition: Definition: If there are more than one edge is If there are more than one edge is associated with given pair of vertices then those associated with given pair of vertices then those edge called asedge called as Parallel or Multiple edge. Parallel or Multiple edge.

For Example, For Example, In graph G, eIn graph G, e44 & e & e77 has (v has (v33, v, v44) are ) are called as Parallel edge.called as Parallel edge.

Page 6: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

6

Simple & Multiple GraphsSimple & Multiple GraphsDefinition: Definition: A graph that has neither self loops A graph that has neither self loops or parallel edge is called as or parallel edge is called as Simple Graph Simple Graph otherwise it is called asotherwise it is called as Multiple Graph. Multiple Graph.

For Example,For Example,

G1 (Simple Graph ) G2 (Multiple Graph)G1 (Simple Graph ) G2 (Multiple Graph)

Page 7: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

7

Weighted GraphWeighted GraphDefinition: Definition: If each edge or each vertex or If each edge or each vertex or both are associated with some +ve no. then both are associated with some +ve no. then the graphthe graph is called as is called as Weighted GraphWeighted Graph

For Example,For Example,V1V1 V2V2

V4V4 V3V3

1.41.4

1.51.5

1.71.7

66

Page 8: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

8

Finite & Infinite GraphFinite & Infinite GraphDefinition: Definition: A graph is Finite no. of vertices as A graph is Finite no. of vertices as well as finite no. of edges called as well as finite no. of edges called as Finite Finite Graph Graph otherwise it is otherwise it is Infinite Graph.Infinite Graph.

For Example, For Example, The graph G1 & G2 is Finite The graph G1 & G2 is Finite Graph.Graph.

Definition: Definition: A graph G=(V,E) is called as A graph G=(V,E) is called as Labeled Graph Labeled Graph if its edges are labeled with if its edges are labeled with some names or data.some names or data.

For Example, For Example, Graph G is labeled graph.Graph G is labeled graph.

Page 9: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

9

Adjacency & IncidenceAdjacency & IncidenceDefinition: Definition: Two vertices vTwo vertices v11 & v & v22 vertices of G vertices of G joins directly by at least one edge then there joins directly by at least one edge then there vertices called vertices called Adjacent Vertices.Adjacent Vertices.

For Example, For Example, In Graph G, vIn Graph G, v11 & v & v22 are adjacent are adjacent vertices.vertices.

Definition: Definition: If VIf Vii is end vertex of edge e is end vertex of edge eijij=(v=(vii,v,vjj) ) then edge ethen edge eijij is said to be is said to be IncidentIncident on v on vii. . Similarly eSimilarly eijij is said to be is said to be IncidentIncident on v on vjj..

For Example, For Example, In Graph G, eIn Graph G, e11 is incident on v is incident on v11 & & vv22..

Page 10: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

10

Degree of a VertexDegree of a VertexDefinition: Definition: The no. of edges incident on a vertex The no. of edges incident on a vertex vvii with self loop counted twice is called as with self loop counted twice is called as degree degree of vertex vi.of vertex vi.

For Example, For Example, Consider the Graph G, Consider the Graph G, d(vd(v11)=3 ,d(v)=3 ,d(v22)=2 ,d(v)=2 ,d(v33)=5 ,d(v)=5 ,d(v44)= 4)= 4

Definition :Definition :

A vertex with degree zero is called as A vertex with degree zero is called as Isolated Isolated VertexVertex & A vertex with degree one is called as & A vertex with degree one is called as Pendant Vertex.Pendant Vertex.

v1v1

v2v2

v3v3

v4v4

ee11ee

22

e4e4ee55

ee33

e6e6e7e7

Page 11: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

11

Handshaking LemmaHandshaking LemmaTheorem: Theorem: The graph G with e no. of edges & n no. The graph G with e no. of edges & n no. of vertices, since each edge contributes two of vertices, since each edge contributes two degree, the sum of the degrees of all vertices in G degree, the sum of the degrees of all vertices in G is twice no. of edges in G.is twice no. of edges in G.

i.e. i.e. d(v d(vii)=2e is called as )=2e is called as Handshaking Handshaking LemmaLemma..

Example:Example: How many edges are there in a graph How many edges are there in a graph with 10 vertices, each of degree 6?with 10 vertices, each of degree 6?

Solution:Solution: The sum of the degrees of the vertices is The sum of the degrees of the vertices is 6*10 = 60. According to the Handshaking Theorem, 6*10 = 60. According to the Handshaking Theorem, it follows that 2e = 60, so there are 30 edges.it follows that 2e = 60, so there are 30 edges.

nn

i=1i=1

Page 12: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

12

Matrix Representation of GraphsMatrix Representation of GraphsA graph can also be represented by matrix.A graph can also be represented by matrix.

Two ways Two ways are used for matrix representation are used for matrix representation of graph are given as follows,of graph are given as follows,

1.1.Adjacent MatrixAdjacent Matrix

2.2.Incident MatrixIncident Matrix

Lets see one by one…Lets see one by one…

Page 13: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

13

1. Adjacent Matrix1. Adjacent MatrixThe The A.M. of Graph G A.M. of Graph G with n vertices & no with n vertices & no parallel edges is a symmetric binary matrix parallel edges is a symmetric binary matrix A(G)=[aA(G)=[aijij] or order n*n where,] or order n*n where,

aaijij=1, if there is as edge between vi &vj.=1, if there is as edge between vi &vj.

aaijij=0, if v=0, if vii & v & vjj are not adjacent. are not adjacent.

A self loop at vertex vi corresponds to aA self loop at vertex vi corresponds to aijij=1.=1.

For Example, For Example,

A(G)= A(G)=

Page 14: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

14

1. Adjacent Matrix1. Adjacent MatrixThe The A.M. of multigraph G A.M. of multigraph G with n vertices is with n vertices is an n*n matrix A(G)=[aan n*n matrix A(G)=[aijij] where,] where,

aaijij=N, if there one or more edge are there =N, if there one or more edge are there between vbetween vii &v &vjj & N is no. of edges between v & N is no. of edges between vii & v& vjj..

aaijij=0, otherwise.=0, otherwise.

For Example, For Example,

A(G)= A(G)=

Page 15: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

15

2. Incident Matrix2. Incident MatrixGiven a graph G with n vertices , e edges & no Given a graph G with n vertices , e edges & no self loops. The incidence matrix x(G)=[Xself loops. The incidence matrix x(G)=[Xijij] of ] of the other graph G is an n*e matrix where,the other graph G is an n*e matrix where,

XXijij=1, if j=1, if jthth edge e edge ejj is incident on i is incident on ithth vertex v vertex vii,,

XXijij=0, otherwise.=0, otherwise.

Here n vertices are rows & e edges are Here n vertices are rows & e edges are columns.columns.

X(G)=X(G)=

Page 16: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

16

Directed Graph or DiagraphDirected Graph or DiagraphDefinition: Definition: If each edge of the graph G has a If each edge of the graph G has a direction then graph called as direction then graph called as diagraph.diagraph.

In a graph with directed edges, the In a graph with directed edges, the in-degreein-degree of a vertex v, denoted by of a vertex v, denoted by degdeg--(v) (v) && out- out-degreedegree of v, denoted by of v, denoted by degdeg++(v).(v).

See the example in Next page….See the example in Next page….

Page 17: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

17

Directed Graph or DiagraphDirected Graph or DiagraphExample:Example: What are the in-degrees and out- What are the in-degrees and out-degrees of the vertices a, b, c, d in this graph:degrees of the vertices a, b, c, d in this graph:

aabb

ccdd

degdeg--(a) = (a) = 11

degdeg++(a) = (a) = 22

degdeg--(b) = (b) = 44

degdeg++(b) = (b) = 22

degdeg--(d) = (d) = 22

degdeg++(d) = (d) = 11

degdeg--(c) = (c) = 00

degdeg++(c) = (c) = 22

Page 18: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

18

Adjacency Matrix of a diagraphAdjacency Matrix of a diagraphIt is defined in similar fashion as it defined for It is defined in similar fashion as it defined for undirected graph.undirected graph.

For Example,For Example,

A(D)=A(D)=

Page 19: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

19

Incident matrix of diagraphIncident matrix of diagraphGiven a graph G with n, e & no self loops is Given a graph G with n, e & no self loops is matrix x(G)=[Xmatrix x(G)=[Xijij] or order n*e where n ] or order n*e where n vertices are rows & e edges are columns such vertices are rows & e edges are columns such that,that,

XXijij=1, if jth edge e=1, if jth edge ejj is incident is incident outout i ithth vertex v vertex vii

XXijij=-1, if jth edge e=-1, if jth edge ejj is incident is incident into into iithth vertex v vertex vii

XXijij=0, if jth edge e=0, if jth edge ejj not incident not incident onon i ithth vertex v vertex vii..

Page 20: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

20

Null GraphNull GraphDefinition: Definition: If the edge set of any graph with n vertices If the edge set of any graph with n vertices is an empty set, then the graph is known asis an empty set, then the graph is known as null null graph.graph.

It is denoted by NIt is denoted by Nnn

For Example, For Example,

NN33 NN44

Page 21: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

21

Complete GraphComplete GraphDefinitionDefinition: Let G be simple graph on n : Let G be simple graph on n vertices. If the degree of each vertex is (n-1) vertices. If the degree of each vertex is (n-1) then the graph is called as then the graph is called as complete graph.complete graph.

Complete graph on n vertices, it is denoted by Complete graph on n vertices, it is denoted by KKnn..

In complete graph KIn complete graph Knn, the number of edges are, the number of edges are

n(n-1)/2n(n-1)/2

For example, For example,

KK11 KK22 KK33 KK44 KK55

Page 22: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

22

Regular GraphRegular GraphDefinitionDefinition: If the degree of each vertex is : If the degree of each vertex is same say ‘r’ in any graph G then the graph is same say ‘r’ in any graph G then the graph is said to be a said to be a regular graph regular graph of degree r.of degree r.

For example, For example,

KK33 KK44 KK55

Page 23: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

23

Bipartite GraphBipartite GraphDefinitionDefinition: The graph is called as : The graph is called as bipartite bipartite graphgraph , if its vertex set V can be partitioned , if its vertex set V can be partitioned into two distinct subset say V1 & V2. such that into two distinct subset say V1 & V2. such that V1 V1 UU V2=V & V1 V2=V & V1 V2 =V2 = & also each edge of & also each edge of G joins a vertex of V1 to vertex of V2.G joins a vertex of V1 to vertex of V2.

A graph can not have self loop.A graph can not have self loop.

Page 24: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

24

Bipartite GraphsBipartite Graphs

Example I:Example I: Is G1 bipartite? Is G1 bipartite?

vv11

vv22 vv33

No,No, because there is no way to because there is no way to partition the vertices into two partition the vertices into two sets so that there are no edges sets so that there are no edges with both endpoints in the same with both endpoints in the same set.set.

Example II:Example II: Is G2 bipartite? Is G2 bipartite?

vv55

vv11

vv22

vv33 vv44

vv66vv11 vv66

vv22vv55

vv33vv44

Yes, Yes, because because we can we can display G2 display G2 like this:like this:

Page 25: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

25

Complete Bipartite GraphsComplete Bipartite GraphsDefinition:Definition: A graph is called as A graph is called as complete complete bipartite graph bipartite graph if each vertex of V1 is joined to if each vertex of V1 is joined to every vertex of V2 by an unique edge.every vertex of V2 by an unique edge.

It is denoted by KIt is denoted by Km,nm,n if no. of vertices in V1 is m & if no. of vertices in V1 is m & that in V2 in n.that in V2 in n.

KK3,23,2 KK3,43,4

Page 26: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

26

Linked representation of graphsLinked representation of graphs

The above adjacency can be represented by,The above adjacency can be represented by,

G=[a:b, c, d; b:a, d; c:a, d; d:a, b, c]G=[a:b, c, d; b:a, d; c:a, d; d:a, b, c]

This is link representation of the graph G.This is link representation of the graph G.

aa

bb

cc

dd a, da, dbba, da, dcc

a, b, ca, b, cdd

b, c, db, c, daa

Adjacent Adjacent VerticesVerticesVertexVertex

Page 27: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

27

IsomorphismIsomorphismDefinitionDefinition: Two graphs are thought of as : Two graphs are thought of as equivalent (equivalent (called isomorphiccalled isomorphic) if they have ) if they have identical behavior in terms of graph theoretic identical behavior in terms of graph theoretic properties.properties.

Two graphs G(V, E) & G’(V’,E’) are said to be Two graphs G(V, E) & G’(V’,E’) are said to be isomorphicisomorphic to each other if there is one-one to each other if there is one-one correspondence between their vertices & correspondence between their vertices & between their edges such that incidence between their edges such that incidence relationship in preserved.relationship in preserved.

It is denoted by G1=G2It is denoted by G1=G2

Page 28: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

28

IsomorphismIsomorphismFor Example,For Example,

1 2 a b1 2 a b

4 3 d c4 3 d c

It is immediately apparent by definition of It is immediately apparent by definition of isomorphism that two isomorphic graphs must isomorphism that two isomorphic graphs must have,have,

• the same number of vertices,the same number of vertices,

• the same number of edges, andthe same number of edges, and

• the same degrees of vertices.the same degrees of vertices.

bb22dd33cc44

aa11

Page 29: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

29

Sub GraphSub GraphDefinition:Definition: A A sub graphsub graph of a graph G = (V, E) is a of a graph G = (V, E) is a graph G’ = (V’, E’) where V’graph G’ = (V’, E’) where V’V and E’V and E’E.E.

For Example:For Example:

G G1 G2G G1 G2

Page 30: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

30

Null Sub GraphNull Sub GraphDefinition:Definition: A subgraph is called as A subgraph is called as null sub graph null sub graph if its if its vertex set is same as vertex set of G & its edge set is empty vertex set is same as vertex set of G & its edge set is empty set. i.e. it does not contain any edges.set. i.e. it does not contain any edges.

For Example:For Example:

G Null SubgraphG Null Subgraph

Page 31: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

31

Spanning GraphSpanning GraphDefinition:Definition: Let G=(V, E) be any graph. Then G’ is said to be Let G=(V, E) be any graph. Then G’ is said to be the the spanning subgraph spanning subgraph of the graph G if its vertex set V’ is of the graph G if its vertex set V’ is equal to vertex set V of G.equal to vertex set V of G.

For Example:For Example:

G G1 G2G G1 G2

Page 32: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

32

Complement of a GraphComplement of a GraphDefinition: Definition: Let G is a simple graph. Then Let G is a simple graph. Then complement of G complement of G denoted by ~G is graph whose vertex set is same as vertex set of denoted by ~G is graph whose vertex set is same as vertex set of G & in which two vertices are adjacent if & only if they are not G & in which two vertices are adjacent if & only if they are not adjacent in G.adjacent in G.

For Example:For Example:

G ~G H ~HG ~G H ~H

Page 33: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

33

Operations on GraphsOperations on GraphsDefinition:Definition: The The unionunion of two simple graphs G of two simple graphs G11 = = (V(V11, E, E11) and G) and G22 = (V = (V22, E, E22) is the simple graph ) is the simple graph with vertex set Vwith vertex set V11 V V22 and edge set E and edge set E11 E E22. .

The union of GThe union of G11 and G and G22 is denoted by is denoted by GG11 G G22..

GG11 GG22 GG1 1 GG2 2

Page 34: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

34

Operations on GraphsOperations on GraphsDefinition:Definition: The The IntersectionIntersection of two simple of two simple graphs Ggraphs G11 =(V =(V11, E, E11) and G) and G22 = (V = (V22, E, E22) is the ) is the simple graph with vertex set Vsimple graph with vertex set V11 V V22 and edge and edge set Eset E11 E E22. .

The Intersection of GThe Intersection of G11 and G and G22 is denoted by is denoted by GG11 G G22..

GG11 GG22 GG1 1 GG2 2

Page 35: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

35

Operations on GraphsOperations on GraphsDefinition:Definition: The The Ring SumRing Sum of two graphs G of two graphs G11 =(V=(V11, E, E11) and G) and G22 = (V = (V22, E, E22) is the simple graph ) is the simple graph with vertex set Vwith vertex set V11 V V22 and edges that either in and edges that either in G1 or G2 but not in both. G1 or G2 but not in both.

The Ring Sum of GThe Ring Sum of G11 and G and G22 is denoted by is denoted by GG11 ⊕ ⊕ GG22..

GG11 GG22 GG1 1 ⊕⊕ GG2 2

Page 36: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

36

Operations on GraphsOperations on GraphsDefinition:Definition: The The Removal of vertex Removal of vertex of graph of graph G =(V, E). Let v ∈ V, then graph (G-v) can be G =(V, E). Let v ∈ V, then graph (G-v) can be obtained by removing vertex v from the graph.obtained by removing vertex v from the graph.

Definition:Definition: The The Removal of an edge Removal of an edge of graph of graph G =(V, E). Let e ∈ E, then graph (G-e) can be G =(V, E). Let e ∈ E, then graph (G-e) can be obtained by removing edge e from the graphobtained by removing edge e from the graph

GG G-eG-e G-vG-v

vv

eevv

Page 37: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

37

PathsPathsDefinition: PathDefinition: Path in a graph is a sequence of in a graph is a sequence of vertices such that from each of its vertices there is vertices such that from each of its vertices there is an edge to the next vertex in the sequence.an edge to the next vertex in the sequence.

Definition: Path P of length n Definition: Path P of length n from vfrom v00 to v to vn n is a is a sequence of vertices & edges of form (vsequence of vertices & edges of form (v00,e,e11,v,v11,e,e22,,….,e….,enn, v, vnn) where each e) where each ej j is an edge between vis an edge between vj-1j-1 & & vvj. j.

The vertices vThe vertices v00 & v & vn n are called are called end points of path end points of path & the other vertices v& the other vertices v11…., v…., vn-1 n-1 are called its are called its interior vertices.interior vertices.

See the example in next page……See the example in next page……

Page 38: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

38

PathsPathsFor Example,For Example,

Path I : vPath I : v11 e e22 v v22 e e44 v v44

Path II: vPath II: v44 e e44 v v22 e e22 v v11 e e11 v v22 e e33 v v33

Path III: vPath III: v33 e e33 v v22 e e22 v v11 e e11 v v22 e e33 v v33

Page 39: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

39

Types of PathsTypes of Paths 1. Simple Path:1. Simple Path:

A path in a graph G is called as A path in a graph G is called as simple path simple path if if the edges do not repeat in the path.the edges do not repeat in the path.

In Fig. path I & path II are simple graph but path In Fig. path I & path II are simple graph but path III is not.III is not.

2. Elementary Path:2. Elementary Path:

A path is said to be A path is said to be elementary path elementary path if if vertices do not repeat in the path.vertices do not repeat in the path.

In Fig. path I is an elementary path but path II is In Fig. path I is an elementary path but path II is not.not.

Page 40: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

40

CircuitsCircuitsDefinition: Definition: The path is called as The path is called as circuitcircuit, if end , if end vertices of the path is vertices of the path is samesame..

The circuit is denoted by letter The circuit is denoted by letter ‘C’.‘C’.

For Example, For Example, In Fig. CIn Fig. C11=(v=(v11, e, e11, v, v22, e, e22, v, v11) & ) & C C22=( V=( V33, e, e44, v, v11, e, e11, v, v22, e, e33, v, v33) are the circuits) are the circuits

Page 41: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

41

Types of CircuitsTypes of Circuits1. Simple Circuit:1. Simple Circuit:

A circuit in the graph G is said to be a simple A circuit in the graph G is said to be a simple circuit if is does not include the same edge circuit if is does not include the same edge twice.twice.

2. Elementary Circuit:2. Elementary Circuit:

A circuit is said to be elementary circuit if it A circuit is said to be elementary circuit if it does not meet same vertex twice ( Except first does not meet same vertex twice ( Except first & last vertex.& last vertex.

Page 42: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

42

Connected & Disconnected Connected & Disconnected GraphsGraphs

Definition: Definition: A graph is said to be A graph is said to be connected connected graph graph if there is exists the path between if there is exists the path between every pair of vertices, otherwise it is every pair of vertices, otherwise it is disconnected.disconnected.

See the example in next page….See the example in next page….

Page 43: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

43

Connected & Disconnected Connected & Disconnected GraphGraph

Example:Example: Are the following graphs connected? Are the following graphs connected?

dd

aabb

cc

ee

Yes.Yes.

dd

aabb

ccee

No.No.

dd

aabb

cc

ee

Yes.Yes.

dd

aabb

ccee

ffNo.No.

Page 44: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

44

ConnectivityConnectivityIn this section, we will see how the removal of In this section, we will see how the removal of edges & vertices disconnects the graph.edges & vertices disconnects the graph.

For that we will see the concepts as given For that we will see the concepts as given below,below,

1.1.Edge ConnectivityEdge Connectivity

2.2.Vertex ConnectivityVertex Connectivity

Lets see one by one …… Lets see one by one ……

Page 45: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

45

Edge ConnectivityEdge ConnectivityIn In Connected graph Connected graph G, a G, a cut set cut set is a is a minimal minimal set set of edges whose removal disconnects the of edges whose removal disconnects the graph & increases the components of graph by graph & increases the components of graph by oneone..

The number of edges in a smallest cut set of a The number of edges in a smallest cut set of a connected graph G is called as connected graph G is called as edge edge connectivityconnectivity..

It is denoted by It is denoted by λλ (G) (G). .

In other words, In other words, λλ (G) (G) is a smallest no. of edges is a smallest no. of edges in G whose removal disconnects G.in G whose removal disconnects G.

See the example in Next Page…..See the example in Next Page…..

Page 46: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

46

Edge ConnectivityEdge ConnectivityFor Example,For Example,

For instance, in Fig. {eFor instance, in Fig. {e11, e, e44, e, e88} is a cut set } is a cut set whereas {ewhereas {e11,e,e44, e, e88, e, e99} is } is notnot a cut set because a cut set because its subset {eits subset {e11, e, e44, e, e99} is also a cut set.} is also a cut set.

Other cut sets in graph {eOther cut sets in graph {e66, e, e77}, {e}, {e88, e, e99} & {e} & {e11, , ee33,e,e55}.}.

Page 47: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

47

Edge ConnectivityEdge ConnectivityIf the cut set of the connected graph contain If the cut set of the connected graph contain only one edge then the edge is called as only one edge then the edge is called as isthmus isthmus oror bridge. bridge. i.e. removal of edge i.e. removal of edge disconnects the graph.disconnects the graph.

λλ (G (G11)= 2 , )= 2 , λλ (G (G33) =1) =1

Page 48: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

48

Vertex ConnectivityVertex ConnectivityThe The vertex connectivityvertex connectivity of a connected of a connected graph G is defined as smallest number of graph G is defined as smallest number of vertices whose removal disconnects the graph.vertices whose removal disconnects the graph.

It is denoted by It is denoted by K(G)K(G). .

For Example,For Example,

If we remove the vertices vIf we remove the vertices v11 & v & v44 then graph G then graph G11 will be disconnected as shown in Gwill be disconnected as shown in G22..

Page 49: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

49

Vertex ConnectivityVertex ConnectivityA graph is said to be A graph is said to be separable graph separable graph if its if its vertex connectivity is vertex connectivity is oneone. .

Is separable graph, a vertex whose removal Is separable graph, a vertex whose removal disconnects the graph is said to be a disconnects the graph is said to be a cut cut vertex vertex or or cut pointcut point..

For Example,For Example,

In this graph, the In this graph, the vv is is cut point.cut point.

Page 50: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

50

Eulerian Path & Eulerian CircuitEulerian Path & Eulerian CircuitA path is called as A path is called as Eulerian Path Eulerian Path if every if every edge in the graph G appears exactly once in edge in the graph G appears exactly once in the path.the path.

A circuit which contains every edge of the A circuit which contains every edge of the graph G exactly once is called as graph G exactly once is called as Eulerian Eulerian CircuitCircuit..

A graph which has an Eulerian circuit is called A graph which has an Eulerian circuit is called as as Eulerian Graph.Eulerian Graph.

See the Example in next page…See the Example in next page…

Page 51: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

51

Eulerian Path & Eulerian CircuitEulerian Path & Eulerian CircuitFor Example, For Example,

GG11 has an has an Eulerian path Eulerian path ee11 e e22 e e33 e e44 e e55 but G but G22 does not have Eulerian path.does not have Eulerian path.

Similarly, GSimilarly, G33 contains an contains an Eulerian circuit Eulerian circuit 1 2 3 4 1 2 3 4 5 1 but G5 1 but G44 does not. does not.

Page 52: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

52

Hamiltonian Path & CircuitHamiltonian Path & CircuitA path in a connected graph G is called as A path in a connected graph G is called as Hamiltonian Path Hamiltonian Path if it contains every vertex of if it contains every vertex of G exactly once.G exactly once.

A circuit in a connected graph G is called A circuit in a connected graph G is called Hamiltonian Circuit Hamiltonian Circuit if it contains every vertex if it contains every vertex of G exactly once (of G exactly once (Except first & last vertexExcept first & last vertex).).

A graph which has Hamiltonian circuit is called A graph which has Hamiltonian circuit is called as as Hamiltonian Path.Hamiltonian Path.

See the Example in next page…See the Example in next page…

Page 53: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

53

Hamiltonian Path & CircuitHamiltonian Path & CircuitFor Example, For Example,

In graph In graph GG11, the Hamiltonian circuit is given by , the Hamiltonian circuit is given by ( 1 2 3 4 1) & ( 1 2 3 4 1) & GG22 has Hamiltonian path (b a c) has Hamiltonian path (b a c) but it does not contain any Hamiltonian circuit.but it does not contain any Hamiltonian circuit.

Page 54: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

54

Shortest Path ProblemShortest Path ProblemFor Example, For Example, Given railway network Given railway network connecting several cities, it is required to find connecting several cities, it is required to find shortest route between two cities.shortest route between two cities.

MumbaMumbaii

NasikNasik

NagpurNagpur

600600

700700

200200

650650

PunePune

Page 55: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

55

Shortest Path ProblemShortest Path ProblemWe now give an algorithm for solving the We now give an algorithm for solving the shortest path problem. shortest path problem.

The algorithm was found by The algorithm was found by DijkstraDijkstra in in 19591959 & is known as & is known as Dijkstra’s shortest path Dijkstra’s shortest path problemproblem..

This algorithm Gives shortest length of path This algorithm Gives shortest length of path from vertex ‘a’ to vertex ‘z’.from vertex ‘a’ to vertex ‘z’.

Page 56: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

56

Dijkstra’s AlgorithmDijkstra’s AlgorithmLet Let G= (V, E)G= (V, E) be a simple graph. Let be a simple graph. Let a & z a & z be any two vertices be any two vertices of the graph. of the graph.

Suppose Suppose L(x)L(x) = = Label of vertex x Label of vertex x which represents length of the which represents length of the shortest path from vertex ‘a’ to ‘z’. shortest path from vertex ‘a’ to ‘z’. wwijij= = Weight of the edge Weight of the edge eeijij=(v=(vii, v, vjj).).

---------------Steps for finding Shortest Path------------------------------Steps for finding Shortest Path---------------

Step 1: Step 1: let let P=P= where where PP is is set of those vertices which have set of those vertices which have permanent labelspermanent labels & & TT = = {all vertices of graph G}{all vertices of graph G}..

Set L(a)=0 , L(x)=∞, Set L(a)=0 , L(x)=∞, x x T & x != a. T & x != a.

Step 2: Step 2: Select vertex v in T which has smallest label. This label Select vertex v in T which has smallest label. This label is called as permanent label of v.is called as permanent label of v.

Also Also set P=P set P=P {v} & T=T-{v} {v} & T=T-{v}. If . If v=zv=z, then , then L(z) is length of L(z) is length of shortest path from vertex a to zshortest path from vertex a to z & & stopstop..

Page 57: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

57

Dijkstra’s AlgorithmDijkstra’s AlgorithmStep 3:Step 3: If v!=zIf v!=z, then revise labels of vertices of T. i.e. , then revise labels of vertices of T. i.e. vertices which do not have permanent labels.vertices which do not have permanent labels.

The new label of vertex x in T is given by,The new label of vertex x in T is given by,

L(x)= min {old L(x), L(v)+w (v, x)}L(x)= min {old L(x), L(v)+w (v, x)}

Where Where w(v, x)w(v, x) is is weight of edge joining vertex v & xweight of edge joining vertex v & x..

If there is If there is no direct edge joining v & x no direct edge joining v & x then take then take w(v, w(v, x)= ∞.x)= ∞.

Step 4Step 4: Repeat steps 2 & 3 : Repeat steps 2 & 3 untiluntil z gets permanent z gets permanent labellabel..

Page 58: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

58

Travelling Salesman ProblemTravelling Salesman ProblemThe The travelling salesman problemtravelling salesman problem is one of the is one of the classical problems in computer science.classical problems in computer science.

A travelling salesman wants to visit a number of A travelling salesman wants to visit a number of cities and then return to his starting point. Of cities and then return to his starting point. Of course he wants to save time and energy, so he course he wants to save time and energy, so he wants to determine the wants to determine the shortest pathshortest path for his trip. for his trip.

We can represent the cities and the distances We can represent the cities and the distances between them by a weighted, complete, between them by a weighted, complete, undirected graph.undirected graph.

The problem then is to find the The problem then is to find the circuit of circuit of minimum total weight that visits each vertex minimum total weight that visits each vertex exactly oneexactly one..

Page 59: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

59

Travelling Salesman ProblemTravelling Salesman ProblemExample:Example: What path would the travelling What path would the travelling salesman take to visit the following cities?salesman take to visit the following cities?

MumbaMumbaii

PunePune

NasikNasik

NagpurNagpur

600600

700700

200200

650650 550550700700

Solution:Solution: The shortest path is Nagpur, Nasik, The shortest path is Nagpur, Nasik, Mumbai, Pune, Nagpur (2,000 miles).Mumbai, Pune, Nagpur (2,000 miles).

Page 60: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

60

Nearest Neighbour MethodNearest Neighbour MethodSo efficient method is available to find the So efficient method is available to find the solution of travelling salesman problem. solution of travelling salesman problem.

So method is So method is Nearest Neighbour method Nearest Neighbour method which gives good results by travelling salesman which gives good results by travelling salesman problem.problem.

In this method, we start the H. Circuit with any In this method, we start the H. Circuit with any vertex & find vertex which is nearest to it. vertex & find vertex which is nearest to it. Containing this way & coming back to starting Containing this way & coming back to starting vertex by travelling through all the vertices vertex by travelling through all the vertices exactly once, we get the H. Circuit.exactly once, we get the H. Circuit.

Page 61: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

61

Nearest Neighbour MethodNearest Neighbour MethodThis method is described below,This method is described below,

1.1.Start with any vertex (say v1) & choose the vertex Start with any vertex (say v1) & choose the vertex closest to starting vertex to form an initial path of one closest to starting vertex to form an initial path of one edge. Construct this path by selecting different vertices edge. Construct this path by selecting different vertices as described in step (2).as described in step (2).

2.2.Let vLet vn n denote the latest vertex that was added to the denote the latest vertex that was added to the path. Select vertex vpath. Select vertex vn+1n+1 closest to v closest to vn n from all vertices from all vertices that are not in the path & add this vertex to the path.that are not in the path & add this vertex to the path.

3.3.Repeat step (2) till all vertices of the graph G are Repeat step (2) till all vertices of the graph G are included in the path.included in the path.

4.4.Lastly form a circuit by adding the edge connecting Lastly form a circuit by adding the edge connecting the starting vertex & last vertex added.the starting vertex & last vertex added.

Page 62: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

62

Planar GraphPlanar GraphA graph is said to be a A graph is said to be a Planar graphPlanar graph if it can if it can be drawn on the plane be drawn on the plane with no intersecting with no intersecting edgeedge. i.e. a graph is a planar graph if it drawn . i.e. a graph is a planar graph if it drawn on a plane such that no edges cross each other.on a plane such that no edges cross each other.

A graph which is non planar graph in A graph which is non planar graph in

One representation may becomes aOne representation may becomes a

Planar graph after redrawing it.Planar graph after redrawing it.

Page 63: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

63

Planar GraphPlanar GraphRegions:Regions:

A planar graph divides the planes into regions. A planar graph divides the planes into regions. A region characterized by the set of edges A region characterized by the set of edges forming its boundary.forming its boundary.

Types of RegionsTypes of Regions: :

1.1.Finite Region Finite Region ( A area is finite)( A area is finite)

2.2.Infinite Region Infinite Region (Area is Infinite)(Area is Infinite)

A Planar graph has A Planar graph has exactly one infinite regionexactly one infinite region..

Page 64: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

64

Planar GraphPlanar GraphEuler’s Formula:Euler’s Formula:

The no. of regions in any planar representation The no. of regions in any planar representation depends upon no. of vertices & no. of edges in depends upon no. of vertices & no. of edges in graph. The relation between edges, vertices & graph. The relation between edges, vertices & regions of any graph is given by Euler’s regions of any graph is given by Euler’s Formula.Formula.

For any connected graph,For any connected graph,

v - e + r = 2v - e + r = 2

Where v, e, r the total no. of vertices, edges & Where v, e, r the total no. of vertices, edges & regions in graph resp.regions in graph resp.

Page 65: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

65

Planar GraphPlanar GraphFor Example,For Example,

Here, v = 12 & e=15 then find r=?Here, v = 12 & e=15 then find r=?

Acc. To Euler’s Formula, Acc. To Euler’s Formula,

v-e-+r=2v-e-+r=2

r= 2-v+er= 2-v+e

r= 2-12+15r= 2-12+15

r= 5r= 5

So the graph G contains 5 Regions So the graph G contains 5 Regions

Page 66: 1 Graphs Theory UNIT IV. 2Contents  Basic terminology,  Multi graphs and weighted graphs  Paths and circuits  Shortest path in weighted graph  Hamiltonian

66

TheTheEndEnd