Question: Write a C/C++ program that inputs a simple, unweighted, undirected graph from a file and outputs to standard output the connected components of the graph,
Write a C/C++ program that inputs a simple, unweighted, undirected graph from a file and outputs to standard output the connected components of the graph, one per line. Use either a DFS or a BFS as a subroutine. When selecting an unvisited vertex to start each DFS/BFS, always choose the lowest-indexed unvisited vertex. A user should see something very similar to the following when invoking your program.
>./connected graph.txt 2 3
0 4 3 7
1 5 8
2 6 >
graph.txt:
9 7 //First row represents number of vertices and number of edges, respectively. 0 4 3 4 7 4 1 8 1 5 5 8 6 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
