Skip to content

Instantly share code, notes, and snippets.

@fredhsu
Created August 6, 2012 18:51
Show Gist options
  • Save fredhsu/3277511 to your computer and use it in GitHub Desktop.
Save fredhsu/3277511 to your computer and use it in GitHub Desktop.
Eulerian Tour Recursive
# Given a graph that is a list of edges between nodes
# i.e. [(0,1), (1,5), (5, 7), (7,1)]
def find_eulerian_tour(graph):
tour = []
find_tour(graph[0][0], graph, tour)
return tour
def find_tour(u, graph, tour):
for edge in graph:
if u == edge[0]:
graph.remove(edge)
find_tour(edge[1], graph, tour)
if u == edge[1]:
graph.remove(edge)
find_tour(edge[0], graph, tour)
tour.append(u)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment