public void BFS() {
        final int rootNode = 0;
        final Queue<Integer> queue = new LinkedList<Integer>();
        queue.add(rootNode);
        visited[rootNode] = true;
        printNodes(rootNode);
        while (!queue.isEmpty()) {
            final int n = queue.peek();
            final int child = getUnvisitedChildNode(n, g);
            if (child != -1) {
                visited[child] = true;
                printNodes(child);
                queue.add(child);
            } else {
                queue.poll();
            }
        }
        clearVisited(visited);
    }