Question: please solve the error in the given code: # -*- coding: utf-8 -*- Spyder Editor This is a temporary script file. def dfs(self,graph,
please solve the error in the given code:
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
def dfs(self,graph, node, visited):
if node not in visited:
visited.append(node)
for n in graph[node]:
self.dfs(graph,n, visited)
return visited
def BFS(self, s):
visited = [False] * (len(self.nodes))
queue = []
queue.append(s)
visited[len(queue)] = True
while queue:
s = queue.pop(0)
print (s, end = " ")
co=len(queue)
for i in self.adj[s]:
co+=1
print(visited[co])
if visited[co] == False:
queue.append(i)
visited[co] = True
DW=nx.DiGraph()
DW.add_nodes_from(['A','B','C','D','E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T'])
DW.add_edge('A','B')
DW.add_edge('A','E')
DW.add_edge('B','F')
DW.add_edge('E','I')
DW.add_edge('F','J')
DW.add_edge('I','M')
DW.add_edge('M','Q')
DW.add_edge('M','N')
DW.add_edge('J','N')
DW.add_edge('N','R')
DW.add_edge('O','S')
DW.add_edge('O','P')
DW.add_edge('F','G')
DW.add_edge('G','K')
DW.add_edge('K','O')
DW.add_edge('G','H')
DW.add_edge('K','L')
DW.add_edge('C','D')
DW.add_edge('C','G')
DW.add_edge('P','T')
d=DGraph()
nx.draw(DW,with_labels=True)
visited = d.dfs(DW,'A', [])
print(visited)
| Convert following maze into a state space tree and then apply backtracking using depth first search on the state space tree. Start state is A and goal state is T NOTE: Avoid cycles/ loops while making state space tree. Solid line in maze shows the wall and dotted line shows the open path. Only horizontal and vertical movements are allowed. Q M LU E A R N F B S O G T H D L
Step by Step Solution
3.49 Rating (156 Votes )
There are 3 Steps involved in it
In case of any query do comment Please rate the answer Note While copying the code from Chegg ... View full answer
Get step-by-step solutions from verified subject matter experts
