Professional Documents
Culture Documents
METHODS
Lecture 7: Finite state machine models
LECTURER: QURATULAIN
DEPARTMENT OF INFORMATION TECHNOLOGY
GOVERNMENT COLLEGE UNIVERSITY FAISALABAD
FINITE STATE MACHINE
MODELS
Transition Table
Present Next state for Input
Next State of Input b
State a
→q0 q0 q0 F
accepts string of a Accepts ALL strings of a’s
Example :
Example :
Q = {q0, q1}
Q = {q0, q1}
∑ = {a}
∑ = {a}
q0 = {q0}
q0 = {q0}
F = {q1}
F = {q1}
L= {a, aa, aaa, aaaa, aaaaa, ….} a
L={ a }
qo a a
Start q1 qo q1
Start
→q0 q1 →q0 q1
q1 ε q1 q1
Accepts string either starting from a OR b and
followed by any number of a,b
Example :
Q = {q0, q1}
∑ = {a,b}
Start qo a a,b
q1
q0 = {q0}
F = {q1}
b
L={ a, b, ab,ba, abb, baa, bab, aba,….. }
Transition Table
Present Next state for Input
Next State of Input b
State a
→q0 q1 q1
F q1 q1 q1
That accepts strings of a’s and b’s, ending
with A.
Example : b a
a
Q = {q0, q1, q2} Start qo q1
∑ = {a, b}
q0 = {q0}
b
F = {q1}
L= { aa, ab, ba, baa, baba, aba, aba,…}
Transition Table
Present Next state for Input
Next State of Input b
State a
→q0 q1 q0
q1 q1 q0
That accepts strings of a’s and b’s, where all
a’s come before all b’s.
Example : a b
Q = {q0, q1, q2} b
Start qo q1
∑ = {a, b}
q0 = {q0}
F = {q0,q1} a
L= {
Transition Table q2
a,b
Present Next state for Input
Next State of Input b
State a
→q0 q0 q1
q1 q2 q1
F q2 q2 q2
NFA: ACCEPT ALL STRING OF LENGTH AT LEAST 2.
Transition Table
Example 3: Present State Next state for Input 0 Next State of Input 1
*q2 ε ε
Start 0, 1 0,1
qo q1 q2
NFA: ACCEPTS ALL STRINGS STARTING WITH 01.
Example 2: Transition Table
NFA with Present State Next state for Input 0 Next State of Input 1
∑ = {0, 1}
→q0 q1 ε
q1 ε q2
F q2 q2 q2
0, 1
Start 0 1
qo q1 q2
DFA: LANGUAGE IN WHICH0 ALWAYS APPEARS
IN A GROUP OF 3
Example:
Transition Table
Q = {q0, q1, q2}
Present Next state for Next State of
∑ = {0, 1} State Input 0 Input 1
q0 = {q0} →q0 q1 q0
F = {q3} q1 q2 ε
L= {000, 0001,10001,1000,0001000, ….}
q2 q3 ε
q3 q1 q3
1
1
Start 0 0 0
qo q1 q2 q3
0
DFA: ACCEPTS ALL STARTING WITH 0.
Transition Table
Example : Present State Next state for Input 0 Next State of Input 1
DFA with
→q0 q2 q1
∑ = {0, 1} L= {00, 01, 000,
001,…} q1 ε ε
F q2 q2 q2
Start
qo
0 0,1
1
q2
q1
DFA: ACCEPTS THE STRINGS WITH AN EVEN
NUMBER OF 0'S FOLLOWED BY SINGLE 1
Example : 1
0
DFA with ∑ = {0, 1} qo
Start q1
L= {001, 0101, 010001, 01010101,…}
0
1
Transition Table
Present
State
Next state for Input
0
Next State of Input 1 q2
→q0 q2 q1
q1 ε ε
F q2 q2 q2
DFA: ACCEPTS ALL ENDING WITH 0.
Transition Table
Example : Present State Next state for Input 0 Next State of Input 1
q1 q1 q0
qo q1
1
EXAMPLES OF DFA
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.
1
0
Start 1 0
qo q1 q2
1
Home Task:
Draw a Transition Table
EXAMPLES OF DFA
Design a FA with ∑ = {0, 1} accepts the only input 101.
Home Task:
• Create a DFA Diagram
• Draw a Transition Table
EXAMPLES OF DFA
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.
Start 1
0
qo q1
1
1 1 1 1
Home Task:
0 Draw a Transition
q2 q3
Table
0
Next Lecture TYPES OF FINITE STATE
MACHINE