Created
April 24, 2015 07:57
-
-
Save yask123/d6b815c1352208ffdf79 to your computer and use it in GitHub Desktop.
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
graph = {'A': set(['B', 'C']), | |
'B': set(['A', 'D', 'E']), | |
'C': set(['A', 'F']), | |
'D': set(['B']), | |
'E': set(['B', 'F']), | |
'F': set(['C', 'E'])} | |
def dfs (graph,start,visited=None): | |
if visited is None: | |
visited=set() | |
visited.add(start) | |
for next in graph[start]-visited: | |
visited.add(next) | |
dfs(graph,next,visited) | |
return visited | |
print dfs(graph,'A') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment