ToA lec 5
ToA lec 5
Remember
Automata)
3 points for DFA
i. no empty string
ii. No. of transaction from each sate is equal to number of
letters given in alphabet.
• For example, if ∑ = {a, b}. This alphabet has two letter i.e, a and b. That
means from every state there will be two transaction. (two arrows on each
state)
iii.
It may also contains reject state.
• Reject state is a state which never allow us to reach final state
DFA (Deterministic Finite
Automata)
To accept a string:
To reject a string:
all the input string is
scanned
DFA
Examples
• Draw DFA for RE = a, defined over ∑ = {a,
b}.
accept state
a a
q1 q2 q1 q2
a a,b
b b OR b
q3 q3
reject state reject state a, b
a, b
DFA
Draw DFA that starts with ‘b’, define over alphabet ∑ = {a,
Examples
b}.
a, b
b accept state
q0 q1
a, b
a
q2
reject state
DFA
Draw DFA for string that starts with ‘ab’, define over alphabet ∑
= Examples
{a, b}.
a, b
a b
q0 q1 q2 Accept state
a
b
q3
reject state
a, b
DFA Examples
Draw DFA for string that starts with ‘aba’, define over
alphabet ∑ =
▶ {a, a, b
b}.
• The RE of above statement will RE= aba (a +
b)* a
be :
a q0 q1 b q2 q3
accept state
a
b
b
q4 a,
reject state b
DFA Examples
Draw DFA for language that has ‘b’ as second letter define
over alphabet ∑ = {a, b}.
• The RE of above statement will be: RE= ( a+ b) b (a + b)*
a, b
a,b b
q0 q1 q2
accept state
a
q3
a, b
reject state
Transition
Table
• Transition table is tabular representation of transition function.
• Transition table shows that which specific transition take place from
specific state.
1, 0
0 1
0
q1 q2 q0 q3 q1
1
q0 1 q1 q1
0 q1, q2
q3
q2 - -
1,
0 q3 q3 q3, q2
Exampl
es a, b
a, b
a a
q0 q1 q2
a b
q0 q0, q1
q0
q1 q2 -
q2 q2 q2
Exam 1,
0
ple
1 0 1
q0 q1 q2 q3
1
0
0
q4 1,
0
1 0
q0 q1 q4
q1 q4 q2
q2 q3 q4
q3 q3 q3
q4 q4 q4
NFA VS
DFA
• In NFA dead configuration is allowed, in DFA dead configuration is not
allowed.
Example
• Draw NFA & DFA for RE = 1, defined over ∑ = {1, 0}.
1
q1 q2
1
q1 q2
1,0
0
NFA q3
1, 0
DFA
NFA VS
DFA
• In NFA multiple transactions are allowed correspond to input while
in DFA multiple transactions are not allowed correspond to input.
Example
• Draw NFA and DFA for RE= (a+b)*b, defined over ∑ = {a, b}.
a, b a
b
b b
q0 q1 q0 q1
a
NFA
DFA q2
a,
b
NFA VS
DFA
• Empty transaction is allowed in NFA while in DFA no empty
transaction is allowed.
• NFA features is not associated with real computers while DFA features is
associated with digital computers.
0) q0
1
q1
1
1
1,0 0
q0 q1 q3
q2
1
1
q0 1
1
q0 q1 q1
1
0 0
q2
q2
TG
•
Examples
Draw a TG that accepts all words with aa or bb defined over ∑ = {a,
b}. RE= (a+b)* (aa + bb) a, b
(a+b)* a, b
a, b
a, b aa
q0 q1
a a
q0 q1 q2
bb q2
a, b
b q3 b
a, b a, b
aa a, b
q0 q1 a, b
aa, bb
a, b q0 q1
bb
q0
Kleene’s Theorem
a b a
q0 q1 q2 q3
aba
q0 q1
a b
a,
b b
q4
reject state
a, b
Kleene’s Theorem Proof (part 3)
• If language can be expressed by RE (Regular Expression) then it can
be accepted by FA (Finite Automata)
• language that has ‘b’ as second letter define over alphabet ∑ = {a,
b}.
RE= ( a + b) b (a + b)*
a, b
a,b b
q0 q1 q2
q3
a, b
r
e
j
Kleene’s Theorem Proof (part 2)
If language can be accepted by TG (Transition Graph) then it can also
be expressed by RE (Regular Expression).
For the proof of part 2, we need to remember following rules;
Rule 1: If a TG has more than one start states, then introduce a new
start state connecting the new state to the old start states by the
transitions labeled by Λ and make the old start states the non-start
states. b
b b b
q0 q1 ^ q0 q1
aa s
aa
a a a a
q
^ q q3
q2 3 2
bb bb
Kleene’s Theorem Proof (part 2)
Rule 2: If a TG has more than one final states, then introduce a new
final state, connecting the old final states to the new final state by
the transitions labeled by Λ.
b b b
b
^ q0 q1 q0
^ q1
^
s
aa aa f
s
a a a
^ q2 q3 ^ a q3 ^
q2
bb bb
Kleene’s Theorem Proof (part 2)
Rule 3: If a state has two (more than one) incoming transition
edges, then replace all these transition edges with a single transition
edge labeled by the sum (+)
c c+d
a
a+b
q0 q1 q0 q1
b
d
Kleene’s Theorem Proof (part 2)
Rule 4 (state elimination): If three states in a TG, are connected in
sequence then eliminate the middle state and connect the first state
with the third by a single transition.
r
a b ar* b
q0 q1 q2
q0 q2
TG to RE
• We have TG:
Example b a
a
s ( (^ a* b). b*.a). a*.^
b a f
q0 q1 q2
b
a a
^ b a
s q0 q1 q2 ^ f
b a
s
^ a* b a ^
q1 q2 f
a
s
(^ a* b). b*.a ^
q2 f
Mealy Machine
• Mealy Machine is Finite Automata (FA)
• A Mealy Machine is an FSM whose output depends on the
present state as well as the present input.
FA
FA without FA with
O/P O/P
: Transition/movement: Q × ∑ → Q
0/c ,
0/b
1/b
Next State
Present state Input= 0 Input= 1
1/c
state output state output q3
q1
q0
q0 q1 a q2 a 0/c
q2
q1 q1 b q3 c
q2 q3 c q2 a
q3 q3 c q3 b
1/a
Mealy Machine
• Find the output of a string “011011” by given mealy
(Example 2)
machine
0/c ,
0/b
1/b
• We have given
1/c string:
string=
q1
q3 1 1 0 1 1
q0 0 c b c b
0/c
q2 Output= b
a
1/a
Mealy Machine (Example 3)
• Design a Mealy Machine that produce 1’s compliment of any binary input
string.
Suppose we have
1/0 string: string= 0
binary 1’s
compliment 1 1
1 0 q0
0 1 1
0 1 q0 q0 q0 q0
0/1
1 0 0
Moore
Machine
• Moore Machine is Finite Automata (FA) with output
: Transition/movement: Q × ∑ → Q
Next State 0 0
Present state output
Input 0 Input 1
1
q1 / c q3 / b
q0 q1 q2 a
q0 / a
q1 q1 q3 c 1
1
q2 q2 q3 a
q3 q3 q2 b q2 / a
0
Moore Machine (Example 2)
• Find the output of a string “101100” by given Moore machine
• We have given
0 string:
0 string= 0 1 1 0 0
1 1 a b a a a
q1 / c q3 / b
Output= a
q0 / a
1 a
1
q2 / a
Note
• In Moore machine output of string will always be:
0 n+1
• In Mealy machine out put of string will always be: n
• Where n in length of string
Moore Machine (Example 3)
• Design a Moore Machine that produce 1’s compliment of any binary input
string.
0
binary 1’s
compliment
0 q1 / 1
1 0
0 1 q0 / 0
1
0
1
Suppose we have string: 1
q2 / 0
string= 1 1
0
1 1 0
q0 q2 q2 q1
0 0 1
Mealy to Moore
Conversion
• Convert the given Mealy Machine into Moore
Machine.
0/c , q1/b
0/b
1/b q1/a
1/c
q3
q1
q0 q 3 /c
q0
0/c
q2
q 2 /a
q 3 /b
Mealy Machine
1/a
Moore Machine
Mealy to Moore Conversion using
transition
• table
Construct Moore Machine transaction table from given Mealy transition
table
q1 q1 q30
b
q0 q0 a q2 a
q2 q30
q2 a
q1 q1 b q3 c
q2 q3 c q2 a q30 q30 q31
c
q3 q3 c q3 b b
q31 q30 q31
Moore Transition Table
Moore Machine to Mealy Machine
Conversion
• Convert given Moore Machine into Mealy
Machine
0 0 0/b
0/c
1 1/b
q1 / c q3 / b
q1 q3
q0 / a q0
1 1/b
1 1/a
q2 / a q2
Moore Machine
0 0/a Mealy Machine
Moore Machine to Mealy Machine
Conversion
• Design a Mealy machine from given Moore
machine.
0 0/
q1 /1 0 q1
q0 / 0 1 q0 1/0
1 1/1
0 0/0
q2 / 0 q2
Moore Machine
Mealy Machine
Moore to Mealy Transition Table
conversion
Construct a Transition table of given Moore machine and convert it
into transition table of Mealy machine.
Next State
Present state output
Input 0 Input 1
0 q0 q0 q1 0
q1 /1 q1 q2 q0 1
q2 q0 q1 0
q0 / 0 1
1
0 Next State
q2 / 0 Input= 0 Input= 1
Present state
state output state output
q0 q0 0 q1 1
q1 q2 0 q0 0
Pumping Lemma
• Pumping Lemma is used to find out whether the language is regular or
not.
• The problems that solve in finite steps and their answer is Yes or
No, such problems are called decidable problems.
Decidability
Decide whether given FA/RE accept any string or not?