ConnectedComponents
ConnectedComponents[g] gives the connected components of graph g as lists of vertices.
Examples
Find connected components:
g = Graph[{1 <-> 2, 2 <-> 3, 4 <-> 5}]
ConnectedComponents[g]
(* {{1, 2, 3}, {4, 5}} *)Single connected graph:
ConnectedComponents[CompleteGraph[5]]
(* {{1, 2, 3, 4, 5}} *)Number of components:
Length[ConnectedComponents[g]]
(* 2 *)Please visit the official Wolfram Language Reference for more details.