Algorithm BFS(v)
//A breadth first search of G is carried out begining at vertex v. For any node i
//visited[i]=1 if i has already been visited. The graphs G and arry visited are
//global, visited is initialized to zero
{
u:=v;//q is a queue of unexplored vertices
visit[v]:=1;
repeat
{
for all vertices w adjacent from u do
{
if(visited[w]=0) then
{
Add w to q;//w is unexplored
visited[w]:=1;
}
}
if q is empty then return;
delete u from q;
}until(false);
}
Algorithm BFT(G,n)
//Breath first traversal of G
{
for i:=1 to n do //Mark all vertices on visited
visit[i]:=0;
for i:=1 to n do if(visited[i]=0) then BFS(i);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment