Skip to content

Commit

Permalink
Add DFS in python (Asiatik#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
adikul30 authored and tstreamDOTh committed Oct 25, 2018
1 parent 947da87 commit fbe380e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Graphs/DFS/Python/dfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import queue
visited = []
MAX = 20
adj = {1: set([2,3,5]), 2: set([3]), 3: set([8,4]), 4:6}
q = queue.Queue(MAX)

def dfs(s):
if s in visited :
return
visited.append(s)
print(s)
children = adj.get(s)
if children != None:
if isinstance(children,int): # Case : values are not a set
dfs(children)
else : # Case : values are a set
for i in children:
dfs(i)
return

def test():
global visited
visited = []
print("dfs : ")
dfs(1)

test()

0 comments on commit fbe380e

Please sign in to comment.