You are on page 1of 21

DISCRETE MATHEMATICS

W W L CHEN
c

W W L Chen, 1991, 2008.

This chapter is available free to all individuals, on the understanding that it is not to be used for financial gain,
and may be downloaded and/or photocopied, with or without permission from the author.
However, this document may not be kept on any information storage and retrieval system without permission
from the author, unless such system is not accessible to any individuals other than its owners.

Chapter 6
FINITE STATE MACHINES

6.1. Introduction
Example 6.1.1. Imagine that we have a very simple machine which will perform addition and multiplication of numbers from the set {1, 2} and give us the answer, and suppose that we ask the machine
to calculate 1 + 2. The table below gives an indication of the order of events:
TIME

t1

t2

t3

STATE

(1) s1

(4) s2

INPUT

(2)

(5)

OUTPUT

(3)

nothing

(6)

[1]

t4

(7)

s3

(8)

nothing

(9)

[1, 2]

(10) s1

Here t1 < t2 < t3 < t4 denotes time. We explain the table a little further:
(1) The machine is in a state s1 of readiness.
(2) We input the number 1.
(3) There is as yet no output.
(4) The machine is in a state s2 (it has stored the number 1).
(5) We input the number 2.
(6) There is as yet no output.
(7) The machine is in a state s3 (it has stored the numbers 1 and 2).
(8) We input the operation +.
(9) The machine gives the answer 3.
(10) The machine returns to the state s1 of readiness.
Note that this machine has only a finite number of possible states. It is either in the state s1 of readiness,
or in a state where it has some, but not all, of the necessary information for it to perform its task. On
the other hand, there are only a finite number of possible inputs, namely the numbers 1, 2 and the
operations + and . Also, there are only a finite number of outputs, namely nothing, junk (when
Chapter 6 : Finite State Machines

page 1 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

incorrect input is made) or the right answers. If we investigate this simple machine a little further,
then we will note that there are two little tasks that it performs every time we input some information:
Depending on the state of the machine and the input, the machine gives an output. Depending on the
state of the machine and the input, the machine moves to the next state.
Definition. A finite state machine is a 6-tuple M = (S, I, O, , , s1 ), where
(a) S is the finite set of states for M ;
(b) I is the finite input alphabet for M ;
(c) O is the finite output alphabet for M ;
(d) : S I O is the output function;
(e) : S I S is the next-state function; and
(f) s1 S is the starting state.
Example 6.1.2. Consider again our simple finite state machine described earlier. Suppose that when
the machine recognizes incorrect input (e.g. three numbers or two operations), it gives the output junk
and then returns to the initial state s1 . It is clear that I = {1, 2, +, } and O = {j, n, 1, 2, 3, 4}, where
j denotes the output junk and n denotes no output. We can see that
S = {s1 , [1], [2], [+], [], [1, 1], [1, 2], [1, +], [1, ], [2, 2], [2, +], [2, ]},
where s1 denotes the initial state of readiness and the entries between the signs [ and ] denote the
information in memory. The output function and the next-state function can be represented by the
transition table below:

s1
[1]
[2]
[+]
[]
[1, 1]
[1, 2]
[1, +]
[1, ]
[2, 2]
[2, +]
[2, ]

output
2
+

n
n
n
n
n
j
j
2
1
j
3
2

n
n
n
n
n
j
j
3
2
j
4
4

n
n
n
j
j
1
2
j
j
4
j
j

[1]
[1, 1]
[1, 2]
[1, +]
[1, ]
s1
s1
s1
s1
s1
s1
s1

n
n
n
j
j
2
3
j
j
4
j
j

next state
2
+
[2]
[1, 2]
[2, 2]
[2, +]
[2, ]
s1
s1
s1
s1
s1
s1
s1

[+]
[1, +]
[2, +]
s1
s1
s1
s1
s1
s1
s1
s1
s1

[]
[1, ]
[2, ]
s1
s1
s1
s1
s1
s1
s1
s1
s1

Another way to describe a finite state machine is by means of a state diagram instead of a transition
table. However, state diagrams can get very complicated very easily, so we shall illustrate this by a very
simple example.
Example 6.1.3. Consider a simple finite state machine M = (S, I, O, , , s1 ) with S = {s1 , s2 , s3 },
I = {0, 1}, O = {0, 1} and where the functions : S I O and : S I S are described by the
transition table below:
0
+s1 +
s2
s3
Chapter 6 : Finite State Machines

0
0
0

0
0
1

s1
s3
s1

1
s2
s2
s2
page 2 of 21

Chapter 66 :: Finite
State
Machines
63
c W W L Chen, 1991, 2008
Chapter
Finite State
Machines
63

Discrete Mathematics

Here
Here we
we have
have indicated
indicated that
that ss11 is
is the
the starting
starting state.
state. If
If we
we use
use the
the diagram
diagram
ssii

x,y
x,y

ssjj

to describe
describe (s
(si,, x)
x) =
= yy and
and (s
(si,, x)
x) =
= ssj ,, then
then we
we can
can draw
draw the
the state
state diagram
diagram below:
below:
to
i
i
j
0,0
0,0

start
start

ss11

1,0
1,0
1,0
1,0

ss22
1,1
1,1

0,0
0,0

0,0
0,0

ss33
Suppose that
that we
we have
have an
an input
input string
string 00110101,
00110101, i.e.
i.e. we
input
0, 0,
0, 1,
1, 1,
1, 0,
0, 1,
1, 0,
successively, while
starting
Suppose
we input
input 0,
0,
0, 111 successively,
successively,
while starting
starting
Suppose
that
we have
an
input
string
00110101,
i.e.0 we
0,
1,state
1, 0,
1,
0,
while
at
state
s
.
After
the
first
input
0,
we
get
output
and
return
to
s
.
After
the
second
input
0, we
we
at state
state ss11.. After
After the
the first
first input
input 0,
0, we
we get
get output
output 00 and
and return
return to
to state
state ss11.. After
After the
the second
second input
input 0,
0,
at
we
1output 0
1
again
get
and
return
to
state
s
.
After
the
third
input
1,
we
get
output
0
and
move
to
state
again get
get output
output 00 and
andreturn
returntotostate
states s.11 .After
Afterthe
thethird
third
input
we
outputand
0 and
move
to state
again
1, 1,
we
getget
output
move
to state
s2 .
s22 .. And
And so
so on.
on. It
It is
is not
not difficult
difficult to
to see
see1 that
that we
we end
end
up input
with the
output
string 000000101
and
in state
state
sAnd
up
with
the
output
string
00000101
and
in
so
on.
It
is
not
difficult
to
see
that
we
end
up
with
the
output
string
00000101
and
in
state
s
.
Note

Note that
that the
the input
input string
string 00110101
00110101 is
is in
Kleene closure
of I,
I, and
and that
the
output2 string
string
ss22 .. Note
in I
I ,, the
the
Kleene
of
that string
the output
that
the input
string
00110101
is in I of
, the
Kleene
closure
of I,closure
and that
the output
00000101 is

00000101
is
in
O
,
the
Kleene
closure
O.
00000101
in O ,closure
the Kleene
in
O , theisKleene
of O.closure of O.
We conclude
conclude this
this section
section by going
going ever
ever so
so slightly
upmarket.
slightly
upmarket.
WeWe
conclude this
section byby
going ever
so slightly
upmarket.
Example 6.1.4.
6.1.4. Let
Let us attempt
attempt to
to add
add two
two numbers
numbers in
in binary
binary notation
notation together,
together, for
for example
example a
a=
= 01011
01011
Example
Example
6.1.4. Let ususattempt
to add
two numbers
in binary
notation together,
for example
a=
01011
and bb =
= 00101.
00101. Note
Note that
that the
the extra
extra 0s
0s are
are there
there to
to make
make sure
sure that
that the
the two
two numbers
numbers have
have the
the same
same
and
and b = 00101. Note that the extra 0s are there to make sure that the two numbers have the same
number of
of digits
digits and
and that
that the
the sum
sum of
of them
them has
has no
no extra
extra digits.
digits. This
This would
would normally
normally be
be done
done in
in the
the
number
number of digits and that the sum of them has no extra digits. This would normally be done in the
following way:
way:
following
following way:
a
0 1 0 1 1
a
a
00 11 00 11 11
+ bb
+ 00 00 11 00 11
+
+
+ b
+ 0 0 1 0 1
1 0 0 0 0
ccc
11 00 00 00 00
Let us
us write
write a
a=
=a
a a
a44 a
a33 a
a a
a11 and
and bb =
= bb55 bb44 bb33 bb22 bb11 ,, and
write x
=
(a
for
every
= 1,
1, 2,
2, 3,
3, 4,
4, 5.
5. We
We can
can
Let
and write
write
xjjj =
= (a
(ajjj ,,, bbbjjj ))) for
for every
every jjj =
=
Let
us write
a=
a555a
a222a
b4 b3 b2 b1 , and
x
1, 2,
3, 4,
5. We
can
4 a3
1 and b = b5
now
think
of
the
input
string
as
x
x
x
x
x
and
the
output
string
as
c
c
c
c
c
,
where
c
=
c
c
c
c
now think
think of
of the
the input
input string
string as
as x
x111x
x222x
x333x
x444x
x555 and
and the
the output
output string
string as
as cc111cc222cc333cc444cc555,, where
where cc =
= cc555cc444cc333cc222ccc111...
now
Note,
however,
that
when
we
perform
each
addition,
we
have
to
see
whether
there
is
a
carry
from
the
Note, however,
however, that
that when
when we
we perform
perform each
each addition,
addition, we
we have
have to
to see
see whether
whether there
there is
is aa carry
carry from
from the
the
Note,
previous
addition,
so
that
are
two
possible
states
at
the
start
of
each
addition.
Let
us
call
them
s
(no
0
previous
addition,
so
that
are
two
possible
states
at
the
start
of
each
addition.
Let
us
call
them
s
(no
previous addition, so that are two possible states at the start of each addition. Let us call them s00 (no
carry) and
and s (carry).
(carry). Then
Then S
S=
= {s
{s00 ,, ss11 },
}, I
I=
= {(0,
0), (0,
(0, 1),
1), (1,
(1, 0),
(1, 1)}
O=
{0, 1}.
1}. The
carry)
{(0, 0),
0), (1,
1)} and
and O
= {0,
The functions
functions
carry)
and ss111 (carry).
Then S
= {s
0 , s1 }, I = {(0, 0), (0, 1), (1, 0), (1, 1)} and O = {0, 1}. The functions

:
S

O
and

:
S

S
can
be
represented
by
the
following
transition
table:

:
S

O
and

:
S

S
can
be
represented
by
the
following
transition
table:
: S I O and : S I S can be represented by the following transition table:

+s0+
+
+s
0
ss1
1

(0, 0)
0)
(0,
00
11

output

output
(0,
1)
(1,
0)
(0, 1)
(1, 0)
11
11
0
0
00

(1, 1)
1)
(1,
00
11

(0, 0)
0)
(0,
ss00
ss00
0

next state
state
next
(0,
1)
(1, 0)
0)
(0, 1)
(1,
ss00
ss00
ss1
ss11
1

(1, 1)
1)
(1,
ss11
ss11
1

Clearly ss00 is
is the
the starting
starting state.
state.
Clearly

6.2. Pattern
PatternRecognition
RecognitionMachines
Machines
6.2.
Pattern
Recognition
Machines
In
In this
this section,
section, we
we study
study examples
examples of
of finite
finite state
state machines
machines that
that are
are designed
designed to
to recognize
recognize given
given patterns.
patterns.
As
there
is
essentially
no
standard
way
of
constructing
such
machines,
we
shall
illustrate
As there is essentially no standard way of constructing such machines, we shall illustrate the
the underlying
underlying
ideas
ideas by
by examples.
examples. The
The questions
questions in
in this
this section
section will
will get
get progressively
progressively harder.
harder.
Chapter 6 : Finite State Machines

page 3 of 21

Discrete
64 Mathematics
WW

L Chen : Discrete Mathematics

W W L Chen, 1991, 2008

Remark.
thethe
examples
Remark. InIn
examplesthat
thatfollow,
follow,weweshall
shalluse
usewords
wordslike
likepassive
passiveand
andexcited
excitedto
todescribe
describethe
the
various
variousstates
statesof
ofthe
thefinite
finitestate
statemachines
machinesthat
thatwe
weare
areattempting
attemptingto
toconstruct.
construct. These
Thesewords
wordsplay
playno
norole
role
in
in serious
serious mathematics,
mathematics, and
and should
should not
not be
be used
used in
in exercises
exercises or
or in
in any
any examination.
examination. ItIt isis hoped
hoped that
thatby
by
using
using such
such words
words here,
here, the
the exposition
exposition will
will be
be aa little
little more
more light-hearted
light-hearted and,
and, hopefully,
hopefully,aalittle
littleclearer.
clearer.
Example
that
I I==OO=={0,
1},
Example 6.2.1.
6.2.1. Suppose
Suppose
that
{0,
1},and
andthat
thatwe
wewant
wanttotodesign
designaafinite
finitestate
statemachine
machinethat
that

recognizes
the
sequence
pattern
11
in
the
input
string
x

I
.
An
example
of
an
input
string
recognizes the sequence pattern 11 in the input string x I . An example of an input string xx II
and
and its
its corresponding
corresponding output
output string
string yyOO isis shown
shown below:
below:
xx==10111010101111110101
10111010101111110101
yy==00011000000111110000
00011000000111110000
Note
Note that
that the
the output
output digit
digit isis 00 when
when the
the sequence
sequence pattern
pattern 11
11 isis not
not detected
detected and
and 11 when
when the
the sequence
sequence
pattern
pattern11
11isisdetected.
detected. In
Inorder
orderto
toachieve
achievethis,
this,we
wemust
mustensure
ensurethat
thatthe
thefinite
finitestate
statemachine
machinehas
hasat
atleast
least
two
two states,
states, aa passive
passive state
state when
when the
the previous
previous entry
entry isis 00 (or
(or when
when no
no entry
entry has
has yet
yet been
been made),
made), and
and
an
an excited
excited state
state when
when the
the previous
previous entry
entry isis 1.1. Furthermore,
Furthermore, the
the finite
finite state
state machine
machine has
has to
to observe
observe
the
the following
following and
and take
take the
the corresponding
corresponding actions:
actions:
(1)
(1) IfIfititisisin
inits
itspassive
passivestate
stateand
andthe
thenext
nextentry
entryisis0,0,ititgives
givesan
anoutput
output00and
andremains
remainsin
inits
itspassive
passive
state.
state.
(2)
(2) IfIfititisisin
inits
itspassive
passivestate
stateand
andthe
thenext
nextentry
entryisis1,1,ititgives
givesan
anoutput
output00and
andswitches
switchesto
toits
itsexcited
excited
state.
state.
(3)
(3) IfIfititisisin
inits
itsexcited
excitedstate
stateand
andthe
thenext
nextentry
entryisis0,0,ititgives
givesan
anoutput
output00and
andswitches
switchesto
toits
itspassive
passive
state.
state.
(4)
(4) IfIfititisisin
inits
itsexcited
excitedstate
stateand
andthe
thenext
nextentry
entryisis1,1,ititgives
givesan
anoutput
output11and
andremains
remainsin
inits
itsexcited
excited
state.
state.
ItIt follows
follows that
that ifif we
we denote
denote by
by ss11 the
the passive
passive state
state and
and by
by ss22 the
the excited
excited state,
state, then
then we
we have
have the
the
state
diagram
below:
state diagram below:
0,0

s1

start

1,1
1,0
0,0

s2

We then
then have
have the
the corresponding
corresponding transition
transition table:
table:
We

+s11++
+s
ss22

0
0 11
00 00
00 11

0
0 11
ss11 ss22
ss11 ss22

Example 6.2.2.
6.2.2. Suppose
Suppose
again
that
{0,
1},and
andthat
thatwewewant
wanttotodesign
designaafinite
finitestate
statemachine
machine
Example
again
that
I I==OO=={0,
1},
that recognizes
recognizes the
the sequence
sequence pattern
pattern 111
111 in
in the
the input
input string
string xx II.. An
An example
example of
of the
the same
same input
input
that
string xxII and
and its
its corresponding
corresponding output
output string
string yyOO isis shown
shown below:
below:
string
10111010101111110101
xx==10111010101111110101
00001000000011110000
yy==00001000000011110000
In
In order
order to
to achieve
achieve this,
this, the
the finite
finite state
state machine
machine must
must now
now have
have at
at least
least three
three states,
states, aa passive
passive state
state
when
when the
the previous
previous entry
entry isis 00 (or
(or when
when no
no entry
entry has
has yet
yet been
been made),
made), an
an expectant
expectant state
state when
when the
the
previous
previoustwo
twoentries
entriesare
are01
01(or
(orwhen
whenonly
onlyone
oneentry
entryhas
hasso
sofar
farbeen
beenmade
madeand
andititisis1),
1),and
andan
anexcited
excited
state
state when
when the
the previous
previous two
two entries
entries are
are 11.
11. Furthermore,
Furthermore, the
the finite
finite state
state machine
machine has
has to
to observe
observe the
the
following
following and
and take
take the
the corresponding
corresponding actions:
actions:
Chapter 6 : Finite State Machines

page 4 of 21

Chapter 6 : Finite State


65
cMachines
W W L Chen, 1991, 2008

Discrete Mathematics

(1) IfIfititisisin
inits
itspassive
passivestate
stateand
andthe
thenext
nextentry
entryisis0,0,ititgives
givesan
anoutput
output00and
andremains
remainsin
inits
itspassive
passive
(1)
state.
state.
(2) IfIf itit isis in
in its
its passive
passive state
state and
and the
the next
next entry
entry isis 1,1, itit gives
gives an
an output
output 00 and
and switches
switches to
to its
its
(2)
expectant state.
state.
expectant
(3) IfIf itit isis in
in its
its expectant
expectant state
state and
and the
the next
next entry
entry isis 0,0, itit gives
gives an
an output
output 00 and
and switches
switches to
to its
its
(3)
passive
state.
passive state.
(4) IfIf itit isis in
in its
its expectant
expectant state
state and
and the
the next
next entry
entry isis 1,1, itit gives
gives an
an output
output 00 and
and switches
switches to
to its
its
(4)
excited state.
state.
excited
(5) IfIfititisisin
inits
itsexcited
excitedstate
stateand
andthe
thenext
nextentry
entryisis0,0,ititgives
givesan
anoutput
output00and
andswitches
switchesto
toits
itspassive
passive
(5)
state.
state.
(6) IfIfititisisin
inits
itsexcited
excitedstate
stateand
andthe
thenext
nextentry
entryisis1,1,ititgives
givesan
anoutput
output11and
andremains
remainsin
inits
itsexcited
excited
(6)
state.
state.
we now
now denote
denote by
by ss11 the
the passive
passive state,
state, by
by ss22 the
the expectant
expectant state
state and
and by
by ss33 the
the excited
excited state,
state,
IfIf we
then we
we have
have the
the state
state diagram
diagram below:
below:
then
0,0

s1

start

1,0
0,0

s2
1,0

0,0

s3
1,1

We then
then have
have the
the corresponding
corresponding transition
transition table:
table:
We

+s11++
+s
ss22
ss33

0
0 11
00 00
00 00
00 11

0
0 11
ss11 ss22
ss11 ss33
ss11 ss33

Example 6.2.3.
6.2.3. Suppose
Suppose
again
that
{0,
1},and
andthat
thatwewewant
wanttotodesign
designaafinite
finitestate
statemachine
machine
Example
again
that
I I==OO=={0,
1},
, but only when the third 1 in the
that
recognizes
the
sequence
pattern
111
in
the
input
string
x

I
that recognizes the sequence pattern 111 in the input string x I , but only when the third 1 in the
sequence pattern
pattern 111
111 occurs
occurs at
at aa position
position that
that isis aa multiple
multiple of
of 3.3. An
An example
example of
of the
the same
same input
input string
string
sequence
and its corresponding output string y O is shown below:
x

I
x I and its corresponding output string y O is shown below:
10111010101111110101
xx==10111010101111110101
00000000000000100000
yy==00000000000000100000
In order
order to
to achieve
achieve this,
this, the
the finite
finite state
state machine
machine must
must as
as before
before have
have at
at least
least three
three states,
states, aa passive
passive
In
statewhen
whenthe
theprevious
previousentry
entryisis00(or
(orwhen
whenno
noentry
entryhas
hasyet
yetbeen
beenmade),
made),an
anexpectant
expectantstate
statewhen
whenthe
the
state
previoustwo
twoentries
entriesare
are01
01(or
(orwhen
whenonly
onlyone
oneentry
entryhas
hasso
sofar
farbeen
beenmade
madeand
andititisis1),
1),and
andan
anexcited
excited
previous
state when
when the
the previous
previous two
two entries
entries are
are 11.
11. However,
However, this
this isis not
not enough,
enough, as
as we
we also
also need
need to
to keep
keep track
track
state
of the
the entries
entries to
to ensure
ensure that
that the
the position
position of
of the
the first
first 11 in
in the
the sequence
sequence pattern
pattern 111
111 occurs
occurs at
at aa position
position
of
immediately after
after aa multiple
multiple of
of 3.3. ItIt follows
follows that
that ifif we
we permit
permit the
the machine
machine to
to be
be at
at its
its passive
passive state
state
immediately
only either
either at
at the
the start
start or
or after
after 3k
3k entries,
entries, where
where kk N,
N, then
then itit isis necessary
necessary to
to have
have two
two further
further states
states
only
to cater
cater for
for the
the possibilities
possibilities of
of 00 in
in at
at least
least one
one of
of the
the two
two entries
entries after
after aa passive
passive state
state and
and to
to then
then
to
Chapter 6 : Finite State Machines

page 5 of 21

Discrete Mathematics
66
W W L Chen : Discrete Mathematics

W W L Chen, 1991, 2008

delay the return to this passive state. We can have the state diagram below:
s3
0,0

1,0

1,1

s1

start

1,0

s2

0,0

0,0

0,0

1,0

s4

0,0
1,0

s5

We
We then
then have
have the
the corresponding
corresponding transition
transition table:
table:

+s
+s11 +
+
ss22
ss33
ss44
ss55

00
00
00
00
00
00

11
00
00
11
00
00

00
ss44
ss55
ss11
ss55
ss11

11
ss22
ss33
ss11
ss55
ss11

Example 6.2.4. Suppose


Supposeagain
againthat
thatII==OO=={0,
{0,1},
1},and
andthat
thatwe
wewant
want to
to design
design aa finite state machine
that recognizes the sequence pattern 0101 in the input string x I . An example of the same input
string x I and its corresponding output string y O is shown below:
x = 10111010101111110101
y = 00000000101000000001
In order to achieve this, the finite state machine must have at least four states, a passive state when
the previous two entries are 11 (or when no entry has yet been made), an expectant state when the
previous three entries are 000 or 100 or 110 (or when only one entry has so far been made and it is 0),
an excited state when the previous two entries are 01, and a cannot-wait state when the previous
three entries are 010. Furthermore, the finite state machine has to observe the following and take the
corresponding actions:
(1) If it is in its passive state and the next entry is 0, it gives an output 0 and switches to its
expectant state.
(2) If it is in its passive state and the next entry is 1, it gives an output 0 and remains in its passive
state.
(3) If it is in its expectant state and the next entry is 0, it gives an output 0 and remains in its
expectant state.
(4) If it is in its expectant state and the next entry is 1, it gives an output 0 and switches to its
excited state.
(5) If it is in its excited state and the next entry is 0, it gives an output 0 and switches to its
cannot-wait state.
(6) If it is in its excited state and the next entry is 1, it gives an output 0 and switches to its passive
state.
Chapter 6 : Finite State Machines

page 6 of 21

Chapter
Machines
67
Chapter 66 :: Finite
Finite State
State
Machines
67
c W W L Chen, 1991, 2008

Discrete Mathematics

(7)
(7) If
If it
it is
is in
in its
its cannot-wait
cannot-wait state
state and
and the
the next
next entry
entry is
is 0,
0, it
it gives
gives an
an output
output 000 and
and switches
switches to
to its
its
(7)
If
it
is
in
its
cannot-wait
state
and
the
next
entry
is
0,
it
gives
an
output
and
switches
to
its
expectant
state.
expectant
state.
expectant state.
(8) If it is in its cannot-wait state and the next entry is 1, it gives an output 1 and switches to its
(8) If it is in its cannot-wait state and the next entry is 1, it gives an output 1 and switches to its
excited state.
excited state.
It
follows
It follows that
that ifif we
we denote
denote by
by ss11 the
the passive
passive state,
state, by
by ss22 the
the expectant
expectant state,
state, by
by ss33 the
the excited
excited
state
and
by
s
the
cannot-wait
state,
then
we
have
the
state
diagram
below:
state and by s44 the cannot-wait state, then we have the state diagram below:
1,0
1,0

0,0
0,0
0,0
0,0

ss11

start
start

ss22

1,0
1,0

1,0
1,0

0,0
0,0

0,0
0,0

ss33

ss44

1,1
1,1

We
We then
then have
have the
the corresponding
corresponding transition
transition table:
table:

+s
+s11+
+
ss22
ss33
ss44
4

00
00
00
00
00

11
00
00
00
11

00
ss22
ss22
ss44
ss22

11
ss11
ss33
ss11
ss33
3

Example
Suppose
again
that
{0,
1},
and
that
we
want
to
Example
6.2.5. Suppose
to
machine
Example 6.2.5.
6.2.5.
Supposeagain
againthat
thatIII==
=OO
O==
={0,
{0,1},
1},and
andthat
thatwe
wewant
want
to design
design aa finite
finite state
state machine
machine

,, but
that
recognizes
the
sequence
pattern
0101
in
the
input
string
x

I
only
when
the
last
1
that
recognizes
the
sequence
pattern
0101
in
the
input
string
x

I
but
only
when
the
last
in
the
that recognizes the sequence pattern 0101 in the input string x I , but only when the last 11 in
in the
the
sequence
pattern
0101
occurs
at
a
position
that
is
a
multiple
of
3.
An
example
of
the
same
input
string
sequence
pattern
0101
occurs
at
a
position
that
is
a
multiple
of
3.
An
example
of
the
same
input
string
sequence
pattern
0101
occurs
at
a
position
that
is
a
multiple
of
3.
An
example
of
the
same
input
string

xx

and
its
corresponding
output
string

O
is
shown
below:
x
II
I and
and its
its corresponding
corresponding output
output string
string yyy
O
O is
is shown
shown below:
below:
xx
=
10111010101111110101
x=
= 10111010101111110101
10111010101111110101
yyy =
00000000100000000000
=
00000000100000000000
= 00000000100000000000
In
order
to
achieve
this,
the
finite
state
machine
must
have
at
least
four
states
and
In
In order
order to
to achieve
achieve this,
this, the
the finite
finite state
state machine
machine must
must have
have at
at least
least four
four states
states sss333,,, sss444,,, sss555 and
and sss666,,,
corresponding
to
the
four
states
before.
We
need
two
further
states
for
delaying
purposes.
If
we
denote
corresponding
to
the
four
states
before.
We
need
two
further
states
for
delaying
purposes.
If
we
corresponding to the four states before. We need two further states for delaying purposes. If we denote
denote
these
two
states
by
s
and
s
,
then
we
can
have
the
state
diagram
as
below:
these
two
states
by
s
and
s
,
then
we
can
have
the
state
diagram
as
below:
1
2
these two states by s1 and s2 , then we can have the state diagram as below:
1

ss33
1,0
1,0

start
start

ss11

0,0
0,0
1,0
1,0

0,0
0,0 1,0
1,0

ss22

1,0
1,0

0,0
0,0

0,0
0,0

0,0
0,0

1,1
1,1

1,0
1,0

ss44

ss55

0,0
0,0

ss66
Chapter 6 : Finite State Machines

page 7 of 21

68

W W L Chen : Discrete Mathematics

68 Mathematics
WW
Discrete

W W L Chen, 1991, 2008

We then
then have
have the
the corresponding
corresponding transition
transition table:
table:
We

+s111++
+s
ss222
ss333
ss444
ss555
ss666

0
0 11
00 00
00 00
00 00
00 00
00 00
00 11

0
0 11
ss222 ss222
ss333 ss333
ss444 ss111
ss222 ss555
ss666 ss333
ss444 ss111

6.3. An
An
Optimistic
Approach
6.3.
Optimistic
Approach
We now
We
now describe
describe an
an approach
approach which
which helps
helps greatly
greatly in
in the
the construction
construction ofof pattern
pattern recognition
recognition machines.
machines.
The
The idea
idea isis extremely
extremely simple.
simple. We
We construct
construct first
first of
of all
all the
the part
part of
of the
the machine
machine to
to take
take care
care ofof the
the
situation
situation when
when the
the required
required pattern
pattern occurs
occurs repeatly
repeatly and
and without
without interruption.
interruption. We
We then
then complete
complete the
the
machine
machine by
by studying
studying the
the situation
situation when
when the
the wrong
wrong input
inputisis made
made at
at each
each state.
state.
WeWe
shall
illustrate
thisthis
approach
by by
looking
thethe
same
fivefive
examples
in the
previous
section.
shall
illustrate
approach
looking
same
examples
in the
previous
section.
Example 6.3.1.
Example
that
I I==OO=={0,
1},
6.3.1. Suppose
Suppose
that
{0,
1},and
andthat
thatwe
wewant
wanttotodesign
designaafinite
finitestate
statemachine
machinethat
that

recognizes
recognizes the
the sequence
sequence pattern
pattern 11
11 in
in the
the input
input string
string xx II.. Consider
Consider first
first of
of all
all the
the situation
situation when
when
the
the required
required pattern
pattern occurs
occurs repeatly
repeatly and
and without
without interruption.
interruption. In
In other
other words,
words, consider
consider the
the situation
situation
when
when the
the input
input string
string isis 111111
111111........ To
To describe
describe this
this situation,
situation, we
we have
have the
the following
following incomplete
incomplete state
state
diagram:
diagram:
1,1
1,1

start

s11

1,0
1,0

s22

nowremains
remainsto
tostudy
studythe
thesituation
situationwhen
whenwe
wehave
havethe
thewrong
wronginput
inputat
ateach
eachstate.
state. Naturally,
Naturally,with
withaa
ItItnow
wrong
input,
the
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
wrong input, the output is always 0, so the only unresolved question is to determine the next state.
Note
that
whenever
we
get
an
input
0,
the
process
starts
all
over
again;
in
other
words,
we
must
return
Note that whenever we get an input 0, the process starts all over again; in other words, we must return
to state
state ss111.. We
We therefore
therefore obtain
obtain the
the state
state diagram
diagram as
as in
in Example
Example 6.2.1.
6.2.1.
to
Example 6.3.2.
6.3.2.Suppose
Suppose
again
O =
1},that
andwethat
a finite
state
Example
again
thatthat
I =IO =
= {0,
1},{0,
and
wantweto want
designtoa design
finite state
machine

. Consider first of all the

machine
that
recognizes
the
sequence
pattern
111
in
the
input
string
x

I
that recognizes the sequence pattern 111 in the input string x I . Consider first of all the situation
situation
the pattern
required occurs
patternrepeatly
occurs repeatly
and without
interruption.
In other
consider
when
the when
required
and without
interruption.
In other
words,words,
consider
the
the
situation
when
the
input
string
is
111111
.
.
.
.
To
describe
this
situation,
we
have
the
following
situation when the input string is 111111 . . . . To describe this situation, we have the following incomplete
incomplete
state diagram:
state
diagram:
start

s11

1,0
1,0

s22
1,0
1,0

s33
1,1
1,1

nowremains
remainsto
tostudy
studythe
thesituation
situationwhen
whenwe
wehave
havethe
thewrong
wronginput
inputat
ateach
eachstate.
state. As
Asbefore,
before,with
withaa
ItItnow
wrong
input,
the
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
wrong input, the output is always 0, so the only unresolved question is to determine the next state.
Chapter 6 : Finite State Machines

page 8 of 21

c W W L Chen, 1991, 2008


Chapter 6 : Finite State
Machines
69
Chapter 6 : Finite State Machines
69
Chapter 6 : Finite State Machines
69

Discrete Mathematics

Note
Note that
that whenever
whenever we
we get
get an
an input
input 0,
0, the
the process
process starts
starts all
all over
over again;
again; in
in other
other words,
words, we
we must
must return
return
to
state
s
.
We
therefore
obtain
the
state
diagram
as
Example
6.2.2.
1
to state
s whenever
. We therefore
obtain
the state
as Example
6.2.2.
Note
that
we get
an input
0, thediagram
process starts
all over
again; in other words, we must return
1

Note
that
we get
an input
0, thediagram
process as
starts
all over
again; in other words, we must return
to
state
s1 .whenever
We therefore
obtain
the state
Example
6.2.2.
Example
6.3.3.
Suppose
again
II==O
Example
Suppose
againthat
thatstate
O=={0,
{0,1},
1},
andthat
thatwe
wewant
wantto
to design
design aa finite
finite state
state machine
machine
to state s1 .6.3.3.
We therefore
obtain
the
diagram
as and
Example
6.2.2.

, but only when the third 1 in the


that
recognizes
the
sequence
pattern
111
in
the
input
string
x

I
that
recognizes
sequenceagain
pattern
input
string
x
, buttoonly
when
the third
1 in the
Example
6.3.3.theSuppose
that111
I =inOthe
= {0,
1}, and
that
weIwant
design
a finite
state machine
sequence
pattern
111
occurs
at
aa position
aa multiple
of
Consider
first
of
all
the
when

sequence
pattern
111
occursagain
atpattern
position
that
is{0,
multiple
of x3.
3.
Consider
first
of
all
the
situation
when
Example
6.3.3.the
Suppose
that111
I =that
=is
1}, and
that
we
design
a finite
state machine
that
recognizes
sequence
inOthe
input
string
Iwant
, buttoonly
when
thesituation
third
1 in
the

the
required
pattern
occurs
repeatly
and
without
interruption.
In
other
words,
consider
the
situation
the
pattern
occurs at
repeatly
and
without
interruption.
consider
the situation
thatrequired
recognizes
the
pattern
111 that
in
the
string
I other
, but words,
only
when
thesituation
third
1 in
the
sequence
pattern
111sequence
a position
is ainput
multiple
of x3.In
Consider
first of
all the
when
when
the
input
string
is
.. .. .. To
situation,
have
following
incomplete
state
when
the pattern
input
string
is 111111
111111
To
describe
this
situation,
we
have
the
following
incomplete
state
sequence
111 occurs
occurs
at a.. position
that
is athis
multiple
of 3. we
Consider
first
of consider
all the
situation
when
the
required
pattern
repeatly
anddescribe
without
interruption.
In
otherthe
words,
the situation
diagram:
diagram:
the required
pattern
repeatly
anddescribe
withoutthis
interruption.
In have
otherthe
words,
consider
the situation
when
the input
stringoccurs
is 111111
. . . . To
situation, we
following
incomplete
state
when the input string is 111111 . . . . To describe this situation, we have the following incomplete state
diagram:
s3
diagram:
s3
s3
1,1
1,1
1,01,1
1,0

1,0
1,0

1,0

s2
s1
start
s2
s
1
start
1,0
It now remains to study the situation when we haves the wrong
input
each state. As before, with a
s2 at each
1the wrong input
start
It
now
the
we
have
state.
before,
aa
wrong
input, to
thestudy
output
always 0,when
so the
question
is each
to determine
nextwith
state.
It
now remains
remains
to
study
theissituation
situation
when
we only
have unresolved
the wrong
input at
at
state. As
Asthe
before,
with
wrong
input,
the
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
Suppose
that
the
machine
isissituation
atalways
state s0,when
and
the
wrong
0 question
is input
made.at
thatAs
if the
the
nextwith
threea
It now remains
to
study
the
we
have
theinput
wrong
each
state.
before,
wrong
input,
the
output
the
only
unresolved
isWe
to note
determine
next
state.
3 ,so
Suppose
that
the
machine
is
state
ss0,3 ,, so
and
the
wrong
input
00 question
is
note
if
the
next
three
entries
111,
that pattern
should
bethe
recognized.
It follows
that (s
0)
= that
s1 . We
now
have
the
wrongare
input,
the
output
only
unresolved
isWe
to
determine
next
state.
Suppose
that
thethen
machine
isisat
atalways
state
the
wrong
input
is made.
made.
We
that
if the
the
next
three
3 , note
3 and
entries
are
111,
then
that
pattern
should
be
recognized.
It
follows
that
(s
,
0)
=
s
.
We
now
have
the
3
1
following
incomplete
state
diagram:
Supposeare
that
thethen
machine
is at state
s3 , and
the wrong input
0 is made.
We
note
if the
entries
111,
that pattern
should
be recognized.
It follows
that (s
= that
s1 . We
nownext
havethree
the
3 , 0)
following
diagram:
entries areincomplete
111, then state
that pattern
following
incomplete
state
diagram:should be recognized. It follows that (s3 , 0) = s1 . We now have the
s3
following incomplete state diagram:
s3
s3
0,0
0,0 1,1
0,0 1,1
1,01,1

1,0
1,0

1,0

s2
s1
start
1,0
s2
s1
start
1,0
Suppose that the machine is at state s1 , and the wrong
input
0 is
s2 made. We note that the next
s1
start
inputs cannot
contribute
pattern,
need
to delay
steps We
before
returning
s1 .
Suppose
that the
machinetoisany
at state
s1 , so
andwethe
wrong
inputby0 two
is made.
note
that thetonext
Suppose
that
the
machine
at
ss1 ,,diagram:
and
the
wrong
input
00 two
is
made.
We
note
that
the
next
now
have
the following
incomplete
state
Suppose
that
the
machine
isany
at state
state
and
the
wrong
input
is
made.
We
note
that
the
next
inputs
cannot
contribute
tois
pattern,
so
we
need
to
delay
by
steps
before
returning
to
s1 .
1
inputs
cannot
contribute
to
so
inputs
cannot
contribute
to any
any pattern,
pattern,
so we
we need
need to
to delay
delay by
by two
two steps
steps before
before returning
returning to
to ss11..
now
have
the following
incomplete
state diagram:
s3
now
now have
have the
the following
following incomplete
incomplete state
state diagram:
diagram:
s3
s3
0,0

start
start
start

s1
s1
s1

0,0
0,0

0,0

0,0 1,1
0,0 1,1
1,01,1
1,0
1,0
0,0
1,0 0,0
1,0 0,0

two
We
two
two
two
We
We
We

1,0
1,0

1,0

s2
s2
s2

0,0
1,0
s4
s5
1,0
0,0
s4
s5
1,0
s4 obtain0,0the state
s5 diagram as Example 6.2.3.
Finally, it remains to examine (s2 , 0). We therefore
1,0
Finally, it remains to examine (s2 , 0). We therefore obtain the state diagram as Example 6.2.3.
Noteit that
in Example
6.3.3,
in ,dealing
the input
0 at
, we haveasactually
introduced
the
Finally,
remains
to examine
(s
0). We with
therefore
obtain
thestate
states1diagram
Example
6.2.3.
Finally, it remains to examine (s22, 0). We therefore obtain the state diagram as Example 6.2.3.
extraNote
states
s
and
s
.
These
extra
states
are
not
actually
involved
with
positive
identification
of
that4 in Example
6.3.3, in dealing with the input 0 at state s1 , we have actually introduced the
5
desired
pattern,
but
are
essential
delaying
return
of the
states
already
present.
It follows
that
Example
6.3.3,
inindealing
the
inputto0one
at
state
s with
, we positive
have
actually
introduced
extraNote
states
s in
and
s5 . These
extra
states with
arethe
not
actually
involved
identification
of the
Note that in4 Example
6.3.3, in dealing with the input 0 at state s11, we have actually introduced the
that
at
these
extra
states,
the
output
should
always
be
0.
However,
we
have
to
investigate
the
situation
extra states
s4 and
extra
states arethe
not
actually
involved
of the
desired
pattern,
but sare
essential
in delaying
return
to one
of the with
statespositive
alreadyidentification
present. It
follows
5 . These
extra states s4 and s5 . These extra states are not actually involved with positive identification of the
for
input
0 and
1.butstates,
desired
pattern,
are essential
in delaying
the return
one of the
already
present.
follows
that
at these
extra
the output
should always
be 0.toHowever,
westates
have to
investigate
the It
situation
desired pattern, but are essential in delaying the return to one of the states already present. It follows
thatinput
at these
extra
for
0 and
1. states, the output should always be 0. However, we have to investigate the situation
that In
at the
these
extra states, the output should always be 0. However, we have to investigate the situation
for input
0 next
and 1.two examples, we do not include all the details. Readers are advised to look carefully
for
input
at the
and examples,
ensure that
understand
thethe
underlying
arguments.
The main
is to
In argument
the0 and
next1.two
wethey
do not
include all
details. Readers
are advised
to question
look carefully
In argument
the next two
wethey
do not
include all
details. Readers
are advised
to question
look carefully
at the
and examples,
ensure that
understand
thethe
underlying
arguments.
The main
is to
Chapter 6 : Finite State Machines
page 9 of 21
at the argument and ensure that they understand the underlying arguments. The main question
is to

Discrete Mathematics

610
610

W W L Chen : Discrete Mathematics


W W L Chen : Discrete Mathematics

W W L Chen, 1991, 2008

In the next two examples, we do not include all the details. Readers are advised to look carefully
recognize that with a wrong input, we may still be able to recover part of a pattern. For example, if
at
the argument
and ensure that
theyweunderstand
theable
underlying
arguments.
The mainFor
question is to
recognize
that
input,
stillwhere
be
recover
part
of a pattern.
if
the pattern
wewith
wanta iswrong
01011 but
we gotmay
01010,
thetofifth
input
is incorrect,
then theexample,
last three
recognize
that
with
a
wrong
input,
we
may
still
be
able
to
recover
part
of
a
pattern.
For
example,
the
pattern
we want
is 01011
but form
we got
where
the fifth
input
is incorrect,
last threeif
inputs
in 01010
can still
possibly
the01010,
first three
inputs
of the
pattern
01011. Ifthen
one the
is optimistic,
the pattern
we want
is 01011 butform
we got
where
the fifth
input
is incorrect,
last three
inputs
in 01010
can still
the 01010,
first0101011.
three
inputs
of the
pattern
01011. Ifthen
one the
is optimistic,
one might
hope that
the possibly
first seven inputs
are
inputs
in
01010
can
still
possibly
form
the
first
three
inputs
of
the
pattern
01011.
If
one
is
optimistic,
one might hope that the first seven inputs are 0101011.
one might hope that the first seven inputs are 0101011.
Example 6.3.4. Suppose again that I = O = {0, 1}, and that we want to design a finite state
Example
6.3.4.
Suppose
again
that
{0,and
1}, that
and we
that
wexto
want
a finite
machine
that
recognizes
the
sequence
0101
in
the
input
string
I . to
Consider
ofmachine
allstate
the
Example
6.3.4.
Suppose
again
that
Ipattern
=I O==O
{0,=1},
want
design
adesign
finite first
state

machine
that
the pattern
sequence
pattern
0101
in
the
input
string
x I . In
Consider
first
all the
situation
whenrecognizes
the
repeatly
and
without
interruption.
other
words,
consider
that recognizes
the required
sequence
patternoccurs
0101
in
the
input
string
x
I . Consider
first
of all
the of
situation
situation
the required
pattern
occurs
repeatly
without
interruption.
Inwe
other
words,
consider
the
situation
when
the input
stringrepeatly
is 010101
. . .without
. and
To describe
this situation,
have
the
following
when
thewhen
required
pattern
occurs
and
interruption.
In other
words,
consider
the
the
situation
when
the
input
string
is
010101
.
.
.
.
To
describe
this
situation,
we
have
the
following
incomplete
statethe
diagram:
situation when
input string is 010101 . . . . To describe this situation, we have the following incomplete
incomplete
state diagram:
state diagram:
0,0
s1
s2
start
0,0
s1
s2
start
1,0
1,0
0,0

s3
s3

0,0
1,1
1,1

s4
s4

It now remains to study the situation when we have the wrong input at each state. As before, with a
It now
now remains
remains
to
study
theissituation
situation
when
weonly
haveunresolved
the wrong
wrong
input at
at
each
state. As
Asthe
before,
with
It
the
we
have
the
input
state.
before,
aa
wrong
input, to
thestudy
output
always 0,when
so the
question
is each
to determine
nextwith
state.
wrong input,
input,
the
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
wrong
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
Recognizing
thatthe
(s
,
1)
=
s
,
(s
,
0)
=
s
,
(s
,
1)
=
s
and
(s
,
0)
=
s
,
we
therefore
obtain
the
1
1
2
2
3
1
4
2
Recognizing
that
(s11,,1)
1) =
=
(s22,,0)
0) =
= ss22,, (s
(s33,,1)
1) =
= ss11 and
and (s
(s44,,0)
0) =
= ss22,, we
we therefore
therefore obtain
obtain the
the
Recognizing
(s
ss11,, (s
state
diagramthat
as Example
6.2.4.
state diagram
diagram as
as Example
Example 6.2.4.
6.2.4.
state
Example
Supposeagain
againthat
thatII==OO=={0,
{0,1},
1},and
andthat
that we
we want
want to
to design
design aa finite
Example 6.3.5.
6.3.5. Suppose
finite state
state machine
machine

Example
6.3.5.theSuppose
again
that0101
I=O
=
{0,input
1}, and
thatxwe
want
to design
a finite
state
machine
that
recognizes
sequence
pattern
in
the
string

I
only
when
the
, but
that recognizes the sequence pattern 0101 in the input string x I , but only when the last
last 11 in
in the
the
that
recognizes
the0101
sequence
pattern
0101 inthat
the is
input
string xof3.I Consider
, but onlyfirst
when
the
last situation
1 in the
sequence
pattern
occurs
at
a
position
a
multiple
of
all
the
sequence pattern 0101 occurs at a position that is a multiple of 3. Consider first of all the situation
sequence
pattern 0101
occurs at arepeatly
position thatwithout
is a multiple of 3. Consider
first of
all the inputs
situation
when
when the
the required
required pattern
pattern occurs
occurs repeatly and
and without interruption.
interruption. Note
Note that
that the
the first
first two
two inputs do
do
when
the required
pattern
occurs
repeatly
and
without
interruption.
Notestring
that the
first
two . inputs
do
not
contribute
to
any
pattern,
so
we
consider
the
situation
when
the
input
is
x
x
0101
.
1
2
not contribute to any pattern, so we consider the situation when the input string is x1 x2 0101 . . .. ,, where
where
not
pattern,
we consider
when the
input string
x1 x2 0101 . . . , where
xx1 ,, xxcontribute
{0, 1}. to
Toany
describe
thissosituation,
we the
havesituation
the following
incomplete
stateisdiagram:
2
1
2 {0, 1}. To describe this situation, we have the following incomplete state diagram:
x1 , x2 {0, 1}. To describe this situation, we have the following incomplete state diagram:
s3
s3
0,0
0,0

start
start

s1
s1

0,0
1,0
0,0

s2
s2

1,0

1,0
1,0

0,0
0,0
1,0

s4
s4

1,0

1,1

0,0

1,1

0,0

s5
s5

s6
s6
It now
now remains
remains to
to study
study the
the situation
situation when
when we
we have
have the
the wrong
wrong input
input at
at each
each state.
state. As
As before,
before, with
with aa
It
It
now remains
study
theis
when
we only
have unresolved
the wrong
input atis
state. Asthe
before,
a
wrong
input, to
the
output
issituation
always 0,
0,
so the
the
only
unresolved
question
is each
to determine
determine
the
nextwith
state.
wrong
input,
the
output
always
so
question
to
next
state.
wrong
input,
the
output
is
always
0,
so
the
only
unresolved
question
is
to
determine
the
next
state.
Recognizing that
that (s
(s33,, 1)
1) =
= ss11,, (s
(s44,, 0)
0) =
= ss22,, (s
(s55,, 1)
1) =
= ss33 and
and (s
(s66,, 0)
0) =
= ss44,, we
we therefore
therefore obtain
obtain the
the
Recognizing
Recognizing
that
(s3 , 1) =6.2.5.
s1 , (s4 , 0) = s2 , (s5 , 1) = s3 and (s6 , 0) = s4 , we therefore obtain the
state diagram
diagram
as Example
Example
6.2.5.
state
as
state diagram as Example 6.2.5.
6.4. Delay
6.4.
DelayMachines
Machines
6.4. Delay Machines
We now consider a type of finite state machines that is useful in the design of digital devices. These are
We now consider a type of finite state machines that is useful in the design of digital devices. These are
called
k-unit
delay type
machines,
where
k
N. Corresponding
to the
input
x = x1digital
x x . . ., the machine
will
We
now
consider
of finite
state
machines
that is useful
in the
design
These will
are
called
k-unit
delaya machines,
where
k
N. Corresponding
to the
input
x = of
x1 x22x33 . . devices.
., the machine
called k-unit delay machines, where k N. Corresponding to the input x = x1 x2 x3 . . ., the machine will
Chapter 6 : Finite State Machines

page 10 of 21

c W W L Chen, 1991,611

2008
Chapter 6 : Finite State Machines

Discrete Mathematics

give
give the
the output
output
y = |0 .{z
..0x x x ...;
! "# }$ 1 2 3
k

in other words, it adds k 0s at the front of the string.


AnAn
important
point
to to
note
is that
if we
to add
k 0sk at0sthe
of theofstring,
then the
important
point
note
is that
if want
we want
to add
at front
the front
the string,
thensame
the
result
can
be
obtained
by
feeding
the
string
into
a
1-unit
delay
machine,
then
feeding
the
output
obtained
same result can be obtained by feeding the string into a 1-unit delay machine, then feeding the output
into
the same
repeating
process.
It process.
follows that
we needthat
onlyweinvestigate
delay
obtained
into machine,
the same and
machine,
and this
repeating
this
It follows
need only1-unit
investigate
machines.
1-unit delay machines.
Example
6.4.1. Suppose
Example 6.4.1.
Supposethat
thatII=={0,
{0,1}.
1}. Then
Thenaa1-unit
1-unit delay
delay machine
machine can
can be
be described
described by
by the
the state
state
diagram
below:
diagram below:
0,0

s2
0,0

start

s1

0,1

1,0

1,0

s3
1,1

Note that (sii , 0) =


states s22 and s33 , the

s22 and (s22 , x) = 0; also (sii , 1) = s33 and (s33 , x) = 1. It follows that at both
output is always the previous input.

general,
maycontain
containmore
morethan
than2 2elements.
elements.Any
Anyattempt
attemptto
to construct
construct aa 1-unit
1-unit delay machine
In In
general,
I Imay
by state diagram is likely to end up in a mess. We therefore seek to understand the ideas behind such a
machine, and hope that it will help us in our attempt to construct it.
Example 6.4.2. Suppose
Supposethat
thatII=={0,
{0,1,1,2,2,3,3,4,4,5}.
5}.Necessarily,
Necessarily,there
theremust
mustbe
beaa starting
starting state
state s11 which
will add the 0 to the front of the string. It follows that (s1 , x) = 0 for every x I. The next question is
to study (s1 , x) for every x I. However, we shall postpone this until towards the end of our argument.
At this point, we are not interested in designing a machine with the least possible number of states. We
simply want a 1-unit delay machine, and we are not concerned if the number of states is more than this
minimum. We now let s2 be a state that will delay the input 0. To be precise, we want the state s2
to satisfy the following requirements:
(1) For every state s S, we have (s, 0) = s2 .
(2) For every state s S and every input x I \ {0}, we have (s, x) 6=
" s22.
(3) For every input x I, we have (s22, x) = 0.
Next,
Next, we
we let
let ss33 be
be aa state
state that
that will
will delay
delay the
the input
input 1.
1. To
To be
be precise,
precise, we
we want
want the
the state
state ss33 to
to satisfy
satisfy
the
following
requirements:
the following requirements:
(1)
(1) For
For every
every state
state ss
S,
S, we
we have
have (s,
(s, 1)
1) =
= ss33..
(2)
(2) For
For every
every state
state ss
S
S and
and every
every input
input x
x
I
I \\ {1},
{1}, we
we have
have (s,
(s, x)
x) 6=
"= ss33..
(3)
For
every
input
x

I,
we
have
(s
,
x)
=
1.
3
(3) For every input x I, we have (s3 , x) = 1.
Similarly,
and ss77 be
be the
the states
states that
that will
will delay
delay the
the inputs
inputs 2,
2, 3,
3, 44 and
and 55 respectively.
respectively.
Similarly, we
we let
let ss44,, ss55,, ss66 and
Let
us
look
more
closely
at
the
state
s
.
By
requirements
(1)
and
(2)
above,
the
machine
2
Let us look more closely at the state s2 . By requirements (1) and (2) above, the machine arrives
arrives at
at state
state
ss22 precisely
when
the
previous
input
is
0;
by
requirement
(3),
the
next
output
is
0.
This
means
precisely when the previous input is 0; by requirement (3), the next output is 0. This means that
that
the
the previous
previous input
input must
must be
be the
the same
same as
as the
the next
next output,
output, which
which is
is precisely
precisely what
what we
we are
are looking
looking for.
for.
Chapter 6 : Finite State Machines

page 11 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

Now all these requirements are summarized in the table below:

+s1 +
s2
s3
s4
s5
s6
s7

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

s2
s2
s2
s2
s2
s2

s3
s3
s3
s3
s3
s3

s4
s4
s4
s4
s4
s4

s5
s5
s5
s5
s5
s5

s6
s6
s6
s6
s6
s6

s7
s7
s7
s7
s7
s7

Finally, we study (s1 , x) for every x I. It is clear that if the first input is 0, then the next state must
delay this 0. It follows that (s1 , 0) = s2 . Similarly, (s1 , 1) = s3 , and so on. We therefore have the
following transition table:

+s1 +
s2
s3
s4
s5
s6
s7

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

0
0
1
2
3
4
5

s2
s2
s2
s2
s2
s2
s2

s3
s3
s3
s3
s3
s3
s3

s4
s4
s4
s4
s4
s4
s4

s5
s5
s5
s5
s5
s5
s5

s6
s6
s6
s6
s6
s6
s6

s7
s7
s7
s7
s7
s7
s7

6.5. Equivalence of States


Occasionally, we may find that two finite state machines perform the same tasks, i.e. give the same
output strings for the same input string, but contain different numbers of states. The question arises
that some of the states are essentially redundant. We may wish to find a process to reduce the number
of states. In other words, we would like to simplify the finite state machine.
The answer to this question is given by the Minimization process. However, to describe this process,
we must first study the equivalence of states in a finite state machine.
Suppose that M = (S, I, O, , , s1 ) is a finite state machine.
Definition. We say that two states si , sj S are 1-equivalent, denoted by si
=1 sj , if (si , x) = (sj , x)
for every x I. Similarly, for every k N, we say that two states si , sj S are k-equivalent, denoted
by si
=k sj , if (si , x) = (sj , x) for every x I k (here (si , x1 . . . xk ) denotes the output string
corresponding to the input string x1 . . . xk , starting at state si ). Furthermore, we say that two states
si , sj S are equivalent, denoted by si
= sj , if si
=k sj for every k N.
The ideas that underpin the Minimization process are summarized in the following result.
PROPOSITION 6A.
(a) For every k N, the relation
=k is an equivalence relation on S.
(b) Suppose that si , sj S, k N and k 2, and that si
=k sj . Then si
=k1 sj . In other words,
k-equivalence implies (k 1)-equivalence.
(c) Suppose that si , sj S and k N. Then si
=k+1 sj if and only if si
=k sj and (si , x)
=k (sj , x)
for every x I.
Chapter 6 : Finite State Machines

page 12 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

Proof. (a) The proof is simple and is left as an exercise.


k1 sj . Then there exists x = x1 x2 . . . xk1 I k1 such that, writing (si , x) =
(b) Suppose that si 6=
0
00
0
00
. . . yk1 and (sj , x) = y100 y200 . . . yk1
, we have that y10 y20 . . . yk1
6= y100 y200 . . . yk1
. Suppose now that
0 00
u I. Then clearly there exist z , z O such that
y10 y20

0
00
(si , xu) = y10 y20 . . . yk1
z 0 6= y100 y200 . . . yk1
z 00 = (sj , xu).

Note now that xu I k . It follows that si


6 k sj .
=
(c) Suppose that si
=k sj and (si , x)
=k (sj , x) for every x I. Let x1 x2 . . . xk+1 I k+1 . Clearly
(si , x1 x2 . . . xk+1 ) = (si , x1 )((si , x1 ), x2 . . . xk+1 ).

(1)

(sj , x1 x2 . . . xk+1 ) = (sj , x1 )((sj , x1 ), x2 . . . xk+1 ).

(2)

Similarly

Since si
=k sj , it follows from (b) that
(si , x1 ) = (sj , x1 ).

(3)

On the other hand, since (si , x1 )


=k (sj , x1 ), it follows that
((si , x1 ), x2 . . . xk+1 ) = ((sj , x1 ), x2 . . . xk+1 ).

(4)

On combining (1)(4), we obtain


(si , x1 x2 . . . xk+1 ) = (sj , x1 x2 . . . xk+1 ).

(5)

Note now that (5) holds for every x1 x2 . . . xk+1 I k+1 . Hence si
=k+1 sj . The proof of the converse is
left as an exercise.

6.6. The Minimization Process


In our earlier discussion concerning the design of finite state machines, we have not taken any care to
ensure that the finite state machine that we obtain has the smallest number of states possible. Indeed,
it is not necessary to design such a finite state machine with the minimal number of states, as any other
finite state machine that performs the same task can be minimized.
THE MINIMIZATION PROCESS.
(1) Start with k = 1. By examining the rows of the transition table, determine 1-equivalent states.
Denote by P1 the set of 1-equivalence classes of S (induced by
=1 ).

(2) Let Pk denote the set of k-equivalence classes of S (induced by =k ). In view of Proposition 6A(b), we
now examine all the states in each k-equivalence class of S, and use Proposition 6A(c) to determine
Pk+1 , the set of all (k + 1)-equivalence classes of S (induced by
=k+1 ).
(3) If Pk+1 6= Pk , then increase k by 1 and repeat (2).
(4) If Pk+1 = Pk , then the process is complete. We select one state from each equivalence class.
Chapter 6 : Finite State Machines

page 13 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

Example 6.6.1. Suppose that I = O = {0, 1}. Consider a finite state machine with the transition table
below:
0
s1
s2
s3
s4
s5
s6

0
1
0
0
1
1

1
0
0
0
0
0

s4
s5
s2
s5
s2
s1

1
s3
s2
s4
s3
s5
s6

For the time being, we do not indicate which state is the starting state. Clearly
P1 = {{s1 }, {s2 , s5 , s6 }, {s3 , s4 }}.
We now examine the 1-equivalence classes {s2 , s5 , s6 } and {s3 , s4 } separately to determine the possibility
of 2-equivalence. Note at this point that two states from different 1-equivalence classes cannot be 2equivalent, in view of Proposition 6A(b). Consider first {s2 , s5 , s6 }. Note that
(s2 , 0) = s5
=1 s2 = (s5 , 0)

and

(s2 , 1) = s2
=1 s5 = (s5 , 1).

It follows from Proposition 6A(c) that s2


=2 s5 . On the other hand,
(s2 , 0) = s5 6
=1 s1 = (s6 , 0).
6 2 s6 also. Consider now {s3 , s4 }. Note that
It follows that s2
6 2 s6 , and hence s5
=
=
(s3 , 0) = s2
=1 s5 = (s4 , 0)

and

(s3 , 1) = s4
=1 s3 = (s4 , 1).

It follows that s3
=2 s4 . Hence
P2 = {{s1 }, {s2 , s5 }, {s3 , s4 }, {s6 }}.
We now examine the 2-equivalence classes {s2 , s5 } and {s3 , s4 } separately to determine the possibility
of 3-equivalence. Consider first {s2 , s5 }. Note that
(s2 , 0) = s5
=2 s2 = (s5 , 0)

and

(s2 , 1) = s2
=2 s5 = (s5 , 1).

It follows from Proposition 6A(c) that s2


=3 s5 . On the other hand,
(s3 , 0) = s2
=2 s5 = (s4 , 0)

and

(s3 , 1) = s4
=2 s3 = (s4 , 1).

It follows that s3
=3 s4 . Hence
P3 = {{s1 }, {s2 , s5 }, {s3 , s4 }, {s6 }}.
Clearly P2 = P3 . It follows that the process ends. We now choose one state from each equivalence class
to obtain the following simplified transition table:
0
s1
s2
s3
s6
Chapter 6 : Finite State Machines

0
1
0
1

1
0
0
0

s3
s2
s2
s1

1
s3
s2
s3
s6
page 14 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

Next, we repeat the entire process in a more efficient form. We observe easily from the transition table
that
P1 = {{s1 }, {s2 , s5 , s6 }, {s3 , s4 }}.
Let us label these three 1-equivalence classes by A, B, C respectively. We now attach an extra column
to the right hand side of the transition table where each state has been replaced by the 1-equivalence
class it belongs to.

0
s1
s2
s3
s4
s5
s6

0
1
0
0
1
1

1
0
0
0
0
0

s4
s5
s2
s5
s2
s1

=1

s3
s2
s4
s3
s5
s6

A
B
C
C
B
B

Next, we repeat the information on the next-state function, again where each state has been replaced
by the 1-equivalence class it belongs to.

0
s1
s2
s3
s4
s5
s6

0
1
0
0
1
1

1
0
0
0
0
0

s4
s5
s2
s5
s2
s1

=1

s3
s2
s4
s3
s5
s6

A
B
C
C
B
B

C
B
B
B
B
A

1
C
B
C
C
B
B

Recall that to get 2-equivalence, two states must be 1-equivalent, and their next states must also be
1-equivalent. In other words, if we inspect the new columns of our table, two states are 2-equivalent
precisely when the patterns are the same. Indeed,
P2 = {{s1 }, {s2 , s5 }, {s3 , s4 }, {s6 }}.
Let us label these four 2-equivalence classes by A, B, C, D respectively. We now attach an extra column
to the right hand side of the transition table where each state has been replaced by the 2-equivalence
class it belongs to.

0
s1
s2
s3
s4
s5
s6

0
1
0
0
1
1

1
0
0
0
0
0

s4
s5
s2
s5
s2
s1

=1

s3
s2
s4
s3
s5
s6

A
B
C
C
B
B

C
B
B
B
B
A

=2

C
B
C
C
B
B

A
B
C
C
B
D

Next, we repeat the information on the next-state function, again where each state has been replaced
Chapter 6 : Finite State Machines

page 15 of 21

616

W W L Chen : Discrete Mathematics

Discrete Mathematics

W W L Chen, 1991, 2008

by the
the 2-equivalence
2-equivalence class
class it
it belongs
belongs to.
to.
by
00
00
11
00
00
11
11

ss11
ss22
ss33
ss44
ss55
ss66

11
11
00
00
00
00
00

00
ss44
ss55
ss22
ss55
ss22
ss1

=11

11
ss33
ss22
ss44
ss33
ss55
ss6

A
A
B
B
C
C
C
C
B
B
B
B

0
0 11
C C
C
C
B
B
B B
B C
C
B
B
C
B C
B
B
B B
A B
B
A

0
0 11
C C
C
C
B
B
B B
B C
C
B
B
C
B C
B
B
B B
A D
D
A

=22

=
A
A
B
B
C
C
C
C
B
B
D
D

Recall that
that to
to get
get 3-equivalence,
3-equivalence, two
two states
states must
must be
be 2-equivalent,
2-equivalent, and
and their
their next
next states
states must
must also
also be
be
Recall
2-equivalent.
In
other
words,
if
we
inspect
the
new
columns
of
our
table,
two
states
are
3-equivalent
2-equivalent. In other words, if we inspect the new columns of our table, two states are 3-equivalent
precisely when
when the
the patterns
patterns are
are the
the same.
same. Indeed,
Indeed,
precisely
P33 =
= {{s
{{s11},
}, {s
{s22,, ss55},
}, {s
{s33,, ss44},
}, {s
{s66}}.
}}.
P
Let us
us label
label these
these four
four 3-equivalence
3-equivalence classes
classes by
by A,
A, B,
B, C,
C, D
D respectively.
respectively. We
We now
now attach
attach an
an extra
extra column
column
Let
to
the
right
hand
side
of
the
transition
table
where
each
state
has
been
replaced
by
the
3-equivalence
to the right hand side of the transition table where each state has been replaced by the 3-equivalence
class it
it belongs
belongs to.
to.
class

ss11
ss22
ss33
ss44
ss55
ss66

00
00
11
00
00
11
11

11
11
00
00
00
00
00

00
ss44
ss55
ss22
ss55
ss22
ss11

0
0 11
C C
C
C
B
B
B B
B C
C
B
B
C
B C
B
B
B B
A B
B
A

=11
=
A
A
B
B
C
C
C
C
B
B
B
B

11
ss33
ss22
ss44
ss33
ss55
ss66

=22
=
A
A
B
B
C
C
C
C
B
B
D
D

0
0 11
C C
C
C
B
B
B B
B C
C
B
B
C
B C
B
B
B B
A D
D
A

=33
=
A
A
B
B
C
C
C
C
B
B
D
D

It follows
follows that
that the
the process
process ends.
ends. We
We now
now choose
choose one
one state
state from
from each
each equivalence
equivalence class
class to
to obtain
obtain the
the
It
simplified transition
transition table
table as
as earlier.
earlier.
simplified

6.7. Unreachable
UnreachableStates
States
6.7.
There may
may be
be aa further
further step
step following
following minimization,
minimization, as
as it
it may
may not
not be
be possible
possible to
to reach
reach some
some of
of the
the states
states
There
of
a
finite
state
machine.
Such
states
can
be
eliminated
without
affecting
the
finite
state
machine.
of a finite state machine. Such states can be eliminated without affecting the finite state machine.
shall
illustrate
this
point
considering
example.
WeWe
shall
illustrate
this
point
byby
considering
anan
example.
Example 6.7.1.
Notethat
thatininExample
Example6.6.1,
6.6.1, we
we have
have not
not included
included any
any information
information on
on the
the starting
starting
Example
6.7.1. Note
state.
If
s
is
the
starting
state,
then
the
original
finite
state
machine
can
be
described
by
the
following
state. If s11 is the starting state, then the original finite state machine can be described by the following
state diagram:
diagram:
state
1,0

start

s1
0,1

s6

1,1

0,0

0,0

s3
1,0

s4

1,0

s2
0,1

0,0

0,1

s5
1,0

1,0

Chapter 6 : Finite State Machines

page 16 of 21

c W W L Chen, 1991,617

2008
Chapter 6 : Finite State Machines

Discrete Mathematics

Chapter 6 : Finite State Machines

617

After minimization,
minimization, the
the finite
finite state
state machine
machine can
can be
be described
described by
by the
the following
following state
state diagram:
diagram:
After
After minimization, the finite state machine can be described by the following
state diagram:
1,0
start

s1

start

s1

0,0
1,1
0,0
1,1

0,1

s3

0,0

s3

0,0

1,0

s2
s2

1,0

0,1

1,0

0,1

0,1

s6
s6

1,0

1,0
It is clear that in both cases, if we start at
state s1 , then it is impossible to reach state s6 . It follows
It is clear that in both cases, if we start at state s1 , then it is impossible to reach state s6 . It follows
that
state
s
is
essentially
redundant,
and
we
may somit
it. it
As a result, we obtain
a finite
6
It
is clear
both cases,
if we start
to reach
state state
s6 . Itmachine
follows
1 , then
that
state that
s6 is in
essentially
redundant,
andatwestate
may omit
it. Asisa impossible
result, we obtain
a finite
state
machine
described
by
the
transition
table
that
state
s
is
essentially
redundant,
and
we
may
omit
it.
As
a
result,
we
obtain
a
finite
state
machine
described by6 the transition table
described by the transition table

1
0
0 1
0 1
0 1
+s1 +
0 1
s03 s13
+s
+
s21+
100 011
ss23 ss23
+s
1
3
3
ss32
011 00
ss22 ss32
2
2
s
0 0
s s2
s33
0 0
s22 s33
or the following state diagram:
or the
the following
following state
state diagram:
diagram:
or
1,0

start

s1

start

s1

0,0
1,1
0,0
1,1

s3

0,0

s3

0,0

1,0

s2
s2

1,0

0,1

1,0

0,1

States such as s6 in Example 6.7.1 are said to be unreachable from the starting state, and can
therefore
besuch
removed
affecting the finite state machine, provided that we do not alter the starting
States
as swithout
6 in Example 6.7.1 are said to be unreachable from the starting state, and can
state.
Such
unreachable
states
may
removed
prior
to the Minimization
process,
or afterwards
if they
States
such
as
s
in
Example
6.7.1be
arethe
said
to be
unreachable
from the starting
state,
and
6
therefore be removed without affecting
finite
state
machine,
provided
that
we do
not
altercan
thetherefore
starting
still
remain
at
the
end
of
the
process.
However,
if
we
design
our
finite
state
machines
with
care,
then
be
removed
without
affecting
the
finite
state
machine,
provided
that
we
do
not
alter
the
starting
state. Such unreachable states may be removed prior to the Minimization process, or afterwards ifstate.
they
such
states
should
normally
not
arise.
Such
unreachable
states
may
be
removed
prior
to
the
Minimization
process,
or
afterwards
if
they
still
still remain at the end of the process. However, if we design our finite state machines with care, then
remain
at
the
end
of
the
process.
However,
if
we
design
our
finite
state
machines
with
care,
then
such
such states should normally not arise.
states should normally not arise.
Problems for Chapter 6
Problems for Chapter 6
1. Consider the finite state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
diagram
below:
1. state
Consider
the finite
state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
state diagram below:
0,0
0,1
0,0
start
start

0,0

1,0

s1
s1

s2

1,1

1,0

s2

1,1

s4

1,1

s5

s4

1,1

s5

0,0
0,0

1,1

a)
b)
a)
c)
b)
d)
c)

0,1

1,0
0,0
s
1,0 3
0,0

s3

0,0

What is the output string for the input string1,1


110111? What is the last transition state?
Repeat
part
(a)
by
changing
the
starting
state
to s2 , s3 ,What
s4 and
5 . last transition state?
What is the output string for the input string 110111?
is sthe
Construct
the
transition
table
for
this
machine.
Repeat part (a) by changing
the starting state to s2 , s3 , s4 and s5 .
Find
an input
x table
I of for
minimal
length and which satisfies (s5 , x) = s2 .
Construct
the string
transition
this machine.

d) Find an input string x I of minimal length and which satisfies (s5 , x) = s2 .

Chapter 6 : Finite State Machines

page 17 of 21

States such as s6 in Example 6.7.1 are said to be unreachable from the starting state, and can
therefore be removed without affecting the finite state machine, provided that we do not alter the starting
state. Such unreachable states may be removed prior to the Minimization process, or afterwards if they
still
remain at the end of the process. However, if we design our finite state machines
care, then
c W W Lwith

Chen, 1991, 2008
Discrete Mathematics
such states should normally not arise.

Problems for Chapter 6


Problems for Chapter 6
1. Consider
Consider the
the finite
finite state
state machine
machine M
M =
= (S,
(S, I,
I, O,
O, ,
, ,
, ss1),
), where
where II =
=O
O=
= {0,
{0, 1},
1}, described
described by
by the
the
1.
1
state
diagram
below:
state diagram below:
0,0

