Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ALGORITHM B F S ( G ) / / Implements a breadth - first search traversal of a given graph / / Input: Graph G

ALGORITHM BFS(G)
//Implements a breadth-first search traversal of a given graph
//Input: Graph G=(:V,E:)
//Output: Graph G with its vertices marked with consccutive integers
//in the order they have been visited by the BFS traversal
mark each vertex in V with 0 as a mark of being "unvisited"
count larr0
for each vertex v in V do
if v is marked with 0
bs(v)
bfs(v)
//visits all the unvisited vertices connected to vertex v by a path
//and assigns them the numhers in the order they are visited
//via global variable count
count larr count +1 ; mark v with count and initialize a queue with v
while the queue is not empty do
for each vertex w in V adjacent to the front vertex do
if w is marked with 0
count larr count +1;, mark w with count
add w to the queue
remove the front vertex from the queue
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions