G is a graph with n nodes. Compute the eigenvalues of the Laplacian. If G is connected, then λ1 > 0. If λi= 0 and λi+1 ne 0, then G has exactly i+ 1connected components.
Thank you sir for your answer, That can be used but I think when the graph is large this method has a high complexity, mostly when we have a number of graphs that we need to check if each graph is connected.
Yes, breadth-first search can be implemented to run in O(|V|+|E|) time, where V is the set of vertices and E is the set of edges. This is best possible.
Benghelima Slimane Charafeddine that's right. A simple way to be able to use Tarjan's algorithm is to transform your graph to a directed one by replacing each edge with two directed edges. Hope this may help !
I will check that because I think this transformation increases the time complexity as the complexity of this algorithm is O(|V|+|E|) where V is the number of vertices and E is the number of edges.