public void search(Integer root) {
        if (root == null || !graph.getVertices().contains(root)) return;

        Set<Integer> visited = new HashSet<>();

        visited.add(root);
        queue.add(root);
        processVertex(root);

        while (!queue.isEmpty()) {

            Integer vertex = queue.peek();

            for (Integer neighbor : graph.getNeighbors(vertex))
                if (!visited.contains(neighbor)) {
                    visited.add(neighbor);
                    queue.add(neighbor);
                    processVertex(vertex);
                }
            queue.remove();
        }
    }
This is traditional top-down approach to traverse graph. This is advantageous when the frontier is small
src/algo/graph/BFS.java