1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

CSE 211 Discrete Mathematics
Discrete Mathematics University of Jazeera College of Information Technology & Design Khulood Ghazal Connectivity Lecture _13.
Chapter 8 Topics in Graph Theory
Chapter 9 Graphs.
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Graph-02.
 期中测验时间:本周五上午 9 : 40  教师 TA 答疑时间 : 周三晚上 6 : 00—8 : 30  地点:软件楼 315 房间,  教师 TA :李弋老师  开卷考试.
1 Slides based on those of Kenneth H. Rosen Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Graphs.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
1 Lecture 5 (part 2) Graphs II Euler and Hamiltonian Path / Circuit Reading: Epp Chp 11.2, 11.3.
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Applied Discrete Mathematics Week 12: Trees
Discrete Structures Chapter 7B Graphs Nurul Amelina Nasharuddin Multimedia Department.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
Representing Graphs Wade Trappe. Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix.
Math Foundations Week 12 Graphs (2). Agenda Paths Connectivity Euler paths Hamilton paths 2.
CTIS 154 Discrete Mathematics II1 8.2 Paths and Cycles Kadir A. Peker.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 5,Wednesday, September 10.
Applied Discrete Mathematics Week 12: Trees
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Discrete.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Let us switch to a new topic:
Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday.
GRAPH Learning Outcomes Students should be able to:
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
(CSC 102) Lecture 29 Discrete Structures. Graphs.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Based on slides by Y. Peng University of Maryland
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Graphs What are Graphs? General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Lecture 52 Section 11.2 Wed, Apr 26, 2006
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
Chapter 9: Graphs.
Great Theoretical Ideas in Computer Science for Some.
COMPSCI 102 Introduction to Discrete Mathematics.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
1. 期中测验时间和地点: 11 月 4 日, 上午 9:40—11 : 40 地点: 教室 2. 答疑时间和地点: 1)11 月 1 日 ( 周五 )13:00—15:00 软件楼 319 2)11 月 2 日和 3 日, 14:00—17:00 软件楼 3 楼 机房讨论室.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Graphs. Representations of graphs : undirected graph An undirected graph G have five vertices and seven edges An adjacency-list representation of G The.
An Introduction to Graph Theory
Matrix Representation of Graphs
Applied Discrete Mathematics Week 13: Graphs
Graphs Hubert Chan (Chapter 9) [O1 Abstract Concepts]
Euler Paths and Circuits
Graphs Rosen, Chapter 8.
Graph theory Definitions Trees, cycles, directed graphs.
Discrete Structures – CNS2300
Based on slides by Y. Peng University of Maryland
Representing Graphs Wade Trappe.
Euler and Hamilton Paths
Graphs G = (V, E) V are the vertices; E are the edges.
Chapter 5 Graphs the puzzle of the seven bridge in the Königsberg,
Applied Discrete Mathematics Week 13: Graphs
Presentation transcript:

1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2,

2 A. Circuits 1.Definitions and examples of Closed Walk, Circuit, Simple Circuit 2.A special kind of circuit – Euler circuit 3.A special kind of simple circuit – Hamiltonian circuit

3 1. Closed Walk, Circuit, Simple Circuit n Definition: Given a graph G=(V,E), a closed walk is a walk that starts and ends at the same vertex: i.e. it is a sequence v 0 e 1 v 1 e 2 v 2 … e n-1 v n-1 e n v 0 where n  0, v i  V, e i ={v i-1,v i }  E (i  1..n-1) When obvious, we shorten it the closed walk to: v 0 v 1 v 2 … v n-1 v 0 n If all the edges in the closed walk are distinct, then the closed walk is a circuit. n If all the vertices in the closed walk are distinct (with exception of the first and last) then the closed walk is a simple circuit. n The length of the closed walk / circuit / simple circuit is the number of edges in the closed walk / circuit / simple circuit.

4 1. Closed Walk, Circuit, Simple Circuit Closed Walk Circuit (edges distinct) Simple Circuit (vertices distinct)

