//Aplication of DFS traversal is to find if the graph is connected or not below is the implementation of it
int no_of_connected_components = 0;
for (int i = 1; i <= nodes; i++)
{
if (visited[i] == false)
{
dfs(i);
no_of_connected_components++;
}
}
//above dfs function is same as previous algo's dfs
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter