FLAT Notes
FLAT Notes
FLAT Notes
Automata:
The term "Automata" is derived from the Greek word "αὐτό ματα" which
means "self-acting". An automaton (Automata in plural) is an abstract self-
propelled computing device which follows a predetermined sequence of
operations automatically.
An automaton with a finite number of states is called a Finite
Automaton(FA) or Finite State Machine (FSM).
Formal definition of a Finite Automaton:
An automaton can be represented by a 5-tuple (Q, ∑, δ, q0, F), where −
Q is a finite set of states.
∑ is a finite set of symbols, called the alphabet of the automaton.
δ is the transition function.
q0 is the initial state from where any input is processed (q0 ∈ Q).
F is a set of final state/states of Q (F ⊆ Q).
Q = {a, b, c},
∑ = {0, 1},
q0 = {a},
F = {c}, and
Transition function δ as shown by the following table −
Present State Next State for Input 0 Next State for Input 1
a a b
b c a
c b c
Its graphical representation would be as follows −
a a, b b
b c a, c
c b, c c
Its graphical representation would be as follows −
DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA
Acceptance of NFA/DFA:
Acceptability by DFA and NDFA:
A string is accepted by a DFA/NDFA iff the DFA/NDFA starting at the initial
state ends in an accepting state (any of the final states) after reading the
string wholly.
A string S is accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff δ*(q0, S) ∈
F The language L accepted by DFA/NDFA is {S | S ∈ ∑* and δ*(q0, S) ∈
F}
A string S′ is not accepted by a DFA/NDFA (Q, ∑, δ, q0, F), iff
δ*(q0, S′) ∉ F
The language L′ not accepted by DFA/NDFA (Complement of accepted
language L) is {S | S ∈ ∑* and δ*(q0, S) ∉ F}
Example
Let us consider the DFA shown in Figure 1.3. From the DFA, the acceptable
strings can be derived.
Strings accepted by the above DFA: {0, 00, 11, 010, 101,..................}
Strings not accepted by the above DFA: {1, 011, 111,.............}
Convert the following NFA to DFA.
q δ(q,0) δ(q,1)
a {a,b,c,d,e} {d,e}
b {c} {e}
c ∅ {b}
d {e} ∅
e ∅ ∅
we find its equivalent DFA. The state table of the DFA is shown in below.
q δ(q,0) δ(q,1)
[d,e] [e] ∅
[e] ∅ ∅
[c, e] ∅ [b]
Mealy Machine
Moore machine
Mealy Machine
A Mealy Machine is an FSM whose output depends on the present state as
well as the present input.
It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
O is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
X is the output transition function where X: Q × ∑ → O
q0 is the initial state from where any input is processed (q0 ∈ Q).
The state table of a Mealy Machine is shown below −
Present state Next state
input = 0 input = 1
State Output State Output
→a b x1 c x1
b b x2 d x3
c d x3 c x1
d d x3 d x2
The state diagram of the above Mealy Machine is −
Moore Machine
Moore machine is an FSM whose outputs depend on only the present state.
A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −
Q is a finite set of states.
∑ is a finite set of symbols called the input alphabet.
O is a finite set of symbols called the output alphabet.
δ is the input transition function where δ: Q × ∑ → Q
X is the output transition function where X: Q → O
q0 is the initial state from where any input is processed (q0 ∈ Q).
The state table of a Moore Machine is shown below −
Present state Next State Output
Input = 0 Input = 1
→a b c x2
b b d x1
c c d x2
d d d x3
The state diagram of the above Moore Machine is −
Explain the difference between Moore and Mealy Machine.
Output depends both upon the Output depends only upon the
present state and the present present state.
input
The value of the output function The value of the output function
is a function of the transitions is a function of the current state
and the changes, when the input and the changes at the clock
logic on the present state is edges, whenever state changes
done. occur.
a=0 a=1
→a d b 1
b a d 0
c c c 0
d b a 1
Ans:
Step 1 & 2 −
Present State Next State
a=0 a=1
→a d b
b a d
c c c
d b a
Step 3 −
Present State Next State
a=0 a=1
=> a d 1 b 0
b a 1 d 1
c c 0 c 0
d b 0 a 1
a=0 a=1
→a d 0 b 1
b a 1 d 0
c c 1 c 0
d b 0 a 1
Ans:
states ‘a’ and ‘d’ give only 1 and 0 outputs respectively, so we retain
states ‘a’ and ‘d’. But states ‘b’ and ‘c’ produce different outputs (1 and
0). So, we divide b into b0, b1 and c into c0, c1.
Present State Next State Output
a=0 a=1
→a d b1 1
b0 a d 0
b1 a d 1
c0 c1 C0 0
c1 c1 C0 1
d b0 a 0
Construction of minimized DFA for the following DFA.
Ans:
Step 1. P0 will have two sets of states. One set will contain q1, q2, q4
which are final states of DFA and another set will contain remaining
states. So P0 = { { q1, q2, q4 }, { q0, q3, q5 } }.
Step 2. To calculate P1, we will check whether sets of partition P0 can be
partitioned or not:
For set { q1, q2, q4 } :
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2
are not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So
q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not
distinguishable, So q2 and q4 are not distinguishable. So, { q1, q2, q4 }
set will not be partitioned in P1.
For set { q0, q3, q5 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0
δ ( q0, 1) = q1 and δ ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which
are in same set in partition P0. Similarly, Moves of q0 and q3 on input
symbol 1 are q3 and q0 which are in same set in partition P0. So, q0 and
q3 are not distinguishable.
δ ( q0, 0 ) = q3 and δ ( q5, 0 ) = q5 and δ ( q0, 1 ) = q1 and δ ( q5, 1 ) = q5
Moves of q0 and q5 on input symbol 0 are q3 and q5 respectively which
are in different set in partition P0. So, q0 and q5 are distinguishable. So,
set { q0, q3, q5 } will be partitioned into { q0, q3 } and { q5 }. So,
P1 = { { q1, q2, q4 }, { q0, q3}, { q5 } }
To calculate P2, we will check whether sets of partition P1 can be
partitioned or not:
For set { q1, q2, q4 } :
δ ( q1, 0 ) = δ ( q2, 0 ) = q2 and δ ( q1, 1 ) = δ ( q2, 1 ) = q5, So q1 and q2
are not distinguishable.
Similarly, δ ( q1, 0 ) = δ ( q4, 0 ) = q2 and δ ( q1, 1 ) = δ ( q4, 1 ) = q5, So
q1 and q4 are not distinguishable.
Since, q1 and q2 are not distinguishable and q1 and q4 are also not
distinguishable, So q2 and q4 are not distinguishable. So, { q1, q2, q4 }
set will not be partitioned in P2.
For set { q0, q3 } :
δ ( q0, 0 ) = q3 and δ ( q3, 0 ) = q0
δ ( q0, 1 ) = q1 and δ ( q3, 1 ) = q4
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are
in same set in partition P1. Similarly, Moves of q0 and q3 on input symbol 1
are q3 and q0 which are in same set in partition P1. So, q0 and q3 are not
distinguishable.
For set { q5 }:
Since we have only one state in this set, it can’t be further partitioned. So,
P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } }
Since, P1=P2. So, this is the final partition. Partition P2 means that q1, q2
and q4 states are merged into one. Similarly, q0 and q3 are merged into one.
Minimized DFA corresponding to DFA is:
*********
UNIT- II
Now we will remove the ε transitions. After we remove the ε transitions from
the NDFA, we get the following −
Regular Set and its properties:
Regular Set: Any set that represents the value of the Regular Expression
is called a Regular Set.
Properties of Regular Sets:
Property 1. The union of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(aa)* and RE2 = (aa)*
So, L1 = {a, aaa, aaaaa,.......} (Strings of odd length excluding Null)
and L2 ={ ε, aa, aaaa, aaaaaa,........} (Strings of even length including Null)
L1 𝖴 L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,........}
(Strings of all possible lengths including Null)
RE (L1 𝖴 L2) = a* (which is a regular expression itself)
Hence, proved.
Property 2. The intersection of two regular set is regular.
Proof −
Let us take two regular expressions
RE1 = a(a*) and RE2 = (aa)*
So, L1 = { a,aa, aaa, aaaa,........} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,........} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.
Property 3. The complement of a regular set is regular.
Proof −
Let us take a regular expression −
RE = (aa)*
So, L = {ε, aa, aaaa, aaaaaa,..........} (Strings of even length including Null)
Complement of L is all the strings that is not in L.
So, L’ = {a, aaa, aaaaa,.......} (Strings of odd length excluding Null)
RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.
Property 4. The difference of two regular set is regular.
Proof −
Let us take two regular expressions −
RE1 = a (a*) and RE2 = (aa)*
So, L1 = {a, aa, aaa, aaaa,.......} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,........} (Strings of even length including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa,........}
(Strings of all odd lengths excluding Null)
RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.
Property 5. The reversal of a regular set is regular.
Proof −
We have to prove LR is also regular if L is a regular set.
Let, L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10
LR = {10, 01, 11, 01}
RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.
Property 6. The closure of a regular set is regular.
Proof −
If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
i.e., RE (L) = a (aa)*
L* = {a, aa, aaa, aaaa , aaaaa,…..............} (Strings of all lengths excluding Null)
RE (L*) = a (a)*
Hence, proved.
Property 7. The concatenation of two regular sets is regular.
Proof −
Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
Here, L1 = {0, 00, 10, 000, 010,..........} (Set of strings ending in 0)
and L2 = {01, 010,011,.......} (Set of strings beginning with 01)
Then, L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,....................}
Set of strings containing 001 as a substring which can be represented by an
RE − (0 + 1)*001(0 + 1)*
Hence, proved.
Statement −
Let P and Q be two regular expressions.
If P does not contain null string, then R = Q + RP has a unique solution that
is R = QP*
Proof −
R = Q + (Q + RP)P [After putting the value R = Q + RP]
= Q + QP + RPP
When we put the value of R recursively again and again, we get the following
equation −
R = Q + QP + QP2 + QP3…..
R = Q (ε + P + P2 + P3 + …. )
R = QP* [As P* represents (ε + P + P2 + P3 + ….) ]
Hence, proved.
Construct of regular expression corresponding to the automata given
below −
*******
UNIT-III
CFG:
A context free grammar G can be formally written as a 4-tuple (N, T, S, P) where
−
N or VN is a set of variables or non-terminal symbols.
T or ∑ is a set of Terminal symbols.
S is a special variable called the Start symbol, S ∈ N
P is Production rules for Terminals and Non-terminals. A production
rule has the form α → β, where α is VN and β are strings on
(VN 𝖴 ∑) *.
Example
Grammar G −
({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})
Here,
S, A, and B are Non-terminal symbols;
a and b are Terminal symbols
S is the Start symbol, S ∈ N
Productions, P : S → AB, A → a, B → b
Derivation:
Let’s find out the derivation tree for the string "a+a*a". It has two leftmost
derivations.
Derivation 1 − X → X+X → a +X → a+ X*X → a+a*X → a+a*a
Parse tree 1 −
Since there are two parse trees for a single string "a+a*a", the grammar G is
ambiguous.
Closure properties of CFL:
Union
Concatenation
Kleene Star operation
Union:
Let L1 and L2 be two context free languages. Then L1 𝖴 L2 is also context
free. Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have
P: S1 → aAb|ab
Let L2 = { cmdm , m ≥ 0}.Corresponding grammar G2 will have
P: S2 → cBb| ε
Union of L1 and L2, L = L1 𝖴 L2 = { anbn } 𝖴 { cmdm }
The corresponding grammar G will have the additional production S → S1 |
S2
Concatenation
If L1 and L2 are context free languages, then L1L2 is also context free.
Example
Union of the languages L1 and L2, L = L1L2 = { anbncmdm }
The corresponding grammar G will have the additional production S → S1
S2
Kleene Star
If L is a context free language, then L* is also context free.
Example
Let L = {anbn , n ≥ 0}. Corresponding grammar G will have P: S → aAb| ε
Kleene Star L1 = { anbn }*
The corresponding grammar G1 will have additional productions S1 → SS1 |
ε
Context-free languages are not closed under −
Intersection − If L1 and L2 are context free languages, then L1 ∩ L2 is
not necessarily context free.
Intersection with Regular Language − If L1 is a regular language and
L2 is a context free language, then L1 ∩ L2 is a context free language.
Complement − If L1 is a context free language, then L1’ may not be
context free.
Simplification of CFGs:
In a CFG, it may happen that all the production rules and symbols are not
needed for the derivation of strings. Besides, there may be some null
productions and unit productions. Elimination of these productions and
symbols is called simplification of CFGs. Simplification essentially
comprises of the following steps −
Reduction of CFG
Removal of Unit Productions
Removal of Null Productions
Reduction of CFG
CFGs are reduced in two phases −
Phase 1 − Derivation of an equivalent grammar, G’, from the CFG, G, such
that each variable derives some terminal string.
Derivation Procedure −
Step 1 − Include all symbols, W1, that derive some terminal and initialize
i=1. Step 2 − Include all symbols, Wi+1, that derive Wi.
Step 3 − Increment i and repeat Step 2, until Wi+1 = Wi.
Step 4 − Include all production rules that have Wi in it.
Phase 2 − Derivation of an equivalent grammar, G”, from the CFG, G’, such
that each symbol appears in a sentential form.
Derivation Procedure −
Step 1 − Include the start symbol in Y1 and initialize i = 1.
Step 2 − Include all symbols, Yi+1, that can be derived from Yi and include all
production rules that have been applied.
Step 3 − Increment i and repeat Step 2, until Yi+1 = Yi.
Removal Procedure −
Step 1 − To remove A → B, add production A → x to the grammar rule
whenever B → x occurs in the grammar. [x ∈ Terminal, x can be Null]
Step 2 − Delete A → B from the grammar.
Step 3 − Repeat from step 1 until all unit productions are removed.
Removal of Null Productions
In a CFG, a non-terminal symbol ‘A’ is a nullable variable if there is a
production A → ε or there is a derivation that starts at A and finally ends up
with
ε: A →.............→ ε
Removal Procedure
Step 1 − Find out nullable non-terminal variables which derive ε.
Step 2 − For each production A → a, construct all productions A →
x where x is obtained from ‘a’ by removing one or multiple non-terminals
from Step 1.
Step 3 − Combine the original productions with the result of step 2 and
remove ε - productions.
(1)
Since S appears in R.H.S, we add a new state S0 and S0→S is added to
the production set and it becomes −
S0→S, S→ ASA | aB, A → B | S, B → b | ∈
(2)
Now we will remove the null productions −
B → ∈ and A → ∈
After removing B → ε, the production set becomes −
S0→S, S→ ASA | aB | a, A → B | S | ∈, B → b
After removing A → ∈, the production set becomes
−
S0→S, S→ ASA | aB | a | AS | SA | S, A → B | S, B → b
(3)
Now we will remove the unit productions.
After removing S → S, the production set becomes −
S0→S, S→ ASA | aB | a | AS | SA, A → B | S, B → b
After removing S0→ S, the production set becomes −
S0→ ASA | aB | a | AS | SA, S→ ASA | aB | a | AS | SA
A → B | S, B → b
After removing A→ B, the production set becomes −
S0 → ASA | aB | a | AS | SA, S→ ASA | aB | a | AS | SA
A → S | b, B → b
After removing A→ S, the production set becomes −
S0 → ASA | aB | a | AS | SA, S→ ASA | aB | a | AS |
SA A → b |ASA | aB | a | AS | SA, B → b
(4)
Now we will find out more than two variables in the R.H.S
Here, S0→ ASA, S → ASA, A→ ASA violates two Non-terminals in R.H.S.
Hence we will apply step 4 and step 5 to get the following final production
set which is in CNF −
S0→ AX | aB | a | AS | SA
S→ AX | aB | a | AS | SA
A → b |AX | aB | a | AS | SA
B → b, X → SA
(5)
We have to change the productions S0→ aB, S→ aB, A→ aB
And the final production set becomes −
S0→ AX | YB | a | AS | SA
S→ AX | YB | a | AS | SA
A → b A → b |AX | YB | a | AS | SA
B→b
X → SA
Y→a
Griebach Normal Form:
**********
UNIT-IV
Instantaneous Description:
Initially we put a special symbol ‘$’ into the empty stack. At state q2, the w
is being read. In state q3, each 0 or 1 is popped when it matches the input. If
any other input is given, the PDA will go to a dead state. When we reach that
special symbol ‘$’, we go to the accepting state q4.
Procedure to convert CFG to PDA:
The NPDA:
Turing Machine:
Here,
x2x1x3 = ‘aaabbaaa’ and y2y1y3 = ‘aaabbaaa’
We can see that
x2x1x3 = y2y1y3
Hence, the solution is i = 2, j = 1, and k = 3.
Type - 3 Grammar
Type-3 grammars generate regular languages. Type-3 grammars must
have a single non-terminal on the left-hand side and a right-hand side
consisting of a single terminal or single terminal followed by a single non-
terminal.
The productions must be in the form X → a or X → aY
where X, Y ∈ N (Non terminal)
and a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule.
Example
X→ε
X → a | aY
Y→b
The class P consists of all those decision problems that can be solved on a
deterministic sequential machine in an amount of time that is polynomial in
the size of the input; the class NP consists of all those decision problems
whose positive solutions can be verified in polynomial time.
********
Unit Wise Question Bank
UNIT I Bloom’s
S.No. Questions COs Taxonomy
Level
What is Automata? Give Formal definition of a CO1 Understanding
1. Finite Automaton.
a)
Define Alphabet ,String and Language. CO1 Understanding
b)
Explain Different types of Automata with an CO1 Understanding
2. Example.
a)
CO1 Understanding
Explain the Difference between NFA and DFA.
b)
Explain Acceptance of NFA/DFA. CO1 Apply
3.
a)
Convert the following NFA to DFA. CO1 Create
b)
a=0 a=1
→a d b 1
b a d 0
c c c 0
d b a 1
b)
What is a Regular Set? Explain its properties. CO2 Understandin
2. g
a)
Write the Identities Related to Regular Expressions. CO2 Understandin
g
b)
State and Prove Arden's Theorem. CO2 Analyze
3.
a)
Construct a regular expression corresponding CO2 Create
to the automata given below −
b)
CO2 Analyze
State and Explain Pumping Lemma
4.
Applications.
a)
Prove that L = {aibi | i ≥ 0} is not regular. CO2 Analyze
b)
CO2 Understandin
List the Closure properties of Regular sets.
5. g
UNIT III Bloom’s
S.No. Questions COs Taxonomy
Level
1. a) What is CFG? CO3 Understanding
What is a Derivation? Explain the two CO3 Understanding
b) sentential forms.
2. Explain about Left and Right Recursive CO3 Understanding
a) Grammars.
What is Ambiguous Grammar? CO3 Understanding
b)
3. Check whether the grammar G with CO3 Analyze
a) production rules −
X → X+X | X*X |X| a is ambiguous or not.
Explain about closure properties of CFL. CO3 Analyze
b)
4. Explain about the simplification of CFGs. CO3 Analyze
a)
emove null production from the following − CO3 Analyze
S → ASA | aB | b, A → B, B → b | ∈
b)
7.a) State Pumping Lemma for CFL and its CO3 Understanding
Applications.
CO4 Understanding
Explain the procedure to convert PDA to CFG.
b)
Convert a PDA into an equivalent CFG PDA={ CO4 Analyze
5. an bn/n=0}.
a)
Explain about the NPDA. CO4 Understanding
b)
UNIT V Bloom’s
S.No. Questions COs Taxonomy
Level
1. a) Explain about the Turing Machine CO5 Understanding
Design a TM to recognize all strings consisting of an odd CO5 Create
b) number of
α’s.
3. CO5 Understanding
Explain about Linear bounded automaton.
a)
b)
CO5 Understanding
5. Define P and NP Problem?
a)
Explain about the Universal Turing Machine. CO5 Understanding
b)