Skip to content

Instantly share code, notes, and snippets.

@Yougigun
Created March 23, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yougigun/02dbcf6fc0abb60e7c9ab8dfc810894d to your computer and use it in GitHub Desktop.
Save Yougigun/02dbcf6fc0abb60e7c9ab8dfc810894d to your computer and use it in GitHub Desktop.
visited = set()
def depth_first_search(graph,node):
if (node in visited): return
visited.add(node)
print(node)
for adjacent_node in graph[node]:
depth_first_search(graph,adjacent_node)
graph = dict()
graph["1"] = ["2","3"]
graph["2"] = ["1","7","4"]
graph["3"] = ["1","2","4"]
graph["4"] = ["7","2","1"]
graph["7"] = ["1"]
depth_first_search(graph,"7")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment