Question: (a) The following python code is the implementation of Best First Search for the graph as below, and the heuristic function to W,h(W), given in

(a) The following python code is the implementation of Best First Search for the graph as below, and the heuristic function to W,h(W), given in the table: graph = \{ 'P':[('Q',21), ('R',9), ('S',6)], \# Part (a)(i): Add your code here def bfs(start, target, graph, queue=[], visited=[]): if start not in visited: print(start) visited.append(start) queue=queue+[x for x in graph[start] if x [0][0] not in visited] queue.sort(key=lambda x:x[1]) if queue[0][0]=target: print(queue[0][0]) else: processing=queue[0] queue.remove(processing) bfs(processing[0], target, graph, queue, visited) bfs('P', 'W', graph)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
