Graphs/Euler Circuit: Difference between revisions
From charlesreid1
| Line 24: | Line 24: | ||
To print the Euler Circuit of a graph (if it has one), you can use Fleury's Algorithm [https://www.geeksforgeeks.org/fleurys-algorithm-for-printing-eulerian-path/]. | To print the Euler Circuit of a graph (if it has one), you can use Fleury's Algorithm [https://www.geeksforgeeks.org/fleurys-algorithm-for-printing-eulerian-path/]. | ||
Step 1: Check that the graph has 0 or 2 odd vertices | Step 1: | ||
* Check that the graph has 0 or 2 odd vertices | |||
* If there are any other number of odd vertices, no Euler circuit exists | |||
Step 2: If there are 0 odd vertices, start at any node on the graph | Step 2: | ||
* If there are 0 odd vertices, start at any node on the graph | |||
* If there are 2 odd vertices, start at one of the odd vertices | |||
Step 3: Follow edges one at a time. If you have a choice | Step 3: | ||
* Follow edges one at a time. | |||
* Edges can be classified as bridges (edges that lead to "dead end" nodes with only one edge) or non-bridges | |||
* If you have a choice among multiple edges, choose the non-bridges first, leave the bridge edge for last. | |||
Step 4: Stop when you run out of edges. | Step 4: | ||
* Stop when you run out of edges. | |||
=Related= | =Related= | ||
Revision as of 22:59, 27 April 2019
Euler tour/Euler path - a tour around a graph that visits every edge of the graph exactly once.
- The following pages all redirect to Graphs/Euler Tour:
Euler circuit/Euler cycle - an Euler tour that starts and ends at the same vertex.
- The following pages all redirect to Graphs/Euler Circuit:
Overview
An Euler Circuit is an Euler path or Euler tour (a path through the graph that visits every edge of the graph exactly once) that starts and ends at the same vertex.
Algorithm
Fleury's Algorithm
To print the Euler Circuit of a graph (if it has one), you can use Fleury's Algorithm [1].
Step 1:
- Check that the graph has 0 or 2 odd vertices
- If there are any other number of odd vertices, no Euler circuit exists
Step 2:
- If there are 0 odd vertices, start at any node on the graph
- If there are 2 odd vertices, start at one of the odd vertices
Step 3:
- Follow edges one at a time.
- Edges can be classified as bridges (edges that lead to "dead end" nodes with only one edge) or non-bridges
- If you have a choice among multiple edges, choose the non-bridges first, leave the bridge edge for last.
Step 4:
- Stop when you run out of edges.
Related
Graphs:
- Graphs#Graph Traversals
- Graphs/Depth First Traversal
- Graphs/Breadth First Traversal
- Graphs/Euler Tour
- Graphs/Euler Circuit
Traversals on trees:
Breadth-first search and traversal on trees:
Depth-first search and traversal on trees:
OOP design patterns:
Flags