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 glu]: if v not in visited + q: q. append (v) return visited a) 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:
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 glu]: if v not in visited + q: q. append (v) return visited a) 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:
New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter12: Working With Document Nodes And Style Sheets: Creating A Dynamic Document Outline
Section12.2: Visual Overview: Exploring Attribute Nodes
Problem 2QC
Related questions
Question
python help - please help me i really beg you
![6.
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 glu):
if v not in visited + q:
q. append (v)
return visited
a)
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 Fis the
starting node with no previous node ('-') to it:
prev = { 'F': '-', 'A': 'F', 'E': '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 } ... },
# This function accesses global variables, initialized as follows:
# - visited - 0 : list of nodes in visited order
# - prev = {s: '-'} : will be like: {'F': '-', 'A': 'F', 'E': 'F', .}
# to update with the sequence of visited nodes and previous nodes.
global visited, prev
s: start node
q- [s]
while q:
u = q.pop (0)
visited.append (u)
for v in glu) :
if v not in visited + q:
q. append (v)
# END OF bfs ()](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F042ee1e8-3b0f-4135-aaca-1faac3c0ce4e%2Fa2407425-5f16-4104-8ed7-7ff1c09db11a%2Fylm6hb_processed.png&w=3840&q=75)
Transcribed Image Text:6.
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 glu):
if v not in visited + q:
q. append (v)
return visited
a)
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 Fis the
starting node with no previous node ('-') to it:
prev = { 'F': '-', 'A': 'F', 'E': '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 } ... },
# This function accesses global variables, initialized as follows:
# - visited - 0 : list of nodes in visited order
# - prev = {s: '-'} : will be like: {'F': '-', 'A': 'F', 'E': 'F', .}
# to update with the sequence of visited nodes and previous nodes.
global visited, prev
s: start node
q- [s]
while q:
u = q.pop (0)
visited.append (u)
for v in glu) :
if v not in visited + q:
q. append (v)
# END OF bfs ()
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![New Perspectives on HTML5, CSS3, and JavaScript](https://www.bartleby.com/isbn_cover_images/9781305503922/9781305503922_smallCoverImage.gif)
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![New Perspectives on HTML5, CSS3, and JavaScript](https://www.bartleby.com/isbn_cover_images/9781305503922/9781305503922_smallCoverImage.gif)
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr