Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle

27
Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle Tutor: Zhou Hong ( 周周 ) [email protected]

description

Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle. Tutor: Zhou Hong ( 周宏 ) [email protected]. About Me. Name: Zhou Hong ( 周宏 ) Office: SHB117 Office Hour: Friday 10:00 am – 12:00 noon or by appointment Topics Responsibility: Graph Theory. Outline. Eulerian Path - PowerPoint PPT Presentation

Transcript of Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle

Page 1: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Tutorial 5 of CSCI2110Eulerian Path & Hamiltonian Cycle

Tutor: Zhou Hong (周宏 )[email protected]

Page 2: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

About Me

• Name: Zhou Hong (周宏 )

• Office: SHB117

• Office Hour: Friday 10:00 am – 12:00 noon or by appointment

• Topics Responsibility: Graph Theory

Page 3: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Outline

• Eulerian Path

• Hamiltonian Cycle

• Stable Matching

Page 4: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Eulerian Path & Eulerian Cycle

Eulerian Path: a path that visits every edge exactly once

Eulerian Cycle: a cycle that visits every edge exactly once

Page 5: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Exercise: T/F Questions

• A Simple Path is a Path

• A Simple Cycle is a Cycle

• A Simple Cycle is a Simple Path

• A Path is a Cycle

• A Eulerian Cycle is a Eulerian Path

Page 6: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Euler’s theorem: A connected graph has an Eulerian cycle if and only if every vertex is of even degree.

Eulerian Cycle

Necessary Condition for Eulerian Cycle: If a connected graph G has an Eulerian cycle, then every vertex in G is of even degree.

𝑒1

𝑒2

𝑒3𝑒4 𝑒5

𝑒6

𝑒7𝑒8

Example:

𝑒1𝑒2𝑒3𝑒4𝑒5𝑒6𝑒7𝑒8An Eulerian Cycle:

Check that every vertex is of even degree

Page 7: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Euler’s theorem: A connected graph has an Eulerian cycle if and only if every vertex is of even degree.

Proof (Eulerian Cycle Even Degrees):

• Let G be a connected graph with an Eulerian cycle C, v be arbitrary vertex in G.

• Every occurrence of v in the Eulerian cycle C will account two edges adjacent to v.

• Since C use every edge of G exactly once, degree of v must be even.

Eulerian Cycle

𝑒1𝑒2𝑒3𝑒4𝑒5𝑒6𝑒7𝑒8

Page 8: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Euler’s theorem: A connected graph has an Eulerian path (but not cycle) if and only if there are two vertices with odd degrees.

Necessary Condition for Eulerian Path: If a connected graph G has an Eulerian path (but not cycle), then exactly two vertices in G are of odd degrees.

𝑒1

𝑒2

𝑒3𝑒4 𝑒5

𝑒6

𝑒7

Example:

𝑒1𝑒2𝑒3𝑒4𝑒5𝑒6𝑒7An Eulerian Path: Check that only are of odd degrees.

Eulerian Path

Page 9: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Proof (Eulerian Path Two vertices of Odd Degrees):

• Let G be a connected graph with an Eulerian path P.

• Every intermediate occurrence of a vertex v in the Eulerian path P will account two edges adjacent to v.

• If a vertex v occurs as starting or ending point of P, then only one edge is associated with v.

• Since P use every edge of G exactly once, starting and ending vertices of P are of odd degrees, all the other vertices have even degrees.

Euler’s theorem: A connected graph has an Eulerian path (but not cycle) if and only if there are two vertices with odd degrees.

Eulerian Path

Page 10: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Euler’s theorem: A connected graph has an Eulerian path (but not cycle) if and only if there are two vertices with odd degrees.

Sufficient Condition for Eulerian Path: In a connected graph G, if there are exactly two vertices have odd degrees, then G has an Eulerian Path (but not cycle).

Exercise: Prove the above Sufficient Condition. (Hint: reduce to Eulerian Cycle)

Eulerian Path

Page 11: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Proof of Sufficient Condition:• Let the two odd degree vertices in G be u,v.• Add an edge e between u,v to form a new connected graph

G’.• Now, every vertex in G’ has even degree.• We have reduced to Eulerian cycle problem, therefore, G’ has

