/** * Finds the set of states that are reachable from the initial state. [Martin, Exercise 2.27(b)] */ public Set findReachableStates() { Set reachable = new HashSet(); // contains the states that are reachable and have been visited Set pending = new HashSet(); // contains the states that are reachable but have not yet been visited pending.add(initial); while (!pending.isEmpty()) { State q = pending.iterator().next(); pending.remove(q); reachable.add(q); for (char a : alphabet.symbols) { State p = delta(q, a); if (!reachable.contains(p)) pending.add(p); } } return reachable; }