Chapter 2 Page 1 of 18 Chapter 2 Euler Circuits Spring 2016 1/15/16 Learning Objectives: Students will demonstrate familiarity with the terminology of graph theory and be able to model real life problems using graphs; understand the meaning and use of Euler circuits and paths and know when an Euler circuit or path is appropriate to use in solving a real life problem; apply Euler’s Theorems to identify the presence of Euler circuits and paths in graphs; find Euler circuits and paths in graphs and Eulerize and semi-Eulerize graphs. Chapter 2 Page 2 of 18 CHAPTER 2 - Routing Problems - find best route (Euler Circuit or Euler Path) through city for garbage, mail, snowplow, police patrol, street sweeper, bus route, delivery van, etc. Graph - think of it as a street map to be traveled by a delivery person that is required to travel each street once. A B C Line & vertex graph of above G D E F Definitions: B A F E C D AB, BC, DE, are edges (similar to streets). Edge length, shape is unimportant in this chapter. EE is a special edge called a loop. A, B, C, are each a vertex (street corner) - plural of vertex is “vertices”. Vertex F is disconnected. A and B are adjacent to each other, A and E aren’t. ABCA is a circuit (route that starts and ends at same vertex) BEDAB is another circuit. ABC is a path (route that starts at one vertex and ends at another) CBE is another path. Chapter 2 Page 3 of 18 degree = 4 B Vertex B has a degree of “4” - 4 edges touch it. Vertex C has a degree of 3, E has a degree of 4, A has a degree of 3. D has a degree of 2. F has a degree of 0. Graph (street map) A2 B3 C3 Note there is no vertex connecting BE with AD. They don’t touch each other.... - one is passing over the top of the other. E2 D4 C2 Graph (street map) B3 Edge HA is a bridge (if erased, graph is disconnected) H3 D3 G2 A3 H2 F3 G4 E3 Edge EF is a bridge (if erased, graph is disconnected) Euler Circuit - a circuit is a route that travels on each edge of a graph once, and only once. This is the most efficient route for a truck driver. Euler’s Circuit Theorem - A graph will have an Euler circuit if every vertex degree is even (2,4,6,etc) degree degree K=2 R=2 A=2 C=2 B=4 J=2 K-A-B-C-J-B-R-K is an Euler circuit. It starts at a vertex K, travels each edge once and only once, and returns back to start vertex K. Note- Every vertex is even degree. Chapter 2 Page 4 of 18 Euler Path - a route that starts at one vertex, which travels on each edge of entire graph, once and only once, and ends at a vertex that is different than the start vertex. This is the most efficient route for a truck driver if he/she wants to end someplace other than where he/she started. Euler’s Path Theorem - A graph will have an Euler path if every vertex except for (2) of them, is even (2,4,6,etc) degree. And.....the (2) odd degree vertices will be the start and end points. degree K2 A2 C 2 J2 R3 B5 Odd degree Fleury’s Algorithm - not covered this course R-K-A-B-C-J-B-R-B is an Euler path start at vertex R travel every edge once and only once return to some other vertex B Note- Every vertex is even degree except R and B Chapter 2 Page 5 of 18 Solutions 3c.) Determine the degree of each vertex: A(3) B(2) C(0) X(4) Y(3) Z(1) D(1) 20.) Draw a line-vertex model of map North Royalton A B C South Royalton Answer: shape/length of edge unimportant 5 vertices 8 edges A NR B C SR 29a.) Does graph have an Euler circuit, Euler path, neither, both? 2 4 2 4 4 4 4 4 2 Answer: graph has EULER CIRCUIT all vertices are even degree. No graph can have both. 4 4 2 Chapter 2 Page 6 of 18 29b.) Does graph have an Euler circuit, Euler path, neither, both? Answer: NEITHER Graph has no Euler Circuit because there are odd degree vertices Graph has no Euler Path because it doesn’t have 2 odd degree vertices. No graph can have both. 3 4 3 4 2 4 4 4 4 2 4 3 4 3 30a.) Does graph have an Euler circuit, Euler path, neither, both? Answer: Graph has an Euler Path because there are 2 odd degree vertices. Graph has no Euler Circuit because there are odd degree vertices. No graph can have both. 2 4 4 2 8 3 4 3 6 Chapter 2 Page 7 of 18 35.) Simplified problem: find an Euler Circuit in this graph. If there are all even degrees, start anywhere….travel each edge once. I started here must end here 1 12 4 5 2 9 10 11 3 8 6 7 …there are 100’s of correct answers 37.) Simplified problem: find an Euler Path: ...is there 2 odd degree vertices, and all the others even? Yes. Must start at one odd degree vertex, and end at the other. Travel each edge once. odd 14 5 6 9 11 13 12 4 8 7 2 10 1 3 odd …there are 100’s of correct answers Chapter 2 Page 8 of 18 Optimal Eulerizing - modify a graph so it will have an euler circuit in it - add the MINIMUM number of extra edges, so that each vertex is even degree. Procedure for optimal eulerizing: 1.) count the degree of each vertex; identify all odd degree vertices 2.) change all odd degree vertices to even by adding minimum of extra edges (dashed lines). - an extra edge must be a repeat of an existing edge. It can’t be an edge that doesn’t already exist. - length of line is unimportant - all lines are considered to be same length regardless how long they appear to be drawn. Shape of line is unimportant – curved, wavy, straight are all same. - this method is trial and error and it doesn’t tell you when you’ve reached the minimum number of extra edges Example: A C B D step (1) A3 B2 must change 2 vertices to even C2 step (2) A34 D3 B2 the dash tells you edge AD must be travelled twice C2 D34 Graph will now have an Euler circuit but it will require travelling edge AD twice. Chapter 2 Page 9 of 18 Example: A B C G D E Step 1: A3 B5 F C2 must change 4 vertices to even G4 D3 E4 F3 Step 2: change all odd degree vertices to even by adding minimum of extra edges (dashed lines). A34 B56 C2 DF is impossible, doesn’t exist G4 D34 E4 F34 Try again A34 B56 C2 added 3 edges G4 D34 E45 F34 Graph will now have an Euler circuit but it will require travelling 3 edges twice: AB, DE, and EF. Chapter 2 Page 10 of 18 Another example: graph step 1 5 must change 2 vertices to even 1 4 4 4 4 step 2 56 edge is impossible, doesn’t exist 12 4 4 4 4 4 4 Try again 56 12 added 5 edges 46 46 4 46 46 4 Chapter 2 Page 11 of 18 Try again 56 12 4 4 4 added 2 edges 46 Graph will now have an Euler circuit but it will require travelling 2 edges twice. Another example City Street Map: 17 Streets to sweep. Your job: Start at Garage, sweep all 17 streets once, and return back into Garage. If you must travel some streets twice, ensure that is minimum number streets. Street sweeper GARAGE B C D H E I J F W Step 1 G2 B5 C3 must change 8 vertices to even D3 H5 E3 I3 J4 F3 W3 Chapter 2 Page 12 of 18 Step 2: G2 B56 C34 No: EH is an impossible edge…. D34 it doesn’t exist in original graph H56 E34 I34 J4 F34 W34 try step 2 again G2 B56 C34 D34 H56 E34 I34 J46 F34 Try step 2 again added 5 edges (too many) W34 G2 B6 C4 D4 H6 E4 I4 added only 4 edges J4 F4 W4 There will be an Euler circuit in this graph but it requires you travel 4 streets (DE, BH, CI, FW dashed lines) twice. Chapter 2 Page 13 of 18 Practice problems 1.) Optimally eulerize see Notes 2.) Optimally eulerize see Notes 43.) Optimally eulerize: 2 3 4 3 4 3 4 3 4 2 3 4 4 4 4 4 3 4 3 4 4 4 4 4 3 4 2 3 4 3 4 3 4 3 4 added 6 edges 2 Chapter 2 Page 14 of 18 Optimal Semi-Eulerizing Graphs - modify the graph by adding the MINIMUM number of extra edges, so that each vertex, except for start and end, is even degree. Procedure for optimal eulerizing: 1.) determine degree of each vertex, identify start and end vertices, 2.) change all odd degree vertices to even except for start and end, by adding minimum of extra edges (dashed lines). - length of line is unimportant - all lines are considered to be same length regardless how long they appear to be drawn. Shape of line is unimportant – curved, wavy, straight are all same. - an extra edge must be a repeat of an existing edge. It can’t be an edge that doesn’t already exist. - this method is trial and error and it doesn’t tell you when you’ve reached the minimum number of extra edges Example: end here to go to next neighborhood Start here A B C must be odd G D E must be odd all others must be even F Chapter 2 Page 15 of 18 Step 1: determine degree of each vertex, identify start and end vertices (end) A3 B5 C 2 must be odd G4 D3 E4 F3 (start) must be odd Step 2: change all odd degree vertices to even except for start and end, by adding minimum of extra edges (dashed lines). A 34 B5 C 23 EC is impossible. Not existing G4 D 34 E 45 A 34 B58 F 34 Try again C 23 added 4 edges G4 D34 E45 A 34 B 56 F34 Try again C 23 G4 D 34 added 3 edges E 45 F 34 There will be an Euler path that starts at E and ends at C. 3 edges must be travelled twice Chapter 2 Page 16 of 18 Example - Start truck at Warehouse (W), and end at a repair station (N)..... Optimal Semi-Eulerize the graph so that it will have an euler path that starts at W and ends at N A H B G C W Warehouse E D L I F K M N repair station Step 1: determine degree of each vertex, identify start and end vertices, W1 start must be odd A2 H3 B3 G4 C4 E5 D2 L2 I2 F3 K3 M2 N2 end must be odd Step 2: change all odd degree vertices to even except for start and end, by adding minimum of extra edges (dashed lines). W1 must be odd A2 H34 B34 G45 C4 E56 K34 I2 D2 added 5 edges each travelled twice L2 F34 M 24 N 23 must be odd Chapter 2 Page 17 of 18 Practice problems: 1.) Optimally semi-eulerize this graph with vertex C and E being start and end: C see Notes E 2.) Optimally semi-eulerize this graph with vertex W and N being start and end: W see Notes N 3.) Optimally semi-eulerize this graph with vertex X and Y being start and end: Y X Ans. 12 12 Y odd 46 X 3 odd 45 56 Chapter 2 Page 18 of 18 4.) Optimally semi-eulerize this graph with vertex Q and R being start and end: R Q Ans. It’s already optimally semi eulerized. 4 4 6 Q3 4 R3 4 50.) Optimally Semi-Eulerize this graph. Euler path must start at A and end at B A B Ans. 4 2 2 3 odd A 4 3 2 3 4 4 4 3 4 4 4 4 4 4 4 4 2 odd B 3 4 3 4 4 4 3 3 2 4 2 3 4 3 2 4 4 added 5 duplicates