For disconnected graphs like the below graph, it will catch in an infinite loop. Also, this implementation doesn't support the directional graphs. For more info [this link](https://stackoverflow.com/questions/41844408/dfs-on-disconnected-graphs) will help