0,1

s1

start

1,0

s2

1,1

s4

1,1

s5

0,0

0,0
1,0

s3
0,0

1,1

618 a) What is
Wthe
W output
L Chenstring
: Discrete
Mathematics
for the
input string 110111? What is the last transition state?
a) What is the output string for the input string 110111? What is the last transition state?
b) Repeat part (a) by changing the starting state to s2 , s3 , s4 and s5 .
b) Repeat part (a) by changing the starting state to s2 , s3 , s4 and s5 .
c) Construct the transition table for this machine.
c)d)Construct
transition
forminimal
this machine.
Find an the
input
string x table
I of
length and which satisfies (s5 , x) = s2 .
d)
Find
an
input
string
x

I
of
minimal
2. Suppose that |S| = 3, |I| = 5 and |O| = 2.length and which satisfies (s5 , x) = s2 .
a) How many elements does the set S I have?
2. Suppose that |S| = 3, |I| = 5 and |O| = 2.
b) How many different functions : S I O can one define?
a) How many elements does the set S I have?
How
many
different
functions
I
S can
define?
b) c)
How
many
different
functions
: S :S I
O can
oneone
define?
How
many
different
finite state
(S, define?
I, O, , , s1 ) can one construct?
c) d)
How
many
different
functions
: Smachines
I SM
can=one
d) How many different finite state machines M = (S, I, O, , , s1 ) can one construct?
3. Consider the finite state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
3. Consider
finite
state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
transitionthe
table
below:
transition table below:

