Title: Lecture 5 part 2
1Lecture 5 (part 2)
- Graphs II
- Euler and Hamiltonian Path / Circuit
- Reading Epp Chp 11.2, 11.3
22. Euler Circuit
Leonhard Euler (pronounced OIL-er) 1707-1783,
Swiss Mathematician Is it possible for a person
to take a walk around the town of Königsberg,
starting and ending at the same location and
crossing each of the seven bridges exactly once?
32.1 Euler Circuit (Definition)
- Definition Let G(V,E) be a graph (simple or
multigraph). - An Euler Circuit for G is a simple circuit that
contains every edge in E. - Implications
- simple circuit edges must be distinct
- At most 1 traversal of each edge.
- every edge in E
- At least 1 traversal of each edge.
42.2 Euler Circuit Theorem
- (Euler Circuit Theorem)
- Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree. - Proof Strategy
- () Assume G has an Euler Circuit
- Prove (1) G is connected
- (2) "vÎV, deg(v) 2k (for some k)
- () Assume G is connected and
- "vÎV, deg(v) 2k (for some k)
- Prove G has an Euler Circuit
52.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
- To Prove G is connected. (Defn of connected?)
- Since G has an Euler Circuit, then let
- v0 e1 v1 e2 v2 en-1 vn-1 en v0
- be the Euler Circuit.
- Pick any 2 vertices x, y in V.
- Now, x must be some vi and y must be some vj in
the Euler circuit. (Why? Since by definition,
An Euler circuit for G is a circuit that
contains EVERY VERTEX in V) - If i j then we have a path from x vi ei1
vi1 ej vj y - If i gt j then we have a path from x vi ei vi-1
ej1 vj y
- Therefore there is a path from x to y in V.
- Therefore G is connected (by definition of
connected graph).
62.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
- Now, we prove (2)
- To show that any vertex has an even degree.
- Pick any vertex v in V.
- Since G has an Euler circuit, then that circuit
must pass through v (by defn of Euler circuit
circuit that contains EVERY VERTEX in V) - Look at the circuit from the viewpoint of v as
the starting vertex. - Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
72.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
If v has some more edges incident on it, the
process repeats again (Why? Because Euler Circuit
traverses every edge in E).
82.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
If v has some more edges incident on it, the
process repeats again (Why? Because Euler Circuit
traverses every edge in E).
92.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
Edges on v occur in exit / entry pairs! Degree of
v must be a multiple of 2 gt EVEN!!!
102.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- The proof that there is () an Euler circuit,
will be given by an ALGORITHM for finding the
circuit. - We first present the algorithm.
- We next show that the algorithm is correct.
- (1) It will ALWAYS terminate and
- (2) If it terminates, it will ALWAYS find the
circuit.
112.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 1 Pick any vertex v ÎV as the starting
vertex. - Step 2 Pick any sequence of adjacent vertices
and edges starting and ending at v, and never
repeating an edge. Let this circuit be C.
C v 1 2 3 v
122.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3 Does C contain every edge and vertex of
G? - If Yes, then stop and output C, which is an
Euler circuit. - If No
1
2
v
3
C v 1 2 3 v
132.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3a Remove the circuit C from G creating G.
4
1
5
2
v
G
6
3
C v 1 2 3 v
142.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3a Remove the circuit C from G creating G.
4
1
5
G
6
3
C v 1 2 3 v
152.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3b Pick any vertex u common to C and G
4
1
5
6
u
3
C v 1 2 3 v
162.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C.
4
1
5
6
u
3
C v 1 2 3 v
172.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C.
4
1
5
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
182.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
4
1
5
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
192.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
4
1
5
C v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
202.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
(ii) Follow C to u
4
1
5
C v
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
212.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
222.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
232.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
242.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(iv) Return from u through untravelled portion
of C to v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
252.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(iv) Return from u through untravelled portion
of C to v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3 v
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
262.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Let C C. Go back to Step 3
4
1
5
2
v
6
3
C v 1 2 3 6 5 4 1 3 v
272.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3 Does C contain every edge and vertex of
G? - If Yes, then stop and output C, which is an
Euler circuit. - If No (3a-3d)
4
1
5
2
v
6
3
C v 1 2 3 6 5 4 1 3 v
282.2 Euler Circuit Theorem (Proof )
- The algorithm
- Step 1 Pick any vertex v ÎV as the starting
vertex. - Step 2 Pick any sequence of adjacent vertices
and edges starting and ending at v, and never
repeating an edge. Let this circuit be C. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C. - Step 3d PATCH C to C to form C
- Start at v
- Follow C to u
- Follow C from u all the way back to u
- Return from u through untravelled portion of C to
v - Let C C.
- Go to Step 3.
292.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- IF the algorithm terminates, THEN it will give an
Euler circuit. This is true because Step 3
checks whether all edges have been used, and step
3a ensures that no edge is repeated in the
circuit. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Create another ciruit C startin from u.
- Step 3d PATCH C to C to form C
302.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- (2) The algorithm will always terminate, because
- The graph is finite,
- Step 3b will always be successful since the
graph is connected, any remaining edges must
connect to the currently found circuit. - Step 2 and 3c will always be successful a new
circuit can always be found since the degree of
the vertex u is even. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Create another circuit C starting from
u - Step 3d PATCH C to C to form C
312.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
322.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
332.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
C a b c d a
d
i
a
f
j
e
b
h
c
g
342.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
C a b c d a
d
i
C d e g h j i d
a
C a b c d e g h j i d a
f
j
e
b
h
c
g
352.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
C a b c d e g h j i d a
f
j
e
b
h
c
g
362.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
C a b c d e g h j i d a
f
j
e
b
h
c
C e f h e
g
C a b c d e f h e g h j i d a
372.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
f
j
e
b
h
c
g
C a b c d e f h e g h j i d a
C is the Euler Circuit
382.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A No.
392.4. Euler Path (Definition)
- Definition Let G(V,E) be a graph.
- An EULER PATH from v to u (v ? u) for G is a
simple path starting from v and ending at u and
contains every edge in E. - Implications
- simple path edges must be distinct
- At most 1 traversal of each edge.
- every edge in E
- At least 1 traversal of each edge.
402.5 Euler Path Theorem
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree. - Euler Path theorem is a COROLLARY (a consequence,
a result) of Euler Circuit theorem. - Proof is left as an exercise (You need to use the
Euler circuit theorem to prove the Euler Path
theorem).
412.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
422.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
a
g
h
A a g h i e h f a
i
b
e
f
k
c
d
j
432.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
a
g
h
A a g h i e h f a
b f e k j d b c d
i
b
e
f
k
c
d
j
443.1. Hamiltonian Circuit (Definition)
- Definition Let G(V,E) be a graph (simple or
multigraph). - A HAMILTONIAN CIRCUIT for G is a elementary
circuit that contains every vertex in V. - (Sir William Hamilton 1805-1865, Irish)
- Implications
- elementary circuit
- vertices must be distinct
- AT MOST ONE traversal of each vertex
- every vertex in V
- AT LEAST ONE traversal of each vertex
- elementary circuit (edges distinct of course!)
453.2 Hamiltonian Circuit (Examples)
Q Is there a Hamiltonian circuit?
A Yes
g
b
d
a
f
h
e
c
g
463.3 Hamiltonian Circuit (Theorem?)
- Q Given ANY graph G(V,E), is there a nice
property which is a sufficient condition to
determine whether the graph has a Hamiltonian
circuit? - (Sufficient condition) Property Hamiltonian
Circuit - A Dont know. No choice but to try all possible
ways. - Q Are there special types of graphs which
definitely have Hamiltonian circuits? - A Yes.
- Q What are they?
- A Graphs of some forms of geometric solids.
- (i) Platonic Solids (ii) Archimedian solids
473.3 Hamiltonian Circuit (Special Cases)
(i) Platonic Solids
483.3 Hamiltonian Circuit (Special Cases)
(ii) Archidemian Solids
493.4. Hamiltonian Path (Definition)
- Definition Let G(V,E) be a graph.
- A HAMILTONIAN Path for G is a elementary path
that contains every vertex in V. - Implications
- elementary path
- vertices must be distinct
- AT MOST ONE traversal of each vertex
- every vertex in V
- AT LEAST ONE traversal of each vertex
- Simple path (edges distinct of course!)
503.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q But does it have a Hamiltonian Path from a
to c? A Yes a e h f d b g c
513.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Does it have a Hamiltonian Path from a to
g? A No.
523.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be Hamiltonian Paths starting from
g? A No.
533.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be Hamiltonian Paths ending at d? A
No.
543.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be a Hamiltonian Path ending at
a? A Yes. Example b g c d f e h
553.6 Hamiltonian Path (Theorem)
- Q Given ANY graph G(V,E), is there a nice
property which is a sufficient condition to
determine whether the graph has a Hamiltonian
path? - (Sufficient condition) Property Hamiltonian
Path - Notes
- (Sufficient condition) Property Hamiltonian
Path - (Necessary condition) Property ? Hamiltonian
Path - (Sufficient and necessary condition)
- Property ? Hamiltonian Path
563.6 Hamiltonian Path (theorem)
Q Given ANY graph G(V,E), is there a nice
property which is a sufficient condition to
determine whether the graph has a Hamiltonian
path? (Sufficient condition) Property ?
Hamiltonian Path Please note that this does not
mean that Property ? Hamiltonian Path Yes
there is, but only for simple graph Sufficient
condition for a simple graph G with n vertices to
have Hamiltonian Path is every pair of vertices
must have .