public String alienOrder1(String words[]) {
        Map<Character, Integer> degree = new HashMap<>();
        Map<Character, Set<Character>> graph = buildGraph(words, degree, new HashSet<>());

        Queue<Character> zeroDegreeNodes = new LinkedList<>();
        for (Map.Entry<Character, Integer> entry : degree.entrySet()) {
            if (entry.getValue() == 0) {
                zeroDegreeNodes.offer(entry.getKey());
            }
        }

        StringBuilder result = new StringBuilder();

        while (!zeroDegreeNodes.isEmpty()) {
            char vertex = zeroDegreeNodes.poll();
            result.append(vertex);
            Set<Character> neighbors = graph.get(vertex);
            if (neighbors != null) {
                for (char neighbor : graph.get(vertex)) {
                    int count = degree.get(neighbor);
                    count--;
                    if (count == 0) {
                        zeroDegreeNodes.offer(neighbor);
                    } else {
                        degree.put(neighbor, count);
                    }
                }
            }
            graph.remove(vertex);
        }

        return graph.size() > 0 ? "" : result.toString();
    }
degree is only used for BFS. Not for DFS.
src/com/interview/graph/AlientDictionary.java