Download - SR2_DFA
-
8/12/2019 SR2_DFA
1/27
CSE 211: Deterministic Finite Automaton
Md. Shaifur Rahman
Dept. of CSEBangladesh University of Engineering & Technology
Class 2-3
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 1 / 20
-
8/12/2019 SR2_DFA
2/27
Outline
1 What is Finite Automaton(FA)
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 2 / 20
-
8/12/2019 SR2_DFA
3/27
Outline
1 What is Finite Automaton(FA)
2 State Diagram of FA
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 2 / 20
-
8/12/2019 SR2_DFA
4/27
-
8/12/2019 SR2_DFA
5/27
Outline
1 What is Finite Automaton(FA)
2 State Diagram of FA
3 Formal Definition of FA
4 Examples of FA
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 2 / 20
-
8/12/2019 SR2_DFA
6/27
Outline
1 What is Finite Automaton(FA)
2 State Diagram of FA
3 Formal Definition of FA
4 Examples of FA
5 Computation by FA
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 2 / 20
-
8/12/2019 SR2_DFA
7/27
Outline
1 What is Finite Automaton(FA)
2 State Diagram of FA
3 Formal Definition of FA
4 Examples of FA
5 Computation by FA
6 What is Regular Language (RL)
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 2 / 20
-
8/12/2019 SR2_DFA
8/27
What is Finite Automaton (FA)
Finite Automaton
has a very small amount of memory
Example: the controller for an automatic door
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 3 / 20
-
8/12/2019 SR2_DFA
9/27
State diagram of a Finite Automaton
Three states: q1, q2
andq3
Start state: q1
Accept state: q2
Transition: arrows
For Input: 11011 Start in state q12 Read 1, follow transition from q1 to q23 Read 1, follow transition from q2 to q24 Read 0, follow transition from q2 to q35 Read 1, follow transition from q3 to q26 Accept because M1 is in an accept state q2
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 4 / 20
-
8/12/2019 SR2_DFA
10/27
State diagram of a Finite Automaton (Contd.)
For input1111, the states are: q1q2q2q2q2 the finalstate: q2, soAccept
For input0110, the states are: q1q1q2q2q3 the final
state: q3, soRejectFor input101010, the states are:q1q2q3q2q3q2q3 the final state: q3, soReject
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 5 / 20
-
8/12/2019 SR2_DFA
11/27
State diagram of a Finite Automaton (Contd.)
What types of inputs are accepted by M1?
Accepts:01, 001, 0001, 00001, . . . , 0101, 0100, 0101, . . . , 01101, 011101, . . .
Rejects: all other strings
Observation: M1 accepts any string that ends with a 1 ANDhas evennumber of0s after the last 1
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 6 / 20
-
8/12/2019 SR2_DFA
12/27
Formal Definition of Finite Automaton
A Finite Automaton (FA) is a 5-tuple (Q, , , q 0, F) where
Q is the set ofall states
is the set ofall input symbols(also called alphabet): Q Q is thetransition function
q0Q is thestart-state
FQ is the set ofaccept-states
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 7 / 20
-
8/12/2019 SR2_DFA
13/27
Example of Formal Definition of FA
Q= {q1, q2, q3} ={0, 1}
is:0 1
q1 q1 q2q2 q3 q2q3 q2 q2
start-state,q0=q1
accept-states, F ={q2}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 8 / 20
-
8/12/2019 SR2_DFA
14/27
FA and its Language
A: is the set of all strings that the FA M accepts
A is thelanguageofM, written as L(M) =A
M recognizeslanguage A
ifM recognizes no strings, L(M) =A= an Mmay accept more than one strings, but it recognizesonly onelanguage
In our previous example,
A={w|w contains at least one 1 and even number of0s following that 1}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 9 / 20
-
8/12/2019 SR2_DFA
15/27
Examples of FA
M2= ({q1, q2}, {0, 1}, , q 1, {q2}) where is:0 1
q1 q1 q2q2 q1 q2
M2 accepts string 1101 as follows: q1q2q2q1q2
M2 rejects string 1010 as follows: q1q2q1q2q1
M2 accepts the language of strings that ends with 1
L(M2) ={w|w ends with 1}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 10 / 20
( )
-
8/12/2019 SR2_DFA
16/27
Examples of FA(Contd.)
M3= ({q1, q2}, {0, 1}, , q 1, {q1}) where is:
0 1
q1 q1 q2q2 q1 q2
M3 accepts string 1101 as follows: q1q2q2q1q2
M3 rejects string 1010 as follows: q1q2q1q2q1
M3 accepts the empty string or the string that ends with 0L(M3) ={w|w is or ends with 0}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 11 / 20
E l f FA(C d )
-
8/12/2019 SR2_DFA
17/27
Examples of FA(Contd.)
M4= ({s, q1, q2, r1, r2}, {a, b},,s, {q1, r1}), two accepting states!
M4 starts in State s
ifa, goes to State q1, accepts if the last symbol is a
ifb, goes to State r1, accepts if the last symbol is b
M4 accepts a, aa, aaa, aba, . . . , b, bb, bab, bbb, . . .
L(M4) ={w|w starts and ends with the same symbol}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 12 / 20
E l f FA(C d )
-
8/12/2019 SR2_DFA
18/27
Examples of FA(Contd.)
M5= ({q0, q1, q2}, {RESET, 0, 1, 2}, , q 0, {q0})
M5 keeps a running count of the sum of the numerical input symbolsit reads, modulo 3
Accepts when the sum is a multiple of3
RESET sets the sum to zero
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 13 / 20
E l f FA(C d )
-
8/12/2019 SR2_DFA
19/27
Examples of FA(Contd.)
State Diagram for FA is cool but not always possible!
For example:
Generalized ModuloMachine
For each i1 let Ai ={all strings where the sum of the numbers isa multiple of i}, also the sum is zero when the input is RESET
FA Bi recognizes language Ai
Bi = (Qi, , i, q0, {q0})
Here, Qi ={q0, q1, q2, . . . , q i1}
For each state qj , ifBi is in qj , i is:i(qj , 0) =qji(qj , 1) =qk where k=j+ 1 modulo ii(qj , 2) =qk where k=j+ 2 modulo ii(qj , RESET) =q0
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 14 / 20
T Y lf
-
8/12/2019 SR2_DFA
20/27
Try Yourself
Question
Show how M1 and M2 accept/reject the strings aabb, ababandaaabbb.
Formally describe FA M1 and M2.
What do the machines do? Can you comment on their languages?
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 15 / 20
T Y lf
-
8/12/2019 SR2_DFA
21/27
Try Yourself
QuestionDraw the state diagram for the following FA:M6= ({q1, q2, q3, q4, q5}, {u, d}, , q 3, {q3}) and is:
u d
q1 q1 q2q2 q1 q3q3 q2 q4q4 q3 q5
q5 q4 q5
What does M6 do? Comment on the language it recognizes.
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 16 / 20
Formal Definition of Computation
-
8/12/2019 SR2_DFA
22/27
Formal Definition of Computation
Let M= (Q, , , q 0, F) be an FAw=w1w2. . . wn be a string where wi M accepts w if there arestates r0, r1, . . . , rnQ and
1 r0=q0
2 (ri, wi+1) =ri+1 fori= 0, 1, . . . , n 1 and3 rn F
M recognizeslanguage L(M) =A ifA= {w| M accepts w}
Regular LanguageA is a Regular Language (RL) if it is recognized by some FiniteAutomaton M.
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 17 / 20
Testing for RL
-
8/12/2019 SR2_DFA
23/27
Testing for RL
Is the following an RL?
A= {w| the sum of the symbols in w is 0 modulo 3, except thatRESET resets the count to 0}
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 18 / 20
Testing for RL
-
8/12/2019 SR2_DFA
24/27
Testing for RL
Is the following an RL?
A= {w| the sum of the symbols in w is 0 modulo 3, except thatRESET resets the count to 0}
YES, Find an FA that recognizes A:
M5
Ifw= 10RESET22RESET012,
q0q1q1q0q2q1q0q0q1q0Shaifur (CSE, BUET) CSE211: DFA Class 2-3 18 / 20
Next Class
-
8/12/2019 SR2_DFA
25/27
Next Class . . .
Can we design an FA for any arbitrary language?
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 19 / 20
Next Class
-
8/12/2019 SR2_DFA
26/27
Next Class . . .
Can we design an FA for any arbitrary language?
Can we combine existing languages to derive/define new languages?
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 19 / 20
-
8/12/2019 SR2_DFA
27/27
Question?
Shaifur (CSE, BUET) CSE211: DFA Class 2-3 20 / 20