Question: ALGORITHM B F S ( G ) / / Implements a breadth - first search traversal of a given graph / / Input: Graph G
ALGORITHM
Implements a breadthfirst search traversal of a given graph
Input: Graph ::
Output: Graph with its vertices marked with consccutive integers
in the order they have been visited by the BFS traversal
mark each vertex in with as a mark of being "unvisited"
count larr
for each vertex in do
if is marked with
visits all the unvisited vertices connected to vertex by a path
and assigns them the numhers in the order they are visited
via global variable count
count larr count ; mark with count and initialize a queue with
while the queue is not empty do
for each vertex in adjacent to the front vertex do
if is marked with
count larr count ; mark with count
add to the queue
remove the front vertex from the queue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
