walks, paths and circuits walks, paths and circuits sanjay jain, lecturer, school of computing

50
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Sanjay Jain, Lecturer, Lecturer, School of Computing School of Computing

Upload: precious-peppin

Post on 14-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Walks, Paths and CircuitsWalks, Paths and Circuits

Sanjay Jain, Lecturer, Sanjay Jain, Lecturer,

School of ComputingSchool of Computing

Page 2: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Walks Paths and Circuits Notation for Walks Connected Graphs Lemma Euler Circuit Euler Path Connected Component Hamiltonian Circuit

Main Menu Main Menu (Click on the topics below)

Page 3: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

WalksWalks

A walk from a vertex u to v (in G) is a sequence of the form

v0 e1 v1 e2 v2 e3……….. ek vk

where u = v0 , v = vk and

for any ei, endpoints(ei) = {vi-1 , vi} Trivial walk from u to u consists of just

u

Length of a walk: number of edges in the walk, where we count different appearance of an edge in the walk separately.

Page 4: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

WalksWalks

v1e2v2e3v3e3v2 is a walk from v1 to v2 with length 3.

v1 v2e2

e3

v3

e1

e4

v4

v5

e5 e6

e7

v6

Page 5: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Notation for WalksNotation for Walks

In graphs without parallel edges, we often omit the name of edges from the walk.

This is so, since the edges are uniquely determined by the end points.

Thus, we can reinsert the edges if needed.

Page 6: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 7: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Paths and CircuitsPaths and Circuits

Path from u to v (in G) is a walk from u to v such that no edges are repeated.

A Simple Path from u to v (in G) is a path from u to v in which no vertices are repeated.

A closed walk is a walk which starts and ends at the same vertex.

A circuit is a closed walk in which no edges are repeated.

A simple circuit is a circuit in which no vertices (except for the last vertex, which is the same as first vertex) are repeated.

Page 8: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Paths and CircuitsPaths and Circuits

v1e2v2e3v3e3v2 is walk but not a path. v1e2v2e3v3 is a path from v1to v3

v1e2v2e3v3e3v2e2v1 is a closed walk but not a circuit v1e2v2e3v3e1v1 is a simple circuit

v1 v2e2

e3

v3

e1

e4

v4

v5

e5 e6

e7

v6

Page 9: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 10: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

TheoremTheorem

Suppose G is a graph, u and v are vertices in V(G), and there is a walk from u to v (in G).

Then there is a simple path from u to v in G.

Page 11: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

ProofProofSince there is a walk from u to v, there must be a shortest

walk from u to v. Let it be

W = v0 e1 v1 e2... vi ei+1…… vj ej+1 ….. ek vk

If it is a simple path, then we are done.

Otherwise suppose vi = vj , ij.

Then, W’ = v0 e1 v1 e2... vi ej+1 ….. ek vk

v0

vi =vj

vk

is also a walk from u to v, with length smaller than W. A contradiction to W being of shortest length. Thus W must be simple path..

Page 12: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 13: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Connected GraphsConnected Graphs

Two vertices u and v in a graph G, are connected iff there is a walk from u to v.

G is connected iff all pair of vertices in G are connected.

Page 14: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

ExampleExample

v1 v2e2

e3

v3

e1

e4

Page 15: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

ExampleExample

v1 v2e2

e3

v3

e1

e4

v4

v5

e5 e6

e7

v6

Page 16: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 17: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

TheoremTheorem

Suppose G is a graph and C is a circuit in G containing vertices u, v. Suppose e is an edge in G.

Let G’ be formed by deleting edge e from the graph G.Then there is still a path from u to v in G’.

Page 18: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

ProofProof

Suppose the circuit C in G isw…… u ……v ….. ……w

e can be in only one of the above paths.So at least one path remains intact after removal of e. Thus, in G’, there is a path from u to v.

Page 19: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 20: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

LemmaLemma

(a) If G is a connected graph, then any two distinct vertices of G can be connected by a simple path

(b) If two distinct vertices v and w are part of a non-trivial circuit and one edge is removed from the circuit, then there still exists a path from v to w in the new graph so formed.

(c) If G is connected and we remove an edge in a circuit, then G still remains connected.

Page 21: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 22: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof of Lemma (a)Proof of Lemma (a)

Suppose v, w are vertices in G.Then since G is connected, there exists a walk from u

to v (in G). Therefore, by a theorem done earlier, there is a

simple path from u to v.

(a) If G is a connected graph, then any two distinct vertices of G can be connected by a simple path

Page 23: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 24: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof of Lemma (b)Proof of Lemma (b)

In earlier theorem we showed: Suppose G is a graph and C is a circuit in G

containing vertices u and v. Suppose e is an edge in G.

Let G’ be formed by deleting edge e from the graph G.

Then there is still a path from u to v in G’.