5 1. Closed Walk, Circuit, Simple Circuit No YesNo Yes No Yes Closed Walk Circuit Simple Circuit Length of closed walk 6 6 5

6 A. Circuits 1.Definitions (Closed Walk, Circuit, Simple Circuit) and Examples 2.A special kind of circuit 2.1 Definition of Euler Circuit 2.2 Euler Circuit Theorem and Proof 2.3 Examples 2.4 (Related) Definition of Euler Path 2.5 Euler Path Theorem 2.6 Example 3.A special kind of simple circuit 3.1 Definition of Hamiltonian Circuit 3.2 Examples 3.3 Special Examples 3.4 (Related) Definition of Hamiltonian Path 3.5 Examples

7 2. Euler Circuit Leonhard Euler (pronounced OIL-er) , 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?”

8 2.1 Euler Circuit (Definition) n Definition: Let G=(V,E) be a graph. An EULER CIRCUIT for G is a circuit that contains every vertex in V and every edge in E. n Implications: –‘Circuit’: edges must be distinct… At most 1 traversal of each edge. –‘every edge in E’: … At least 1 traversal of each edge. –‘every vertex in V’: … At least 1 traversal of each vertex.

9 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

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 walk from x = v i e i+1 v i+1 … e j v j = y If i  j then we have a walk from x = v i e i v i-1 … e j+1 v j = y n Therefore there is a walk from x to y in V. n Therefore G is connected (by definition of connected graph).

Euler Circuit Theorem (Proof  ) Proof (  ): Assume G=(V,E) has an Euler circuit. Show (1) G is connected, (2) (  v  V, deg(v) = 2k) Before we prove (2)… Note that any vertex in a circuit can be the starting vertex

Euler Circuit Theorem (Proof  ) Proof (  ): Assume G=(V,E) has an Euler circuit. Show (1) G is connected, (2) (  v  V, deg(v) = 2k) So in general, all these refer to the same circuit: v 0 e 1 v 1 e 2 v 2 … e n-1 v n-1 e n v 0 v 1 e 2 v 2 … e n-1 v n-1 e n v 0 e 1 v 1 ….. v n-1 e n v 0 e 1 v 1 e 2 v 2 … e n-1 v n-1 It just depends on which vertex you want to take as the starting vertex.

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.

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

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

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!!!

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.

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 v v Proof: (The algorithm)

19 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 C: v v Proof: (The algorithm)

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 C: v v Proof: (The algorithm) G

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’ C: v v Proof: (The algorithm) G’

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’ C: v v u = Proof: (The algorithm)

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’ C: v v u = Proof: (The algorithm)

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’ C: v vC’: u = Proof: (The algorithm)

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’’: C: v vC’: u = Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v C’’: v Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u C’’: v Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u C’’: v Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u (iii) Follow C’ from u all the way back to u C’’: v Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u (iii) Follow C’ from u all the way back to u C’’: v Proof: (The algorithm)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u C’’: 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)

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 C: v vC’: u = (i) Start at v (ii) Follow C to u C’’: v 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)

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 C : v v Proof: (The algorithm)

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 C : v v Proof: (The algorithm)

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.

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’’:

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’’:

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

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?

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

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

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

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

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

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.

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 path starting from v and ending at u and contains every vertex in V and every edge in E. n Implications: –‘Path’: edges must be distinct… At most 1 traversal of each edge. –‘every edge in E’: … At least 1 traversal of each edge. –‘every vertex in V’: … At least 1 traversal of each vertex.

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

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?

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

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

51 A. Circuits 1.Definitions (Closed Walk, Circuit, Simple Circuit) and Examples 2.A special kind of circuit 2.1 Definition of Euler Circuit 2.2 Euler Circuit Theorem and Proof 2.3 Examples 2.4 (Related) Definition of Euler Path 2.5 Euler Path Theorem 2.6 Example 3.A special kind of simple circuit 3.1 Definition of Hamiltonian Circuit 3.2 Examples 3.3 Special Examples 3.4 (Related) Definition of Hamiltonian Path 3.5 Examples

Hamiltonian Circuit (Definition) n Definition: Let G=(V,E) be a graph. A HAMILTONIAN CIRCUIT for G is a simple circuit that contains every vertex in V. (Sir William Hamilton , Irish) n Implications: –‘Simple circuit’: vertices must be distinct… –AT MOST ONE traversal of each vertex –‘every vertex in V’: … –AT LEAST ONE traversal of each vertex –‘Simple circuit’: (edges distinct of course!)

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

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

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

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

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

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

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.

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.

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.

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

63 B. Graph Representation 1.Graph Representation using Matrices 2.Using matrices to find information. 2.1 Q: Is the graph directed or undirected? 2.2 Q: How many connected components are there? 2.3 Q: Is there a walk of length n from v to u?

64 1. Graph Representation using matrices n There are 2 main ways to represent graphs in the computer: –Use a 2D array. –Use an adjacency lists. (Graph implementation taught in cs1102) n Using a 2D array corresponds to using a adjacency matrix representation. n IMPT: We assume you know (1) basic matrix terminology and (2) matrix multiplication (Please refer to p for your personal revision, if you need to).

65 1. Graph Representation using matrices n An m x n matrix A over a set S, is a rectangular array of elements of S arranged into m rows and n columns.

66 1. Graph Representation using matrices n A graph with n vertices can be represented using a n x n adjacency matrix. n Each entry a ij of the matrix is used to indicate the presence or absence of an edge from v i to v j. v1v1 v2v2 v3v3 v4v4 v5v5

67 2. Using matrices to find information n Let A be the adjacency matrix representation of some graph G. n Looking only at the matrix (i.e. do not draw the graph), how do we know… Q1: … whether the graph is directed or undirected? Q2: … how many connected components are there in the graph? Q3: … whether is there a walk of length w from v i to v j ?

Directed or undirected graph? n Q1: How do we know whether the graph is a directed or an undirected graph? A: The graph is undirected iff  i,j, a ij = a ji. v1v1 v2v2 v3v3 v4v4 v5v5 “Symmetric”

Directed or undirected graph? n Q1: How do we know whether the graph is a directed or an undirected graph? A: The graph is undirected iff  i,j, a ij = a ji. v1v1 v2v2 v3v3 v4v4 v5v5 “NOT Symmetric”

Directed or undirected graph? n Q1: How do we know whether the graph is a directed or an undirected graph? A: The graph is undirected iff  i,j, a ij = a ji. Why? If there is an edge from v i to v j, (a ij = 1) and since the graph is undirected, then there is also an edge from v j to v i (a ji = 1). Similarly, if there is no edge from v i to v j, (a ij = 0) then there is also no edge from v j to v i (a ji = 0).

How many connected components? n Q2: How do we know how many connected components are there in the graph? v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7

How many connected components? n Q2: How do we know how many connected components are there in the graph? v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7

How many connected components? n Q2: How do we know how many connected components are there in the graph? v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7

How many connected components? n Q2: How do we know how many connected components are there in the graph? v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7

How many connected components? n Q2: How do we know how many connected components are there in the graph? v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 3 connected components

How many connected components? n In general, if the graph has k connected components, each with n i vertices then there exist a way to swap the rows and columns of the matrix so that the vertices of the connected components are arranged together, resulting in a matrix of the form: Each A i is a adjacency matrix of n i vertices. Each O is a matrix with all entries as 0.

How many connected components? n ‘There exists a way’ doesn’t tell you how to deterministically find ‘the way’. (Not part of our syllabus). n There are algorithms which break a graph into connected components (which will be covered in other courses)

Walk from v i to v j of length w? n Q3: How do we know whether there is a walk from v i to v j of length w? v1v1 v2v2 v3v3 v4v4 v5v5 Q: Is there a walk from v 1 to v 2 of length 1? A: Yes. Q: Is there a walk from v 1 to v 2 of length 2? A: No. =

