To perform uninformed search using DFS Traversal > Python Program
To perform uninformed search using DFS Traversal > Python Program
Artificial Intelligence
Program:graph={'A':['B','C'],'B':['A','D','E'],'C':['A','E'],'D':['B','E'],'E':['D','B','C']}
def dfs(start,graph):
seq=[]
l=[start]
while l:
temp =l.pop(0)
if temp not in seq:
seq = seq + [temp]
l = graph[temp] + l
return(seq)
print("BFS SEARCH SEQ.",dfs('A',graph))
#OUTPUT-------
#RESTART: C:/Users/student/AppData/Local/Programs/Python/Python35-32/dfs.py =
#BFS SEARCH SEQ. ['A', 'B', 'D', 'E', 'C']
Comments
Post a Comment