Title: FSM for recognizing
1FSM for recognizing words in alphabetic order
The FSM has inputs from the set a,b,c,,z, and
after seeing a stream of characters, should be in
an accepting (recognizing) state if and only if
the characters read were in alphabetical order.
Thus, chilly is acceptable, but baby is not.
Even nonsense words such as agijjjlvyzz are
acceptable. Intuitions behind solution 1. Once
a stream of characters contains an out-of-order
pair of letters, it can never become alphabetical
by adding additional letters, so there is a
trap state once an unalphabetical pair is
detected. All other states except the trap
states will be accepting states, indicating that
what has been read so far is all in alphabetical
order. 2. Recall that a state of a FSM is a
snapshot of the entire state of the system, and
should have the property that knowing the state
is enough to tell you what to do on the next
input character. If the FSM is not currently in
the trap state, and if the next input character
were k, should it go to the trap state? What
do you need to know to determine this? Or, what
conditions dictate whether a k causes it to go
to the trap state? The answer is If the last
char from the input stream was after k in the
alphabet, then go to trap, else the string is
still ok. Thus, we need to know what the prior
(which should also be alphabetically last) input
character was. 3. Our machine now becomes
(more) clear Each state represents the last
character that has been seen. We have states
labeled a, b, ..., z, and also a trap state
z
a
b
c
trap
2To make the solution easier to see, lets pretend
there are only 5 letters in the alphabet a, b,
c, d, e. Then from the previous page we have
And then from our intuition 2, an input of a
from state b transitions to trap, as does an
input of a or b from state c, etc. Also
notice that an input of a from state a should
transition back to state a, since the last char.
read is still a. Similarly for the other
characters. So we now have
The asterisk () indicates this transition
applies for any input character. Finally,
suppose we are in state b, and that d is
read, then the transition should go to the state
indicating that the most recent letter read is no
longer b, but is now d. Hence, to the state
labeled d. Similarly for the other states and
characters. Our solution, whose generalization
to the full alphabet, is now complete
edc
ed
e
a
b
c
d
e
d
e
b
c
a a,b a,b,c a,b,c,d