Definition of a Finite State Machine

advertisement
Lecture 23:
Finite State Machines with no Outputs
Acceptors & Recognizers
Introduction
Finite State Machines (FSMs) are theoretical models of computational systems. Finite state
machines, also called finite automata, are used in the study of the theory of computation.
R = right
L = left
U = up
D = down
Formal Definition
Definition of a Finite State Machine - Formally, a finite Automaton (FA) is defined as a 5-tuple
(Q,S, d, q0, F) where,
(1) Q is a finite set of states.
(2) S is a finite set of symbols or the alphabet.
(3) d: Q x S -> Q is the transition function
(4) q0 is an element of Q called the start state, and
(5) F is a subset of Q called the set of accept states.
An Example
Q = {1, 2, 3, 4, 5, 6}
q0 = 1 (start state)
S = {U, D, L, R}
F = {6}
An FSM to Recognize (Accept) Integers
Valid Integers
123
123456
-543
9
Not an Integer
123.456
12+345
Hello There
9
3
5
How to Implement an FSM in a Computer Program
Example Binary String Recognizer
accepts strings containing at least three 1's
The double circle indicates the accept state, the start state is labeled (0), and the transitions
between states are labeled according the input symbol currently being read. The binary
strings below, are accepted or rejected as indicated,
01010000
reject
01001110
accept
0111
accept
110000
reject
Example Binary String Recognizer
accepts strings containing three consecutive 1's
Applying this FSM to the sample binary strings listed below gives the indicated results.
0000110011001100
reject
0001110000000000
accept
1010101010000000
reject
11111111
accept
Building Finite State Machines
Consider an FSM that accepts (or recognizes) strings containing the substring "1101". We
create a start state and a state for each bit in the substring for which we are searching.
Accepting Binary Encoded Values
divisible by four
Dual Parity Tester
We can check the parity of 1's or 0's or both in a binary value using an FSM. In this example, we
want an FSM that accepts binary strings with an even number of 0's and an even number of 1's.
The start state is an accept state since the empty string has zero 0's and zero 1's (and zero is even).
Computational Limits of Finite State Machines
Counting 1's and 0's - Consider the design of an FSM that accepts all binary strings that
have an equal number of 1's and 0's. At first this may seem to be a relatively simple
problem; however, we need to deal with the possibility that the count of the number of 1's
or 0's could grow without bound.
We can produce a partial FSM for recognizing binary strings with the same number of 1's
and 0's, but a consecutive number of 1's or 0's could occur which would exceed any finit
number of states in the FSM.
FSM for Recognizing Binary Palindromes
In our example problem, we want to design an FSM that accepts all binary strings that have the
same sequence of 1's and 0's when read either left-to-right or right-to-left. Again, we are limited
by the fact that an input string can be arbitrarily long. In this case however, the FSM is
impractical even for strings of finite length. For binary strings of maximum length Nmax, our
palindromic binary string recognizer uses 2Nmax+1-1 states
Describe the Language Recognized by this FSM
Download