500 likes | 507 Views
Learn how to find Euler paths and circuits in graphs using Euler's theorem. Identify the conditions for the existence of an Euler path or circuit and apply the algorithm to solve sample problems.
E N D
Pencil Drawing Problem-Euler Paths Which of the following pictures can be drawn on paper without ever lifting the pencil and without retracing over any segment?
Definitions • An Euler path is a path that passes through each edge of a graph exactly one time. • An Euler circuit is a circuit that passes through each edge of a graph exactly one time. • The difference between an Euler path and an Euler circuit is that an Euler circuit must start and end at the same vertex.
Example: Recognizing Euler Circuits • Consider the graph below. • Is • an Euler circuit? • b) Does the graph have an Euler circuit? E F D A C B
Example: Recognizing Euler Circuits Solution a) No, it does not use edge BD. b) Yes, the circuit is an Euler circuit. E F D A C B
Examples • Euler path • Euler circuit
Euler Theorem • Euler’s Theorem • The following statements are true for connected graphs: • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other. • If a graph has no odd vertices (all even vertices), it has at least one Euler circuit. An Euler circuit can start and end at any vertex. • If a graph has more than two odd vertices, then it has no Euler paths and no Euler circuits.
Euler’s Theorem Suppose we have a connected graph. 1. If the graph has an Euler circuit, then each vertex of the graph has even degree. 2. If each vertex of the graph has even degree, then the graph has an Euler circuit.
Finding Euler Paths To find Euler paths, we’ll first give an algorithm for finding Euler cycles and then modify it to give Euler paths. THM: An undirected graph G has an Euler circuit iff it is connected and every vertex has even degree. NOTE: for directed graphs the condition is that G be weakly connected and that every vertex has same in-degree as out-degree.
Finding Euler Circuits Q: Why does the following graph have no Euler circuit?
Finding Euler Circuits A: It contains a vertex of odd degree.
Generalizing to Euler Paths Q: Does the following have an Euler circuit?
Generalizing to Euler Paths A: No, vertices of odd degree: Q: But why does it have an Euler path?
Generalizing to Euler Paths A: YES! Because exactly 2 vertices of odd degree. So can add a phantom edge between odd degree vertices:
Generalizing to Euler Paths All degrees now even so find Euler cycle:
Generalizing to Euler Paths Now remove phantom edge obtaining: 1 2 3 7 4 6 5
B A C B C A D D E Example: Using Euler’s Theorem • Use Euler’s theorem to determine whether an Euler path or an Euler circuit exists in the figures shown from the previous example.
B A C D Example: Using Euler’s Theorem continued • The graph has no odd vertices (all vertices are even). According to item 1, at least one Euler circuit exists. An Euler circuit can be determined by starting at any vertex. The Euler circuit will end at the vertex from which is started. Remember that each Euler circuit is also an Euler path.
B C A D E Example: Using Euler’s Theorem continued • There are 3 even vertices (A, B, C) and two odd vertices (D, E). Based on item 2, we conclude that since there are exactly two odd vertices, at least one Euler path exists but no Euler circuits exists. Each Euler path must begin at one of the odd vertices and end at the other odd vertex.
A B C E D Model Problem Explain why the graph has at least one Euler path. degree 2 number of edges at each vertex: degree 4 degree 4 2 A: D: 3 3 B: E: 4 C: 4 degree 3 Two odd vertices degree 3 • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other.
A B C E D Model Problem Find a Euler path. 6 5 2 3 7 4 1 8 C, E, C, A, B, D, E D, B,
degree 2 degree 2 Model Problem Explain why the graph has a least one Euler circuit. degree 4 degree 4 degree 2 degree 2 degree 4 degree 4 no odd vertices 2. If a graph has no odd vertices (all even vertices), it has at least one Euler circuit. An Euler circuit can start and end at any vertex.
Model Problem Find an Euler circuit. 11 10 12 9 13 3 8 4 2 14 1 7 5 6 G, C, G, I, J, H, D, C, A, B, D, F, H H, E, Euler Circuit – a circuit that travels through every edge of a graph once and only once, and must begin and end at the same vertex.
degree 3 Model Problem A, B, C, and D represent rooms. The outside of the house is labeled E. The openings represent doors. a) Is it possible to find a path that uses each door exactly once? degree 6 look for a Euler path or circuit exactly 2 odd vertices • If a graph has exactly two odd vertices, then it has at least one Euler path, but no Euler circuit. Each Euler path must start at one of the odd vertices and end at the other.
Model Problem A, B, C, and D represent rooms. The outside of the house is labeled E. The openings represent doors. b) If possible, find such a path. 10 9 7 2 1 3 8 6 4 5 start at one of the odd vertices E, B, D, C, A, E, C, E, D B, A,
Fluery’s Algorithm • If Euler’s Theorem indicates the existence of an Euler path or Euler circuit, one can be found using the following procedure. • If the graph has exactly two odd vertices, chose one of the two odd vertices as the starting point. If the graph has no odd vertices, choose any vertex as the starting point. • Number edges as you trace through the graph according to the following rules: • After you traveled over an edge, change it to a dashed line. • When faced with a choice of edges to trace, choose an edge that is not a bridge (an edge, which, if removed from a connected graph would leave behind a disconnected graph). Travel over an edge that is a bridge only if there is no alternative.
Fleury’s Algorithm • To determine an Euler path or an Euler circuit: 1. Use Euler’s theorem to determine whether an Euler path or an Euler circuit exists. If one exists, proceed with steps 2-5. 2. If the graph has no odd vertices (therefore has an Euler circuit, which is also an Euler path), choose any vertex as the starting point. If the graph has exactly two odd vertices (therefore has only an Euler path), choose one of the two odd vertices as the starting point.
Fleury’s Algorithm continued 3. Begin to trace the edges as you move through the graph. Number the edges as you trace them. Since you can’t trace any edges twice in Euler paths and Euler circuits, once an edge is traced consider it “invisible.” 4. When faced with a choice of edges to trace, if possible, choose an edge that is not a bridge (i.e., don’t create a disconnected graph with your choice of edges). 5. Continue until each edge of the entire graph has been traced once.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Preliminaries. Make sure that the graph is connected and either (1) has no odd vertices (circuit), or (2) has two odd vertices (path).
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Start. Choose a starting vertex. [ In case (1) this can be any vertex; in case (2) it must be one of the two odd vertices.]
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • Intermediate steps. At each step, if you have a choice, don’t choose a bridge of the yet-to-be-traveled part of the graph. However, if you have only one choice, take it.
Euler Circuits Fleury’s Algorithm for Finding an Euler Circuit (Path) • End. When you can’t travel any more, the circuit (path) is complete. [In case (1) you will be back at the starting vertex; in case (2) you will end at the other odd vertex.]
B A C F D G E Example • Use Fluery’s algorithm to determine an Euler circuit. • There is at least one Euler circuit since there are no odd vertices. • Start at any vertex to determine an Euler circuit.
start here 10 6 9 1 5 7 B 4 A C 8 2 3 F D G E Example continued • Start at C. • Choose either CB or CD. Continue to trace from vertex to vertex around the outside of the graph.
start here 10 6 9 1 5 7 B 4 A C 8 2 3 F D G E Example continued • Start at C. • Choose either CB or CD. Continue to trace from vertex to vertex around the outside of the graph.
7 3 8 4 2 6 1 5 9 Model Problem The graph has at least one Euler circuit. Find it using Fleury’s Algorithm. F E D C A B no odd vertices, begin at any vertex.
Fleury's Algorithm: O(E)? • Pick any vertex to start. • From that vertex pick an edge to traverse, considering following rule: never cross a bridge of the reduced graph unless there is no other choice. • Darken that edge, as a reminder that you can't traverse it again. • Travel that edge, coming to the next vertex. • Repeat 2-4 until all edges have been traversed, and you are back at the starting vertex. By reduced graph we mean the original graph minus the darkened (already used) edges. A bridge of a graph G is an edge whose deletion increases the number of components of G.
Fleury's Algorithm in Action Pick any vertex (e.g. F) Take F to C (arbitrary) Take C to D (arbitrary) Take D to A (arbitrary) A bridge is not a local property (i.e. if edge EF existed then AB would not be a bridge). How can we recognize a bridge efficiently? In the original graph, AB was not a bridge. Can we preprocess the graph in O(E) time identifying bridges and building a structure that can be updated in constant time with each reduction? Take A to C. Can't go to B: that edge is a bridge of the reduced graph, and there are two other choices.
Euler Paths and CircuitsDefinition DEF: An Euler path in a graph G is a simple path containing every edge in G. An Euler circuit (or Euler cycle) is a cycle which is an Euler path. NOTE: The definition applies both to undirected as well as directed graphs of all types.
Euler Circuits Eulerizing Graphs Our first step is to identify the odd vertices. This graph has eight odd vertices (B,C,E,F,H,I,K,and L), shown in red.
Euler Circuits Eulerizing Graphs When we add a duplicate copy of edges BC,EF,HI, and KL, we get this graph. This is the eulerized version of the original graph.
Euler Circuits Eulerizing Graphs This graph shows the many possible Euler circuits,with the edges numbered in the order they are traveled..
Euler Circuits Eulerizing Graphs With the four duplicate edges (BC,EF,HI,and KL) indicating the deadhead blocks where a second pass is required. The total length of this route is 28 blocks (24 blocks in the grid plus 4 deadhead blocks).
Euler Circuits Eulerizing Graphs In some situations we need to find an exhaustive route, but there is no requirement that it be closed—the route may start and end at different points.
Euler Circuits Eulerizing Graphs In these cases, we want to leave two odd vertices on the graph unchanged, and change the other odd vertices into even vertices.
Euler Circuits Eulerizing Graphs This process id called a semi-eulerization of the graph. In this case the route will start at one of the two odd vertices and end at the other one.