Advertisement
FaisalAhemdBijoy

simple DFS

Feb 22nd, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Feb 22 16:08:35 2020
  4.  
  5. @author: Faisal Ahmed
  6. """
  7.  
  8. print("DFS Algo")
  9. graph={
  10. 'A' :['B','C'],
  11. 'B' :['D','E'],
  12. 'C' :['F'],
  13. 'D' :[],
  14. 'E' :['F'],
  15. 'F' :[]
  16. }
  17. visited=[]
  18.  
  19. def dfs(visited,graph,node):
  20.     if node not in visited:
  21.         print(visited)
  22.         print("\n")
  23.         print (node)
  24.         print(".........")
  25.        
  26.         visited.append(node)
  27.         for neighbour in graph[node]:
  28.             dfs(visited,graph,neighbour)
  29.            
  30. dfs(visited,graph,'A')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement