To perform uninformed search using BFS Traversal > Python Program
To perform uninformed search using BFS 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 bfs(start,graph):
seq=[]
l=[start]
while l:
temp =l.pop(0)
if temp not in seq:
seq = seq + [temp]
l = l + graph[temp]
return(seq)
print("BFS SEARCH SEQ.",bfs('A',graph))
#OUTPUT---------
#RESTART: C:\Users\student\AppData\Local\Programs\Python\Python35-32\bfs.py =
#BFS SEARCH SEQ. ['A', 'B', 'C', 'D', 'E']
Comments
Post a Comment