0 1
0 1
00 10
0s 1s
s
1

ss12
s2

01 01
1 1

ss11 ss22
s1 s2

a) Construct the state diagram for this machine.


a) b)
Construct
the the
state
diagram
for this
machine.
Determine
output
strings
for the
input strings 111, 1010 and 00011.
b) Determine the output strings for the input strings 111, 1010 and 00011.
Consider the
the finite
finite state
state machine
machine M
M == (S,
(S,I,
I,O,
O,,
,,,ss11),), where
where II == O
O == {0,
{0,1},
1}, described
described by
by the
the
4.4. Consider
state
diagram
below:
state diagram below:
0,0

0,0

s1

start

1,0

0,0

s2

1,0

1,1

1,0

s6
0,0

a)
b)
c)
d)

s3

1,0

s5

1,0

0,0

s4
0,0

Find
thethe
output
string
for for
thethe
input
string
0110111011010111101.
a)
Find
output
string
input
string
0110111011010111101.
Construct
thethe
transition
table
for for
thisthis
machine.
b)
Construct
transition
table
machine.
Determine
all all
possible
input
strings
which
givegive
thethe
output
string
0000001.
c)
Determine
possible
input
strings
which
output
string
0000001.
Describe
in
words
what
this
machine
does.
d) Describe in words what this machine does.
page 18 of 21

Chapter 6 : Finite State Machines

5. Suppose that I = O = {0, 1}. Apply the Minimization process to each of the machines described
by the following transition tables:

Discrete Mathematics

W W L Chen, 1991, 2008

5. Suppose that I = O = {0, 1}. Apply the Minimization process to each of the machines described
by the following transition tables:

0
s1
s2
s3
s4
s5
s6
s7
s8

0
1
1
0
0
0
0
0

0
0
1
1
1
0
1
0

s6
s2
s6
s5
s4
s2
s3
s2

s3
s3
s4
s2
s2
s6
s8
s7

s1
s2
s3
s4
s5
s6
s7
s8

0
0
0
0
0
1
1
0

0
0
0
0
0
0
1
0

s6
s3
s2
s7
s6
s5
s4
s2

1
s3
s1
s4
s4
s7
s2
s1
s4

6. Consider the finite state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
transition table below:
0
s1
s2
s3
s4
s5
s6

1
0
0
0
0
0

1
1
1
0
1
0

s2
s4
s3
s1
s5
s1

1
s1
s6
s5
s2
s3
s2

a) Find the output string corresponding to the input string 010011000111.


b) Construct the state diagram corresponding to the machine.
c) Use the Minimization process to simplify the machine. Explain each step carefully, and describe
your result in the form of a transition table.
7. Consider the finite state machine M = (S, I, O, , , s1 ), where I = O = {0, 1}, described by the
transition table below:
0
s1
s2
s3
s4
s5
s6
s7
s8
s9

1
0
0
0
0
0
0
0
0

1
1
1
0
1
0
0
1
0

s2
s4
s3
s1
s5
s1
s1
s5
s1

1
s1
s6
s5
s2
s3
s2
s2
s3
s2

a) Find the output string corresponding to the input string 011011001011.


b) Construct the state diagram corresponding to the machine.
c) Use the Minimization process to simplify the machine. Explain each step carefully, and describe
your result in the form of a transition table.
Chapter 6 : Finite State Machines

page 19 of 21

s6
s7
s8
s9

0
0
0
0

0
0
1
0

s1
s1
s5
s1

s2
s2
s3
s2

Find the
Discretea)Mathematics

output string corresponding to the input string 011011001011.


c W W L Chen, 1991, 2008

b) Construct the state diagram corresponding to the machine.
c) Use the Minimization process to simplify the machine. Explain each step carefully, and describe
your result in the form of a transition table.

8.
8. Consider
Consider the
the finite
finite state
state machine
machine M
M=
= (S,
(S, I,
I, O,
O, ,
, ,
, ss11),
), where
where II =
=O
O=
= {0,
{0, 1},
1}, described
described by
by the
the
state
diagram
below:
state diagram below:
0,0

start

s1
1,1

s2

1,0
1,1

1,1

0,0

