//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