Hello,
I can't figure out how to find the number of connected components from an undirected disconnected graph.
the input I'm getting is like this:
7
1 2
4 5
3 6
2 7
the top number is the number of vertices and the rest of the numbers are the edges, eg. 1--2 is an edge.
Is there a way that you can implement DFS algorithm to find the number of connected components? like increment a variable every time DFS is called or something?
Thanks in advance