Created
August 6, 2012 18:51
-
-
Save fredhsu/3277511 to your computer and use it in GitHub Desktop.
Eulerian Tour Recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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