Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

https://repl.it/student/submissions/5635422 Please verify your email I share your program anhance your work after submitting O export to repl 4back to classroom run pef BES(graph, start,

image text in transcribed
image text in transcribed
https://repl.it/student/submissions/5635422 Please verify your email I share your program anhance your work after submitting O export to repl 4back to classroom run pef BES(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 # Step 2: initialize open queue open-queue = deque() open queue.append(start) # Step 3: ihile loop setting while len(open-queue)>e: current node current node open queue.popleft) # Step 3.1 return path if we're at the goal if current nodes goal: for neighbors in graph[current node]: if neighbors not in open queue and neighbors not in closed_set: open queue.append (neighbors) parent[neighbors]- current node closed set.add(current node) # step 3.2a: iterate over neighbors of current node r and add to open queue if not already there or in closed # Renenber to store the parent information - Step 3.2b: add current node to closed set # Step 4: return failure condition if there is no path return None . Resend verification link Due: Mar 01,2019 11:59 pm Instructions from your teacher Breadth-First Search submit 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 return a shortest path from start to node, inclusive, as a list. For example, given the graph below, BFS(graph, e, 6) sbould return [o, 1, 6] or o, 5, 6].If there is no path, return an empty list, [] 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 404 PM hp

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

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

5. Who should facilitate the focus group?

Answered: 1 week ago