Function graph_algorithms::list_of_algorithms::bfs::bfs::bfs
source · [−]pub fn bfs()Expand description
Performs Breadth First Search algorithm on a given graph represented as an adjacency list. Prints a graph, where each inner vector contains the nodes of a strongly connected component in sorted order.
Input
no_of_vertices- Input the number of vertices in the graphno_of_edges- Input the number of edges in the graphsource- The source vertex of an edge in the graphdestination- The destination of an edge in the graphStart_vertex- The start vertex where BFS algorithm starts from
Output
Prints the visit order of the vertices of the graph
Sample input
Please Enter Number of Vertices : 5
Please Enter Number of edges in the graph : 5
Source : 0
Destination : 1
Source : 0
Destination : 2
Source : 0
Destination : 3
Source : 2
Destination : 1
Source : 2
Destination : 4
Enter Starting Vertex : 0Sample output
Visited node: 0
Visited node: 1
Visited node: 2
Visited node: 3
Visited node: 4