0% found this document useful (0 votes)
5 views

ToA lec 5

Uploaded by

shariqqayyum612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ToA lec 5

Uploaded by

shariqqayyum612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 48

DFA (Deterministic Finite

 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:

all the input string is


scanned and the last state
is accepting

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}.

• The RE of above statement will be: RE= b (a + 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}.

• The RE of above statement will be: RE= ab (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 can be generated from transition diagram.


• For example diagram of FA

• Transition table shows that which specific transition take place from
specific state.

• We write all states in column and transitions in a row.


Example

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.

• Designing and understanding of NFA is easy and simple while designing


and understanding of DFA difficult.
Transition Graph (TG)
 It is a method to define a
language.
• Properties
I. Number of
of TG are should
states given below:
be finite.
II. There must be at least one initial state and one final
state.
III. • initial and final states can be more than one
No dead transitions
IV. Multiple end state. are allowed.
V. Can read more than one character at a
time.
VI. It allows null transactions.
TG
Examples
• Draw transition Graph (TG) of RE= 1*(1+ 1

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

 Kleene’s Theorem has three parts:

1) If language can be accepted by FA (Finite Automata) then it can


also be accepted by TG (Transition Graph).

2) If language can be accepted by TG (Transition Graph) then it can


also be expressed by RE (Regular Expression).

3) If language can be expressed by RE (Regular Expression) then it can


be accepted by FA (Finite Automata)
Kleene’s Theorem Proof
(part 1)can be accepted by FA (Finite Automata) then it can
• If language
also be accepted by TG (Transition Graph).
• Lets S= aba

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

TG NFA DFA Mealy Moore


Machine Machine
Tuples of Mealy
Machine
 A Mealy Machine has 6-tuple 6-tuple (Q,,, q0, O, λ ), where

1. Q is a finite set called the states. (e.g. q0 , q1, q2,....)

  is a finite set called the alphabet. (input alphabet e.g.  =


{a,b})

  : Transition/movement: Q × ∑ → Q

4. q0 is the start state (initial state)

5. O is a finite set of symbols called the output alphabet

6. λ is the output transition function where λ: Q × ∑ → O


How to Design Mealy Machine (Example 1)
• Design a Mealy Machine from given Transition Table

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

• A Moore Machine is an FSM whose output depends only on


the present state.
Tuples of Moore
Machine
 A Moore Machine has 6-tuple (Q,,, q0, O, λ ), where

1. Q is a finite set called the states. (e.g. q0 , q1, q2,....)

  is a finite set called the alphabet. (input alphabet e.g.  =


{a,b})

  : Transition/movement: Q × ∑ → Q

4. q0 is the start state (initial state)

5. O is a finite set of symbols called the output alphabet

6. λ is the output transition function where λ: Q → O


How to Design Moore Machine (Example
1)
• Design a Moore Machine from given Transition Table

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

Mealy Transition Table


Next State
Next State Present state output
Input 0 Input 1
Present state Input= 0 Input= 1
state output state output q0 q0, a q2, a a
q1 q1', b q30, c
b
q0 q0 a q2 a q2 q2, a a
q30,c
q1 q1 b q3 c
q30 q30,c q31,b
c
q2 q3 c q2 a
q3 q3 c q3 b q31 q30,c q31,b
b
Moore Transition Table
Mealy to Moore Conversion using
transition
• table
Construct Moore Machine transaction table from given Mealy transition
table

Mealy Transition Table

Next State Next State


Present state output
Present state Input= 0 Input= 1 Input 0 Input 1
state output state output
q0 q0 q2,
a

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.

• There are two types of language finite and infinite.

• Finite language in always regular.

• Infinite language may be a regular or may be non-regular


• Pumping Lemma is one of the method to find language is regular or not.

• Pumping Lemma performs negative test.


• if we apply pumping lemma test on language and language pass that test, than
there will be no surety that language is regular or non-regular.
• If language fail pumping lemma test, then it is sure that language is non-regular
Steps for pumping
Lemma Test
1. Suppose language is regular.

2. If language is regular then we can make its Finite


Automata.

3. Suppose finite automata has 8 states.

4. Take word of length greater than states

5. Divide word into 3 parts i.e; x,y,z


• Make sure that length of X + Y <= N

6. X and Z can be Null but Y can not be Null. Y>=1

7. Will decide language is regular or not


pumping Lemma for Regular
Language (Example)
1) Suppose language is regular.  Prove that language is regular for all
2) If language is regular then the strings ending with “bab” defined
we can make its Finite over
Automata. ∑ = {a, b}.
3) Suppose finite automata has • We suppose language is regular, than we can
8 states.
make its FA. (step 1 & 2)
4) Take word of length greater
than states • N=8 (step 3)
5) Divide word into 3 parts i.e; • Word= aabbababab (step 4)
x,y,z • Length of x= 4, y=3, z=3 (step 5)
1) Make sure that length of • X= aabb
• Increase power; of Yy= aba;
(step 7) z=
X + Y <= N
• X YY Z bab
6) X and Z can be Null but Y can String belong to
not be Null. Y>=1 • aabbabaababab Language (L), Hence L is
RL
7) Increase the power of Y (pump
Pumping Lemma for Non-Regular
(Example)
Language
1) Suppose language is regular.  Prove that language is non-regular
2) If language is regular then for L is an bn over ∑ = {a, b}.
we can make its Finite  Our language can be L= {ab,
Automata. aabb, aaabbb, aaaabbbb,…….}
3) Suppose finite automata has • We suppose language is regular, than
8 states. we can
4) Take word of length greater make its FA. (step 1 & 2)
than states • N=8 (step 3)
5) Divide word into 3 parts i.e; • Word= aaaaabbbbb (step 4)
x,y,z • Length of x= 1, y=4, z=5 (step 5)
1) Make sure that length of • Increase power of Y (step 7)
X + Y <= N
• X=
• X YYa;Zy= aaaa; z= bbbbb
6) X and Z can be Null but Y can String does not belong to
not be Null. Y>=1 •a Language (L), Hence L is

7) Increase the power of Y (pump aaaaaaaabbbbb non RL


Decidabilit
y
• Decidability is making decision about following:

• Is given FA/RE accept any string or not?


• Is given FA/RE represents finite or infinite language?
• Whether two languages are equivalent 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?

 To find out that given FA/RE accept any string or not


 We will perform following steps on given FA, If we have given RE then first
we construct FA from RE then we perform following steps.

• Mark the initial state.


• Mark the states that are connected with initial states.
• Remove the edges that connect initial state with other states.
• Remove the edges of next marked state and if next marked state
edges connected with another state then also marked that state.
• Repeat the above process until final state is marked
• If we are unable to reach to final state, it means our FA does not accept any
string
• If we reach to final state, it means our FA accept any string

You might also like