pptx

advertisement

Tutorial 5 of CSCI2110

Eulerian Path & Hamiltonian Cycle

Tutor: Zhou Hong ( 摹漏 ) hzhou@cse.cuhk.edu.hk

About Me

• Name: Zhou Hong ( 摹漏 )

• Office: SHB117

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

• Topics Responsibility: Graph Theory

• Eulerian Path

• Hamiltonian Cycle

• Stable Matching

Outline

Eulerian Path & Eulerian Cycle

Eulerian Path: a path that visits every edge exactly once

Eulerian Cycle: a cycle that visits every edge exactly once

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

Eulerian Cycle

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

Necessary Condition for Eulerian Cycle:

If a connected graph G has an Eulerian cycle, then every vertex in

G is of even degree.

𝑒

2 𝑒

6

Example: 𝑒

1 𝑒

3 𝑒

4 𝑒

5 𝑒

7

An Eulerian Cycle: 𝑒

1 𝑒

2 𝑒

3 𝑒

4 𝑒

5 𝑒

6 𝑒

7 𝑒

8 𝑒

8

Check that every vertex is of even degree

Eulerian 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.

𝑒

1 𝑒

2 𝑒

3 𝑒

4 𝑒

5 𝑒

6 𝑒

7 𝑒

8

Eulerian Path

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.

Example: 𝑒

2 𝑒

1 𝑒

3 𝑒

4 𝑒

6 𝑒

5 𝑒

7

An Eulerian Path: 𝑒

1 𝑒

2 𝑒

3 𝑒

4 𝑒

5 𝑒

6

Check that only are of odd degrees.

𝑒

7

Eulerian Path

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

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.

Eulerian Path

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

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) u v

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

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.

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.

Proof Idea

• Start with a longest simple path P=v

1 v

2

...v

k

.

• We can find a simple cycle C among v

1 to v k 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.

v

4

P

… v v

3 v k-2 v

2 v k-1 v

1 v k

Find a Simple Cycle

Now, what we need to do is just finding a cycle among v

1 to v k

. But how?

If there exists a pair of vertices v i and v i is adjacent to v k and v i+1

, such that v

, then we can find a cycle C = v i+1 i+1 is adjacent to v v i+2

…v k v i v i-1

…v

2 v

1 v i+1

.

1

P

… v i v i+1 v k-2 v

2 v

1 v k-1 v k

Existence of Such Vertex Pair v i and v i+1

• Since P is the longest simple path in G, all neighbors of v

1 in P, otherwise P can be extended. and v k must be

• Proof by contradiction, suppose no desired pair of vertices exists.

– All vertices before (in P) neighbors of v

1 are not adjacent to v k

• This implies there are deg(v

1

)

≥ n/2 vertices in P are not adjacent to vertex v k

. Together with vertices adjacent to v k

(

≥ n/2) and v k itself, there are at least n+1 vertices in P, contradiction.

v

4

P

… v

3 v k-2 v

2 v k-1 v

1 v k

Stable Matching

The Marrying Procedure

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

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

Boys Optimal & Girls Pessimal Algorithm

All boys get the best partner simultaneously!

All girls get the worst partner simultaneously!

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

Can a girl do better by lying?

YES!

Girls with True Preference (Day 1)

Boys

A:213

Girls

1:ABC

B:123 2:BAC

C:231 3:CBA

Girls with True Preference (Day 2)

Boys

OKAY, marriage day!

Girls

A:213 1:ABC

B:123

Girl 2 gets her

second best choice

C:231

2:BAC

3:CBA

Girl 2 Tells a Lie (Day 1)

Boys

A:213

Girls

1:ABC

B:123 2:BCA

C:231 3:CBA

Girl 2 Tells a Lie (Day 2)

Boys

A:213

Girls

1:ABC

B:123 2:BCA

C:231 3:CBA

Girl 2 Tells a Lie (Day 3)

Boys

A:213

Girls

1:ABC

B:123 2:BCA

C:231 3:CBA

Girl 2 Tells a Lie (Day 4)

Boys

OKAY, marriage day!

Girls

A:213 1:ABC

B:123

Girl 2 gets her best choice

C:231

2:BCA

3:CBA

Thank You!

Q & A ?

Download