Created
April 21, 2015 08:15
-
-
Save yask123/cedc8944b3460f0970f4 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'])} | |
s= 'A' | |
visited = set() | |
stack = [s] | |
while stack: | |
vertex = stack.pop() | |
if vertex not in visited: | |
visited.add(vertex) | |
stack.extend(graph[vertex] - visited) | |
print visited |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment