Since the problem assumptions tell us the incoming graph is undirected and connected, can’t we just return the following boolean expression:
num_edges/2 == num_vertices - 1
That is the formula for the number of edges in a tree (which is minimally connected, as the text states).
I can see why you would need to perform DFS if the incoming graph was possibly unconnected, but I don’t understand why DFS is necessary with the given assumptions.
Thanks for the book by the way, I like how down-to-business it is.
EDIT: Also asked this question here, not sure I have conveyed all the details correctly though: