Beruflich Dokumente
Kultur Dokumente
Finite automata - also known as nite state machines - are one of the simplest models of computation. They are excellent models for computers with an extremely limited amount of memory. Examples: automatic door at supermarket elevator controls vending machine calculators Finite automata are also the basis for programs that perform spell checking, grammar checking, indexing. They are fundamental in the study of compilers.
Finite Automata
CIS 3150
Joe Sawada - University of Guelph
CIS 3150
Finite Automata
1 / 25
CIS 3150
Finite Automata
2 / 25
Automatic Door
CLOSED
OPEN
NEITHER
Note that the controller only needs a single bit of memory to remember what state it is in.
CIS 3150
Finite Automata
3 / 25
CIS 3150
Finite Automata
4 / 25
Finite Automata
From last example, notice that we can represent the Automatic Door Contoller either using a state diagram or a transition table. Depending on the size of your problem (controller) one method may be easier to understand than the other. When designing more complicated devices, using a standard methodology and terminology becomes very important. We must be a bit more formal when dening both state diagrams and nite automatons.
CLOSED
OPEN
NEITHER
CLOSED OPEN
CIS 3150
Finite Automata
5 / 25
CIS 3150
Finite Automata
6 / 25
Formal Denition: FA
Denition
A nite (state) automaton is a 5-tuple M = (Q, , , q0 , F ) where: Q: a nite set of states : a nite input alphabet : Q Q a transition function F Q: the set of accept (nal) states q0 Q: the initial or start state
Final states are drawn with double circles A special arrow indicates the start state Example: Three consecutive 1s
1 0 1 1
A
s
0,1
This FA ends up in an accept state if and only if the input contains 3 consecutive ones. Note: can be determined from the input on the arcs.
CIS 3150 Finite Automata 7 / 25 CIS 3150 Finite Automata 8 / 25
FA Terminology
In the last example, we say that all input strings with 3 consecutive 1s are recognized or accepted by the nite automaton M - since they all end up in an accept state.
Denitions
We say that an input string is accepted by a nite state automaton M if it starts from q0 and ends at an accept state. The language recognized by a nte automaton M , denoted L(M ) is the set of all strings that are accepted by M .
1 D A A D
b q2 q2 q2
An important question we will ask later: Does every language L1 have a corresponding nite automaton M such that L(M ) = L1 ?
5. F = {B, D}
CIS 3150
Finite Automata
9 / 25
CIS 3150
Finite Automata
10 / 25
Describe Languages
What languages are recognized by the following FA?
0 0
A C
1
A
s
1 1
0,1
1 1
0,1
1 1 0 0 0 1 1
1 1 0 0 0 1 1
A B
0
B
0
A
s
0,1
0,1
(1) L1 = { (01)n | n 1} (2) L2 = all binary strings except the substring 000 or ending 10.
CIS 3150 Finite Automata 11 / 25 CIS 3150
Finite Automata
12 / 25
Example
Example
Design a FA that will recognize the set {1, 00}.
A
s 0
B
0,1 1
C
0
E
0,1
0,1
CIS 3150
Finite Automata
13 / 25
CIS 3150
Finite Automata
14 / 25
More Examples
Design FA that recognize the following languages over the alphabet {0, 1}: L1 = {w | w has an odd number of 1s} L2 = {w | w contains substring 110} L3 = {w | w contains more 0s than 1s} What is the underlying reason why we cant build one for L3 ?
Formally, we want a more precise notion of what it means for a string to be accepted by a nite automaton M = (Q, , , q0 , F ).
Denition
M accepts a string w = w1 w2 wn if a sequence of states r0 , r1 , . . . rn in Q exists with the three conditions: r0 = q0 (ri , wi+1 ) = ri+1 rn F for i = 0 to n 1
CIS 3150
Finite Automata
15 / 25
CIS 3150
Finite Automata
16 / 25
Regular Operations
Denition
A language is called a regular language if some nite automaton recognizes it.
Regular Operations
Theorem
The class of regular languages is closed under each of the three regular operations: union, concatenation, star.
Regular Operations
Let A and B be languages. Concatenation: A B = {xy | x A and y B} Union: A B = {x | x A or y B}
N is not closed under subtraction since x = 2 and y = 1 are both in this set but 1 2 = 1 is not.
In other words, if you are given two regular languages A and B, you can apply any sequence of the operations union, concatenation, star to these languages and the resulting language will also be regular. We will prove this theorem after we introduce non-determinism.
A = { , a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb, . . .}
CIS 3150 Finite Automata 17 / 25
CIS 3150
Finite Automata
18 / 25
Non-determinism
All the examples we have looked at so far have been deterministic: for each state and input pair, there was a unique state given by the transition function. If for each such pair, there is more than one possible next state, then we say the machine is non-deterministic: the next state is not necessarily uniquely determined. To dene such a machine, we simply need to redene the transition function. Denition
A non-deterministic nite automaton (NFA) is a 5-tuple M = (Q, , , q0 , F ) where: Q: a nite set of states : a nite input alphabet : Q P(Q) is a transition function q0 S: called the initial or start state F a subset of Q called the accepting or nal states The new transition function maps an input state pair to a set of states which may be empty. Also the input may be empty: includes the empty string .
Non-Determinism
Example of a non-deterministic FA
0
A
s
B
1
notice the null transition notice that the input/state pair (A,0) has multiple transitions notice that the input/state pair (A,1) has no transition
NOTE: If there is no transition for an input, state pair, then the machine stops, rejecting the input. This simplies the diagram by eliminating the need to have a sink state.
CIS 3150
Finite Automata
19 / 25
CIS 3150
Finite Automata
20 / 25
Non-Determinism
Another example of a non-deterministic FA
1 1 0 0 0 0 0
Where could the input 0001 end up? A or B or C.
Non-Determinism
A
s 1
B
1 1 0
0,1
The denitions for recognize or accept are slightly dierent for non-deterministic FA (NFA), since the same input string could end up at more than one state. Denition
A NFA is said to recognize or accept an input string x, if there exists a nal state that can be obtained from s0 using x. The language recognized by a NFA M is the set of all strings recognized by M .
CIS 3150
Finite Automata
21 / 25
CIS 3150
Finite Automata
22 / 25
Non-Determinism
Find the language recognized by the following NFAs.
0
Non-Determinism
Design
Design NFAs that recognize the following languages. Try to use the least number of states possible.
1
A
s
B
0 1
L2 = {1, 00}
L1 = {0}
L3 = {1n | n 2}
A
s
0,1
1
s
s 0
1 0
B A
s 1
L1
L2
L3
CIS 3150
Finite Automata
23 / 25
CIS 3150
Finite Automata
24 / 25
Non-Determinism
Theorem
If the language L is recognized by some NFA M0 , then it can also be recognized by some deterministic FA M1 .
Corollary
A language is regular if and only if some NFA recognizes it.
It turns out that not all languages can be recognized by NFA (ie. there exists non-regular languages). An example of a language that is not regular, and hence can not be recognized by any NFA is: L = {0n 1n | n = 0, 1, 2, . . .}
CIS 3150
Finite Automata
25 / 25