AI Slip 4
AI Slip 4
Description: Hangman is a classic word-guessing game. The user should guess the word correctly by
entering alphabets of the user choice. The Program will get input as single alphabet from the user
and it will matchmaking with the alphabets in the original.
Q.2) Write a Python program to implement Breadth First Search algorithm. Refer the following graph
as an Input for the program.[Initial node=1,Goal node=8]
graph = {
'A' : ['B','C','G'],
'B' : ['D', 'E'],
'C' : ['F'],
'G' : [],
'D' : [],
'E' : ['F'],
'F' : []
}
visited = [] # List to keep track of visited nodes.
queue = [] #Initialize a queue
def bfs(visited,graph,node):
visited.append(node)
queue.append(node)
while queue:
s = queue.pop(0)
print (s, end = " ")
for i in graph[s]:#checking adjacent
if i not in visited:
visited.append(i)
queue.append(i)
bfs(visited, graph, 'A')