check graph for connected components using depth first search