an Eulerian cycle.• Remove e from the cycle, we get a Eulerian path of G. (u,v

are starting and ending points of the path)

G u vG’

Eulerian Path

Page 12: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Hamiltonian Path & Hamiltonian Cycle

Hamiltonian Path: a path that visits every vertex exactly once.

Hamiltonian Cycle: a cycle that visits every vertex exactly once (except for the vertex that is both the start and end).

A Hamiltonian Cycle in a dodecahedron

Page 13: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Hamiltonian Path in Homework 3

Semi-Complete Directed Graph G=(V,A): u,v V, either (u,v) A or (v,u) A (but not both)

Tips: the following example is similar to Q3 of HW3, but not the same.

Page 14: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Hamiltonian Cycle in Undirected Graph

Consider the following statement: If a graph G has n 3 vertices and degree of each vertex is at least n/2, then G has a Hamiltonian Cycle.

Do we need to specify that G is connected?

NO

Exercise: Prove that minimum degree of G is at least n/2 implies G is connected

Key Observation: Any pair of vertices share at least one common neighbor.

Page 15: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Proof Idea

• Start with a longest simple path P=v1v2...vk.

• We can find a simple cycle C among v1 to vk in graph G.

• If k < n, since G is connected, there must exists a vertex adjacent to some vertex in the cycle C.– Which implies we can get a longer simple path through C.

vkv1

P…

v2

v3v4

vk-1

vk-2

v

Page 16: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Find a Simple Cycle

vkv1

P…

v2 vk-1

vk-2vi

vi+

1

Now, what we need to do is just finding a cycle among v1 to vk. But how?If there exists a pair of vertices vi and vi+1, such that vi+1 is adjacent

to v1 and vi is adjacent to vk, then we can find a cycle C = vi+1vi+2…vkvivi-1…v2v1vi+1.

Page 17: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Existence of Such Vertex Pair vi and vi+1

• Since P is the longest simple path in G, all neighbors of v1 and vk must be in P, otherwise P can be extended.

• Proof by contradiction, suppose no desired pair of vertices exists.– All vertices before (in P) neighbors of v1 are not adjacent to vk

• This implies there are deg(v1) n/2 vertices in P are not adjacent to vertex vk. Together with vertices adjacent to vk ( n/2) and vk itself, there are at least n+1 vertices in P, contradiction.

vkv1

P…

v2

v3v4

vk-1

vk-2

Page 18: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Stable Matching

Page 19: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Morning: boys propose to their favorite girl on list. If a boy has an empty list already, he stays home and does his CSC2110 homework.

Afternoon: girls accept their favorite suitor and reject the rest (possibly breaking up with her current boyfriend)

Evening: boys who got rejected write off the top girl from their lists

The Marrying Procedure

This procedure is then repeated until all boys propose to a different girl

Page 20: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Boys Optimal & Girls Pessimal Algorithm

All boys get the best partner simultaneously!All girls get the worst partner simultaneously!

Can a girl do better by lying?

That is, among all possible stable matching,boys get the best possible partners simultaneously.

YES!

Page 21: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girls with True Preference (Day 1)

Boys

A:213

B:123

C:231

1:ABC

2:BAC

3:CBA

Girls

Page 22: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girls with True Preference (Day 2)

Boys

A:213

B:123

C:231

1:ABC

2:BAC

3:CBA

GirlsOKAY, marriage day!

Girl 2 gets her second best choice

Page 23: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girl 2 Tells a Lie (Day 1)

Boys

A:213

B:123

C:231

1:ABC

2:BCA

3:CBA

Girls

Page 24: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girl 2 Tells a Lie (Day 2)

Boys

A:213

B:123

C:231

1:ABC

2:BCA

3:CBA

Girls

Page 25: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girl 2 Tells a Lie (Day 3)

Boys

A:213

B:123

C:231

1:ABC

2:BCA

3:CBA

Girls

Page 26: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Girl 2 Tells a Lie (Day 4)

Boys

A:213

B:123

C:231

1:ABC

2:BCA

3:CBA

GirlsOKAY, marriage day!

Girl 2 gets her best choice

Page 27: Tutorial 5 of CSCI2110 Eulerian  Path & Hamiltonian Cycle

Thank You!

Q & A ?