(b) If two distinct vertices v and w are part of a non-trivial circuit and one edge is removed from the circuit, then there still exists a path from v to w in the new graph so formed.

Page 25: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 26: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof of Lemma (c)Proof of Lemma (c)

(c) If G is connected and we remove an edge in a circuit, then G still remains connected.

Page 27: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof of Lemma (c)Proof of Lemma (c)

Suppose e is the edge in a circuit of G which is removed. Suppose e has endpoints u and v. Suppose G’ be the new graph. By part (b) there is a path, say P, from u to v in G’.

To show: for all u’,v’ in V(G), there exists a walk from u’ to v’ in G’.Consider any u’, v’ in G.G is connected --> there is a walk and thus a path, say Q, from u’

to v’ in G. If Q doesn’t contain e: Q is a path from u’ to v’ in G’.If Q contains e: replace “uev” in Q by P and “veu” in Q by reverse of P.That is, if Q=u’……uev…..v’then consider the walk u’……P…….v’Note that this new walk is a walk in G’ from u’ to v’. Since u’, v’ were arbitrary element of V(G’), we get that G’ is

connected.

Page 28: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 29: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler CircuitEuler Circuit

Suppose G is a graph. Euler circuit of G (in G) is a circuit which goes through all the edges (exactly once) and all the vertices of G.

Note that the vertices may be repeated in an Euler circuit.

Page 30: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler Circuit - ExampleEuler Circuit - Example

. ... .

.v0 v2 v4

v5v3v1

v0v1v3v2v5v4v2v0 is an Euler circuit of the above graph

Page 31: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler Circuit - ExampleEuler Circuit - Example

. ... .

.v0 v2 v4

v5v3v1

Page 32: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 33: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

TheoremTheorem

If a graph G has Euler circuit, then (a) G is connected, and (b) every vertex of G has even degree.

Part (a): If G is not-connected then no circuit goes through all the vertices.

Page 34: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof (b)Proof (b)Suppose the Euler circuit is:

v0 e1 v1 e2….. ei vi ei+1……ej vj ej+1 ….. ek v0

For any vertex v (except v0):

Coming in, going out occur in pairs. Each coming in and going out are via different edges (no repetition of edges in a circuit). Thus the degree of vertex v in G must be even. Similar reasoning holds for v0 also, except that we consider the first exit and last entry separately.

.come in,

go out, ..…..

go out, ..

come in,

Page 35: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 36: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

TheoremTheorem

If G is connected and every vertex of G has even degree, then G has an Euler circuit.

Corollary: G has Euler circuit iff it is connected and every vertex of G has even degree.

Page 37: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Proof

.v

u.C

(b) No edges left: Done. Or: we made a circuit C and v (in C) still has an edge unused in C.

a) From u, walk until you are back at u (don’t repeat an edge).

C’

c) From v build circuit C’ (using only unused edges).

d) Insert C’ in C to form C’’ as follows:

e) Let C =C’’, and go to step b).

C’’

C: …… v…… …..Then C’’: …..C’….. ….. (v is replaced by C’).

C’’ uses all the edges in C and C’ exactly once.

.

Page 38: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 39: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler PathEuler Path

Suppose G is a graph. Let u and v be two distinct vertices of G. Then Euler path of G, from u to v, is a path from u to v which goes through all the edges of G (exactly once) and all the vertices of G.

Page 40: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler Path - ExampleEuler Path - Example

. ... .

.v0 v2 v4

v5v3v1

v2v0v1v3v5v4v2v3 is an Euler path from v2 to v3

Page 41: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Euler PathEuler Path

Corollary: Suppose G is a connected graph, and u, v are two distinct vertices in G.

Then G has an Euler path from u to v, iff degree of u and v is odd, and the degree of all other vertices in G is even.

Page 42: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 43: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Connected ComponentConnected Component

A Graph H is a connected component of G iff

a) H is a subgraph of Gb) H is connectedc) No connected subgraph H’ of G has H as its proper

subgraph.

Page 44: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Connected ComponentConnected Component

v1 v2e2

e3

v3

e1

e4

v4

v5

e5 e6

e7

v6

Page 45: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 46: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Hamiltonian CircuitHamiltonian Circuit

A Hamiltonian Circuit of G is a simple circuit of G which goes through every vertex of G.

Page 47: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Hamiltonian Circuit - ExampleHamiltonian Circuit - Example

. ... .

.v0 v2 v4

v5v3v1

v0v1v3v5v4v2v0 is an Hamiltonian circuit of the above graph

Page 48: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT

Page 49: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

Hamiltonian Circuit - TheoremHamiltonian Circuit - Theorem

A non-empty graph G has Hamiltonian Circuit iff

1. G has only one vertexor2. G has at least two vertices and G has a subgraph H

such that

a) H contains every vertex of G

b) H is connected

c) every vertex of H has degree 2

(note that this means H has same number of vertices as edges)

Page 50: Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing

END OF SEGMENT