Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # dictionary_adjacency_list.py
- graph = {
- '7' : ['19','21', '14'],
- '19': ['1', '12', '31'],
- '21': [],
- '14': ['23', '6'],
- '1' : [],
- '12': [],
- '31': [],
- '23': [],
- '6' : []
- }
- visited = [] # List of visited nodes of graph.
- def dfs(visited, graph, node):
- for neighbor in graph[node]:
- dfs(visited, graph, neighbor)
- print(node)
- print("Following is the Depth-First Search")
- dfs(visited, graph, '7')
- print("visited=",visited)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement