private boolean dfs(Integer start) {
        visited.add(start);

        for (Integer neighbor : graph.getNeighbors(start)) {

            if (visited.contains(neighbor) && !exited.contains(neighbor))
                return true;

            if (!visited.contains(neighbor) && dfs(neighbor))
                return true;
        }
        exited.add(start);
        return false;
    }
To find if the given graph has cycle , We need to maintain one additional set of exited vertices and do dfs.
In any step if iteration if a vertex is already in visited set and yet not exited from recusion stack, then
we can return true. We can optimize using one array with 3 different values.
src/algo/graph/CycleDetection.java