Closed aoyuanbo closed 6 years ago
Whether or not there is a cycle, this program always returns true after running ` for (Integer neighbor : graph.getNeighbors(start)) {
if(visited.contains(neighbor) && !exited.contains(neighbor)) return true; if(!visited.contains(neighbor) && dfs(neighbor)) return true; }`
Can you give any sample directed graph that returns true if there is no cycle?
I know what happened, I use the undirected graph.
Whether or not there is a cycle, this program always returns true after running ` for (Integer neighbor : graph.getNeighbors(start)) {