0,1

0,0

s3

s4

s5
0,1

1,1

0,0

0,1

1,0

s7
0,1

s8

1,0

s6
1,0

a)
b)
c)
d)

Write down the output string corresponding to the input string 001100110011.
Write down the transition table for the machine.
Apply the Minimization process to the machine.
Can we further reduce the number of states of the machine? If so, which states can we remove?

9. Suppose that I = O = {0, 1}.


a) Design a finite state machine that will recognize the 2-nd, 4-th, 6-th, etc, occurrences of 1s in
the input string (e.g. 0101101110).
b) Design a finite state machine that will recognize the first 1 in the input string, as well as the 2-nd,
4-th, 6-th, etc, occurrences of 1s in the input string (e.g. 0101101110).
c) Design a finite state machine that will recognize the pattern 011 in the input string.
d) Design a finite state machine that will recognize the first two occurrences of the pattern 011 in
the input string.
e) Design a finite state machine that will recognize the first two occurrences of the pattern 101 in
the input string, with the convention that 10101 counts as two occurrences.
f) Design a finite state machine that will recognize the first two occurrences of the pattern 0100 in
the input string, with the convention that 0100100 counts as two occurrences.
10. Suppose that I = O = {0, 1}.
a) Design a finite state machine that will recognize the pattern 10010.
b) Design a finite state machine that will recognize the pattern 10010, but only when the last 0 in
the sequence pattern occurs at a position that is a multiple of 5.
c) Design a finite state machine that will recognize the pattern 10010, but only when the last 0 in
the sequence pattern occurs at a position that is a multiple of 7.
11. Suppose that I = {0, 1, 2} and O = {0, 1}.
a) Design a finite state machine that will recognize the 2-nd, 4-th, 6-th, etc, occurrences of 1s in
the input string.
b) Design a finite state machine that will recognize the pattern 1021.
12. Suppose that I = O = {0, 1, 2}.
a) Design a finite state machine
every input string x1 . . . xk in
b) Design a finite state machine
every input string x1 . . . xk in
Chapter 6 : Finite State Machines

which gives the output string x1 x1 x2 x3 . . . xk1 corresponding to


I k . Describe your result in the form of a state diagram.
which gives the output string x1 x2 x2 x3 . . . xk1 corresponding to
I k . Describe your result in the form of a state diagram.
page 20 of 21

Discrete Mathematics

W W L Chen, 1991, 2008

13. Suppose that I = O = {0, 1, 2, 3, 4, 5}.


a) Design a finite state machine which inserts the digit 0 at the beginning of any string beginning
with 0, 2 or 4, and which inserts the digit 1 at the beginning of any string beginning with 1, 3 or
5. Describe your result in the form of a transition table.
b) Design a finite state machine which replaces the first digit of any input string beginning with 0,
2 or 4 by the digit 3. Describe your result in the form of a transition table.

Chapter 6 : Finite State Machines

page 21 of 21

You might also like