update and rename Depth first search algorithm
parent
6f17e9bf3c
commit
1eb13d9b7d
|
@ -6,12 +6,12 @@ graph={
|
||||||
'C':['G','D'],
|
'C':['G','D'],
|
||||||
'S':['G'],
|
'S':['G'],
|
||||||
}
|
}
|
||||||
#function of BFS
|
#function of DFS
|
||||||
def BFS(graph,start,goal):
|
def BFS(graph,start,goal):
|
||||||
Visited=[]
|
Visited=[]
|
||||||
queue=[[start]]
|
queue=[[start]]
|
||||||
while queue:
|
while queue:
|
||||||
path=queue.pop(0)
|
path=queue.pop()
|
||||||
node=path[-1]
|
node=path[-1]
|
||||||
if node in Visited:
|
if node in Visited:
|
||||||
continue
|
continue
|
||||||
|
@ -29,4 +29,4 @@ def BFS(graph,start,goal):
|
||||||
|
|
||||||
|
|
||||||
Solution=BFS(graph,'S','G')
|
Solution=BFS(graph,'S','G')
|
||||||
print('Solution is ',Solution)
|
print('Solution is ',Solution)
|
Loading…
Reference in New Issue