Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im posting this for the 3rd time, answer in python please https://repl.it/student/submissions/5635422 repl,it HW9 - P1.BFS path Please verify your email. Re onhance your work

Im posting this for the 3rd time, answer in python please image text in transcribed
image text in transcribed
https://repl.it/student/submissions/5635422 repl,it HW9 - P1.BFS path Please verify your email. Re onhance your work after submitting share your program back to classroom 1 fron collections inport deque export to repl 3- def BFS(graph, start, goal): # Step 1: initialize variables parent.- () # holds mapping between every node and it's parent in the path current node start closed_ set e Step 2: initialize open queue open queue deque() open queue. append (start) 12 13 14- # Step 3: while loop setting current node while len (open queue) > e: current_node open_queue.popleft() # Step 3.1 return path if we're at the goal if current nodegoal: 18 19 20 # step 3.2a: iterate over neighbors of current node and add to open queue if not |ready there or in closed # Remember to store the parent information for neighbor in graph[current node]: 23- 24 - 25 26 if neighbor not in open queue and neighbor not in closed set: open queue.append (neighbor) parent[neighbor] current node closed set.add (current_node) 23 29 3e 31 e Step 4: return failure condstion 4f there is no path return one Due: Mar 01, 2019 11:59 pm submit Instructions from your teacher Breadth-First Search In this exercise, you will implement BFS for a adjacency list representation for a graph. The function, BFS(), takes three arguments: the graph to traverse, the start node, and the end node. It should retun a shortest path from start to node, inclusive, as a list. For example, given the graph below, BFS(graph, e, 6) should return [e, 1, 6] or to, 5, 6]. If there is no path, return an empty list, [0 1. Create an empty set of closed nodes and an empty dictionary to store each node's parent 2. Initialize the open queue to contain the start node 3. While the open queue is not empty, dequeue the next node from the open queue and set it to the current node 1. If it is the goal node, reconstruct the path back to the start using the parent mapping 2 Otherwise, for each of its neighbors, add it to the open queue if it's not in there or in the closed set and store the current node as its parent. Add the current node to the set of closed nodes. 4. If you empty the open queue without reaching the goal node, there is no path 2: 0 0 6 0 12-30 PM (up

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions