Question: The coding language is Python. 6. [10] Recall the breadth search first (bfs) algorithm discussed in class, presented below: def bfs (g, s) : q,
The coding language is Python.
![The coding language is Python. 6. [10] Recall the breadth search first](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/670fab6b82b28_171670fab6b4b13c.jpg)

6. [10] Recall the breadth search first (bfs) algorithm discussed in class, presented below: def bfs (g, s) : q, visited = [s], while q: u = q. pop (0) visited. append (u) for v in g[u] : if v not in visited + q: q . append (v) return visited a) [3] The above simple version just returns a list of nodes in order visited by the algorithm. Below is a slightly modified, but incomplete, version of bfs(), which "returns" (or produces) the same information in global variable visited, and also updates a dictionary prev, which records for each node the previous node in the path to it found by the algorithm; for example, where F is the starting node with no previous node ( ' - ' ) to it: prev = { 'FI : '-1, 'A' : 'F', 'B': 'F', ..} Complete the function below as necessary, in any of the blank lines, to properly update variable prev: def bfs (g, s) : # g: graph, ex. { A: { B: 4, C: 7 } .. . s: start node # This function accesses global variables, initialized as follows: # - visited = list of nodes in visited order - prev = (s: '-" } : will be like: {'F': ' -1, 'A' : 'F', 'E': 'F' , ...} # to update with the sequence of visited nodes and previous nodes. global visited, prev q = [s] while q: NO u = q- pop (0) visited. append (u) for v in g[u] : if v not in visited + q: q . append (v) # END OF bis () b) [7] Complete the function below to return a string representing a path from node s to node e: def path (s, e, prev) : # s, e : start and end nodes in path from s to e # prev : dictionary, ex. { 'F1 : 1- ', , 'A' : 'F' , 'E': 'F', ..} # this returns a string like: "S->X->Y->Z->E") t = in whileNOTE: in all subsequent questions pertaining to graphs, assume the following is in effect: A, B, C, D, E, F, G, H, I, J = 'A', "B" 'C' 'D ' "E" 'G' "I "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
