Skip to main content

Eulerian Path and Eulerian Circuit - Fleury's Algorithm

Definition​

Fleury's Algorithm is a method for finding Eulerian paths and circuits in a graph. It's particularly useful when dealing with graphs that have a mix of even and odd degree vertices

Practice​

fleury(graph):
initialize empty list path
current_vertex = any_vertex_with_odd_degree(graph) or any_vertex(graph)
while graph has edges:
if current_vertex has unvisited edges:
next_vertex = choose_edge(current_vertex, graph)
remove_edge(current_vertex, next_vertex, graph)
add current_vertex to path
current_vertex = next_vertex
else:
add current_vertex to path
break
return path

choose_edge(vertex, graph):
for each adjacent_vertex of vertex:
if removing_edge(vertex, adjacent_vertex, graph) does not disconnect graph:
return adjacent_vertex
return any adjacent_vertex

removing_edge(vertex1, vertex2, graph):
remove edge between vertex1 and vertex2 from graph temporarily
check if graph is still connected
restore edge between vertex1 and vertex2 in graph
return true if graph is still connected, false otherwise

any_vertex_with_odd_degree(graph):
for each vertex in graph:
if degree of vertex is odd:
return vertex
return null