 1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3.

Presentation on theme: "1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3."— Presentation transcript:

1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3

2 2. 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?”

3 2.1 Euler Circuit (Definition) n 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. n 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.

4 2.2 Euler Circuit Theorem n (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. n 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

5 2.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?) n Since G has an Euler Circuit, then let v 0 e 1 v 1 e 2 v 2 … e n-1 v n-1 e n v 0 …be the Euler Circuit. n Pick any 2 vertices x, y in V. n Now, x must be some v i and y must be some v j 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 = v i e i+1 v i+1 … e j v j = y If i  j then we have a path from x = v i e i v i-1 … e j+1 v j = y n Therefore there is a path from x to y in V. n Therefore G is connected (by definition of connected graph).

6 2.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) n Now, we prove (2)… n To show: that any vertex has an even degree. n Pick any vertex v in V. n 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…”) n Look at the circuit from the viewpoint of v as the starting vertex. n Each time v is exited through the use of one edge, it must be returned to by the use of another edge.

7 2.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) v 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).

8 2.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) v 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).

9 2.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) v 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 => EVEN!!!

10 2.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. n We first present the algorithm. n We next show that the algorithm is correct. n (1) It will ALWAYS terminate; and n (2) If it terminates, it will ALWAYS find the circuit.

11 2.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. Step 1: Pick any vertex v  V as the starting vertex. n 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 v 1 2 3 Proof: (The algorithm)

12 n Step 3: Does C contain every edge and vertex of G? n If ‘Yes’, then stop and output C, which is an Euler circuit. n If ‘No’… 2.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. v 1 2 3 6 4 5 C: v 1 2 3 v Proof: (The algorithm)

13 2.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. n Step 3a: Remove the circuit C from G creating G’. v 1 2 3 4 5 6 C: v 1 2 3 v Proof: (The algorithm) G

14 2.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. n Step 3a: Remove the circuit C from G creating G’. 1 3 4 5 6 C: v 1 2 3 v Proof: (The algorithm) G’

15 2.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. n Step 3b: Pick any vertex u common to C and G’ 1 3 4 5 6 C: v 1 2 3 v u = Proof: (The algorithm)

16 2.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. n 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’. 1 3 4 5 6 C: v 1 2 3 v u = Proof: (The algorithm)

17 2.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. n 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’. 1 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = Proof: (The algorithm)

18 2.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. n Step 3d: PATCH C’ to C to form C’’: 1 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = Proof: (The algorithm)

19 2.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. n Step 3d: PATCH C’ to C to form C’’: 1 v 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v C’’: v Proof: (The algorithm)

20 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u C’’: v Proof: (The algorithm)

21 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u C’’: v 1 2 3 Proof: (The algorithm)

22 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u (iii) Follow C’ from u all the way back to u C’’: v 1 2 3 Proof: (The algorithm)

23 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u (iii) Follow C’ from u all the way back to u C’’: v 1 2 3 6 5 4 1 3 Proof: (The algorithm)

24 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u C’’: v 1 2 3 6 5 4 1 3 (iii) Follow C’ from u all the way back to u (iv) Return from u through untravelled portion of C to v Proof: (The algorithm)

25 2.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. n Step 3d: PATCH C’ to C to form C’’: v 1 2 3 4 5 6 C: v 1 2 3 vC’: 3 6 5 4 1 3 u = (i) Start at v (ii) Follow C to u C’’: v 1 2 3 6 5 4 1 3 v (iii) Follow C’ from u all the way back to u (iv) Return from u through untravelled portion of C to v Proof: (The algorithm)

26 2.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. n Let C = C’’. Go back to Step 3: v 1 2 3 4 5 6 C : v 1 2 3 6 5 4 1 3 v Proof: (The algorithm)

27 2.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. n Step 3: Does C contain every edge and vertex of G? n If ‘Yes’, then stop and output C, which is an Euler circuit. n If ‘No’… (3a-3d) v 1 2 3 4 5 6 C : v 1 2 3 6 5 4 1 3 v Proof: (The algorithm)

28 2.2 Euler Circuit Theorem (Proof  ) The algorithm: Step 1: Pick any vertex v  V as the starting vertex. n 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. n 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.

29 2.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: (1)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. n 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’’:

30 2.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… (a) The graph is finite, (b) Step 3b will always be successful since the graph is connected, any remaining edges must connect to the currently found circuit. (c) Step 2 and 3c will always be successful – a new circuit can always be found since the degree of the vertex u is even. n 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’’:

31 2.3 Example n (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 a b c d e f g h j i VertexDegree a2a2 b2b2 c2c2 d4d4 e4e4 f2f2 g2g2 h4h4 i2i2 j2j2 Even

32 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit?

33 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit? C = a b c d a

34 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit? C = a b c d a C’ = d e g h j i d C’’ = a b c d e g h j i d a

35 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit? C = a b c d e g h j i d a

36 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit? C = a b c d e g h j i d a C’ = e f h e C’’ = a b c d e f h e g h j i d a

37 2.3 Example n (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 a b c d e f g h j i Q: Where is the Circuit? C = a b c d e f h e g h j i d a C is the Euler Circuit

38 2.3 Example n (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.

39 2.4. Euler Path (Definition) n 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. n 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.

40 2.5 Euler Path Theorem n (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. n Euler Path theorem is a COROLLARY (a consequence, a result) of Euler Circuit theorem. n Proof is left as an exercise (You need to use the Euler circuit theorem to prove the Euler Path theorem).

41 2.6 Euler Path Theorem (Example) n (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. a b cd ef gh j i k Q: Where is the Path?

42 2.6 Euler Path Theorem (Example) n (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. a b cd ef gh j i 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. k Q: Where is the Path? A: a g h i e h f a

43 2.6 Euler Path Theorem (Example) n (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. a b cd ef gh j i 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. k Q: Where is the Path? A: a g h i e h f ab f e k j d b c d

44 3.1. Hamiltonian Circuit (Definition) n 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) n 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!)

45 3.2 Hamiltonian Circuit (Examples) g b d a f e c h Q: Is there a Hamiltonian circuit? gbdafhecg A: Yes

46 3.3 Hamiltonian Circuit (Theorem?) n 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 n A: Don’t know. No choice but to try all possible ways. n Q: Are there special types of graphs which definitely have Hamiltonian circuits? n A: Yes. n Q: What are they? n A: Graphs of some forms of geometric solids. (i) Platonic Solids; (ii) Archimedian solids

47 3.3 Hamiltonian Circuit (Special Cases) (i) Platonic Solids:

48 3.3 Hamiltonian Circuit (Special Cases) (ii) Archidemian Solids:

49 3.4. Hamiltonian Path (Definition) n Definition: Let G=(V,E) be a graph. A HAMILTONIAN Path for G is a elementary path that contains every vertex in V. n 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!)

50 3.5 Hamiltonian Path (Example) n Example: The following graph does not have a Hamiltonian circuit. g b d a f e c h Q: But does it have a Hamiltonian Path from a to c? A: Yes: a e h f d b g c

51 3.5 Hamiltonian Path (Example) n Example: The following graph does not have a Hamiltonian circuit. g b d a f e c h Q: Does it have a Hamiltonian Path from a to g? A: No.

52 3.5 Hamiltonian Path (Example) n Example: The following graph does not have a Hamiltonian circuit. g b d a f e c h Q: Can there be Hamiltonian Paths starting from g? A: No.

53 3.5 Hamiltonian Path (Example) n Example: The following graph does not have a Hamiltonian circuit. g b d a f e c h Q: Can there be Hamiltonian Paths ending at d? A: No.

54 3.5 Hamiltonian Path (Example) n Example: The following graph does not have a Hamiltonian circuit. g b d a f e c h Q: Can there be a Hamiltonian Path ending at ‘a’? A: Yes. Example: b g c d f e h

55 3.6 Hamiltonian Path (Theorem) n 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 n Notes: (Sufficient condition:) Property  Hamiltonian Path (Necessary condition:) Property ← Hamiltonian Path (Sufficient and necessary condition:) Property ↔ Hamiltonian Path

56 3.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 ….

Download ppt "1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3."

Similar presentations