150 likes | 939 Views
Euler Circuit . Chapter 5. Fleury’s Algorithm. Euler’s theorems are very useful to find if a graph has an Euler circuit or an Euler path when the graph is simple. However, for a complicated graph with hundreds of vertices and edges, we need an algorithm. Algorithm: A set of procedural rules
E N D
Euler Circuit Chapter 5
Fleury’s Algorithm • Euler’s theorems are very useful to find if a graph has an Euler circuit or an Euler path when the graph is simple. • However, for a complicated graph with hundreds of vertices and edges, we need an algorithm. • Algorithm: A set of procedural rules • Examples • The instruction of assembling a new bike, • Recipe for baking an apple pie
Fleury’s Algorithm • Finds an Euler circuit in a connected graph with no odd vertices. • Finds an Euler path in a connected graph with two odd vertices. • The idea behind the algorithm: Don’t burn your bridges behind you. A B Bridge You would only want to cross that bridge if you know that all edges in A have been traveled.
Fleury’s Algorithm • Bridges are the last edges we want to cross to find an Euler circuit. • The graph whose bridges we are supposed to avoid is not necessarily the original graph of the problem. Instead it is that part of the original graph which has yet to be traveled. • Once we travel along an edge, we are done with it. • Each time we traverse an edge, the untraveled part of the graph changes and its bridges are changing. • We start with 2 copies of the graph: copy 1 for making decisions and copy 2 for record keeping.
B B C D C D E F E F Fleury’s Theorem • Every time we traverse another edge, we erase it from copy 1 but mark (red) and level it with the appropriate number on copy 2. • Copy 1 gets smaller and cop2 gets redder. • Copy 1 helps us decide where to go next; copy 2 helps us reconstruct our trip. Copy 2 Copy 1 A Start at F (arbitrarily)
Fleury’s Theorem Copy 1 Copy 2 A A B B C D C D E F E F Step 1: Travel from F to C Could have also travel from F to D
Fleury’s Theorem Copy 1 Copy 2 A A B B 2 C D C D 1 E F E F Step 2: Travel from C to D Could have also travel to A or to E
Fleury’s Theorem Copy 1 Copy 2 A A B B 3 2 D C C D 1 E F E F Step 3: Travel from D to A Could have also travel to B but not to F – DF is a bridge!
Fleury’s Theorem Copy 1 Copy 2 A A B B 3 4 2 C D C D 1 E F E F Step 4: Travel from A to C Could have also travel to E but not to B – AB is a bridge!
Fleury’s Theorem Copy 1 Copy 2 A A B B 3 4 2 C D C D 5 1 E F E F Step 5: Travel from C to E There is no choice!
Fleury’s Theorem Copy 1 Copy 2 A 7 B 3 4 8 6 2 C D 5 9 1 E F Steps 6, 7, 8, and 9: Only one way to go at each step
Fleury’s Algorithm for finding Euler circuit • First make sure that the graph is connected and all the vertices have even degree. • Pick any vertex as the stating point • When you have a choice, always choose to travel along an edge that is not a bridge of the yet-to-be-traveled part of the graph • Label the edges in the order in which you travel them • When you cannot travel any more, stop. You are done.
Fleury’s Algorithm for finding Euler path • First make sure that the graph is connected and have exactly two vertices of odd degree. • Pick any vertex of the two vertices of odd degree as the stating point. • When you have a choice, always choose to travel along an edge that is not a bridge of the yet-to-be-traveled part of the graph • Label the edges in the order in which you travel them • When you cannot travel any more, stop. You are done. • When steps are followed properly, the trip will guaranteed to end at the other vertex of odd degree.