An n log n algorithm for minimizing states in a finite automaton