Walk from v i to v j of length w? n Q3: How do we know whether there is a walk from v i to v j of length w? v1v1 v2v2 v3v3 v4v4 v5v5 Q: Is there a walk from v 1 to v 2 of length 1? A: Yes. Q: Is there a walk from v 1 to v 2 of length 2? A: No. = Q: Is there a walk from v 2 to v 3 of length 2? A: Yes, 3 such walks.

Walk from v i to v j of length w? n Q3: How do we know whether there is a walk from v i to v j of length w? v1v1 v2v2 v3v3 v4v4 v5v5 Q: Is there a walk from v 1 to v 2 of length 3? A: Yes. Q: Is there a walk from v 2 to v 3 of length 3? A: No. = Q: How many of such walks? A: 6.

Walk from v i to v j of length w? Theorem: Let G = (V,E) and V = {v 1,v 2,…,v m } and let A be the adjacency matrix of G.  n >= 1, The i-j-th entry of A n = the number of walks of length n from v i to v j (  i,j  {1..m}) Proof by induction on n: Base case: (n=1) The i-j-th entry of A 1 = the number of walks of length 1 from v i to v j (  i,j  {1..m}) This is true since the i-j-th entry of A is 1 if there is an edge and 0 otherwise. If there is an edge, then there is a walk of length 1 from v i to v j.

Walk from v i to v j of length w? Theorem: Let G = (V,E) and V = {v 1,v 2,…,v m } and let A be the adjacency matrix of G.  n >= 1, The i-j-th entry of A n = the number of walks of length n from v i to v j (  i,j  {1..m}) Proof by induction on n: Inductive case: (k  k+1) Let a ij be used to denote elements in A. Let b ij be used to denote elements in A k. Let c ij be used to denote elements in A k+1. Assume: The i-j-th entry of A k = the number of walks of length k from v i to v j (  i,j  {1..m}) To Prove: The i-j-th entry of A k+1 = the number of walks of length k+1 from v i to v j (  i,j  {1..m})

Walk from v i to v j of length w? = AAkAk A k+1 i i jj a i1 b 1j + a i2 b 2j + a i3 b 3j + … + a im b mj = c ij a i1 a i2 a im b 1j b 2j b mj a i1 b 1j = # Walk of Length 1 from v i to v 1 x # Walk of Length k from v 1 to v j. (IH) = # Walk of Length k+1 from v i to v j with v 1 as 2 nd vertex

Walk from v i to v j of length w? = AAkAk A k+1 ii jj a i1 b 1j + a i2 b 2j + a i3 b 3j + … + a im b mj = c ij a i1 a i2 a im b 1j b 2j b mj a i2 b 2j = # Walk of Length 1 from v i to v 2 x # Walk of Length k from v 2 to v j.(IH) = # Walk of Length k+1 from v i to v j with v 2 as 2 nd vertex

Walk from v i to v j of length w? = AAkAk A k+1 ii jj a i1 b 1j + a i2 b 2j + a i3 b 3j + … + a im b mj = c ij a i1 a i2 a im b 1j b 2j b mj a i3 b 3j = # Walk of Length 1 from v i to v 3 x # Walk of Length k from v 3 to v j. (IH) = # Walk of Length k+1 from v i to v j with v 3 as 2 nd vertex

Walk from v i to v j of length w? = AAkAk A k+1 ii jj a i1 b 1j + a i2 b 2j + a i3 b 3j + … + a im b mj = c ij a i1 a i2 a im b 1j b 2j b mj a im b mj = # Walk of Length 1 from v i to v m x # Walk of Length k from v m to v j. (IH) = # Walk of Length k+1 from v i to v j with v m as 2 nd vertex

Walk from v i to v j of length w? = AAkAk A k+1 ii jj a i1 b 1j + a i2 b 2j + a i3 b 3j + … + a im b mj = c ij a i1 a i2 a im b 1j b 2j b mj All walks of length k+1 from v i to v j can only pass through v 1 to v m as their second vertex. (There are no other vertices to pass through). Therefore c ij will store the number of walks from v i to v j of length k+1. (Proven the k+1 case)

88 n End of Lecture