Breadth First Traverse
The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push()
and pop()
objects. Here, you can use list
for this and methods append()
and pop(0)
.
When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited
array, which contains True
, if node i
is already visited, or False
, if not.
Here is a BFS example again:
Swipe to start coding
Algorithm is next:
-
Push start vertex to queue and label it as visited in
visited
array -
if the queue is not empty, go to the step 3. Else leave the function.
-
Get the current
node
from queue, andpush
to the queue all unvisited neighbors. Label them as visited. -
Output which node you add and content of the queue on each step to demonstrate how it works.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Zusammenfassen Sie dieses Kapitel
Code in file erklären
Erklären, warum file die Aufgabe nicht löst
Awesome!
Completion rate improved to 7.69
Breadth First Traverse
Swipe um das Menü anzuzeigen
The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push()
and pop()
objects. Here, you can use list
for this and methods append()
and pop(0)
.
When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited
array, which contains True
, if node i
is already visited, or False
, if not.
Here is a BFS example again:
Swipe to start coding
Algorithm is next:
-
Push start vertex to queue and label it as visited in
visited
array -
if the queue is not empty, go to the step 3. Else leave the function.
-
Get the current
node
from queue, andpush
to the queue all unvisited neighbors. Label them as visited. -
Output which node you add and content of the queue on each step to demonstrate how it works.
Lösung
Danke für Ihr Feedback!
Awesome!
Completion rate improved to 7.69single