Final Revision FLAT
Final Revision FLAT
Q2) Construct a DFA to accept a string containing two consecutive zeroes followed by
two consecutive ones
Q3) Construct a DFA to accept a string containing even number of zeroes and any
number of ones
Construct a DFA to accept all strings which do not contain three consecutive zeroes
Q) Construct a DFA to accept all strings which satisfies #(x) mod 5=2
Q) Construct a DFA to accept all strings (0+1)* with an equal number of 0's & 1's
such that each prefix has at most one more zero than ones and at most one more
one than zeroes
1. The set of binary strings consisting of an equal number of a’s and b’s.
2. The set of strings over ‘(‘ and ‘)’ that have “balanced” parentheses.
Regular
Expression
Expression
NFA with Є-moves
Deterministic
Finite Automata
NFA without
Є -moves
Let r be a re. Then there exists and NFA with transition that accepts L(r).
Proof:
We show by induction on the number of operators in the re r that there is an NFA M with
transition, having one final state and no transitions out of this Final state, such that
L(M)=L(r )
Basis zero operator : the expression r must be , Φ or a for some a in ∑. The NFA’s are given
below which satisfy this conditions
a) r = b) r=Φ c) r = a
Induction
Assume that theorem is true for regular expressions with fewer that I operators, i>=1. Let r
have I operators. There are three cases depending on the form of r.
Case 1 :
r= r1 + r2
Here both r1 and r2 must have fewer than I operators. Thus there are NFA’s
M1=(Q1,∑1 , 1 ,q1,{f1}) and M2=(Q2,∑2, 2 ,q2,{f2}) with L(M1 )=L(r1) and (M2 )=L(r2)
Since we may rename states of an NFA at which we assume Q1 and Q2 are disjoint.
Case 3
Construction of M is
Regular grammars are another way to describe regular languages a grammar is made of of
terminals, variables, and production rule defined by
G=(V,T,S,P) where,
where A,B,C∈V,x∈T∗
the number of states in the smallest deterministic finite automaton (DFA) recognizing
L is equal to the number of equivalence classes in RL. In particular, this implies that
• Union
• Intersection
• concatenation
• Kleene closure
• Complement
Let see one by one with an example
Union
If L1 and If L2 are two regular languages, their union L1 U L2 will also be regular.
Example
L1 = {an | n > O} and L2 = {bn | n > O}
Intersection
If L1 and If L2 are two regular languages, their intersection L1 ∩ L2 will also be
regular.
Example
L1= {am bn | n > 0 and m > O} and
L2= {am bn U bn am | n > 0 and m > O}
L3 = L1 ∩ L2 = {am bn | n > 0 and m > O} are also regular.
Concatenation
If L1 and If L2 are two regular languages, their concatenation L1.L2 will also be
regular.
Example
L1 = {an | n > 0} and L2 = {bn | n > O}
L3 = L1.L2 = {am . bn | m > 0 and n > O} is also regular.
Kleene Closure
If L1 is a regular language, its Kleene closure L1* will also be regular.
Example
L1 = (a U b )
L1* = (a U b)*
Complement
If L(G) is a regular language, its complement L'(G) will also be regular. Complement
of a language can be found by subtracting strings which are in L(G) from all possible
strings.
Example
L(G) = {an | n > 3} L'(G) = {an | n <= 3}
Note − Two regular expressions are equivalent, if languages generated by them are
the same. For example, (a+b*)* and (a+b)* generate the same language. Every string
which is generated by (a+b*)* is also generated by (a+b)* and vice versa.
Union : If L1 and L2 are two context free languages, their union L1 ∪ L2 will
also be context free. For example,
L1 = { anbncm | m >= 0 and n >= 0 } and L2 = { anbmcm | n >= 0 and m >= 0 }
L3 = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also context free.
L1 says number of a’s should be equal to number of b’s and L2 says number
of b’s should be equal to number of c’s. Their union says either of two
conditions to be true. So it is also context free language.
So CFL are closed under Union.
Kleene Closure : If L1 is context free, its Kleene closure L1* will also be
context free. For example,
L1 = { anbn | n >= 0 }
L1* = { anbn | n >= 0 }* is also context free.
Note :So CFL are closed under Kleen Closure.
.
Context Sensitive Grammar-Properties
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then
any no. of d’s. L2 says any no. of a’s followed by n no. of b’s followed by n no.
of c’s followed by n no. of d’s. Their intersection says n no. of a’s followed by
n no. of b’s followed by n no. of c’s followed by n no. of d’s. So it can be decided
by turing machine, hence recursive.
The Expressive Power of any machine can be determined from the class or
set of Languages accepted by that particular type of Machine. Here is the
increasing sequence of expressive power of machines :
Example 1:
Let L= { anbncn | n>=0 }. By using pumping lemma show that L is not context free
language.
Solution:
Step 1: Let L is a context free language, and we will get contradiction. Let n be a natural
number obtained by pumping lemma.
Step 2: Let w = anbncn where| w |>= 3n. By using pumping lemma we can write w = uvxyz
with |vy| >= 1 and |vxy| <= n.
Step 3: In step 3, we consider two cases.
• Case 1: Here, v and y contain only one type of alphabet symbol, i.e. both
contains only a’s.
Then uv2xy2z may contain equal number of three alphabet symbols but not in correct
order. The resulting string is of the form
aaaa.aaaaaaaaa..aabb…bbbcc…..bcccbc
Here not all b’s follows a’s and not all c’s follows b’s. Hence it cannot be member of context
free language L and a contradiction occurs. Both the cases result in contradictions so L is
not context free language.
Problem
Find out whether the language L = {xnynzn | n ≥ 1} is context free or not.
Solution
Let L is context free. Then, L must satisfy pumping lemma.
At first, choose a number n of the pumping lemma. Then, take z as 0n1n2n.
Break z into uvwxy, where
|vwx| ≤ n and vx ≠ ε.
Hence vwx cannot involve both 0s and 2s, since the last 0 and the first 2 are at least
(n+1) positions apart. There are two cases −
Case 1 − vwx has no 2s. Then vx has only 0s and 1s. Then uwy, which would have
to be in L, has n 2s, but fewer than n 0s or 1s.
Case 2 − vwx has no 0s.
Here contradiction occurs.
Hence, L is not a context-free language.
Example 2:
Let L= { anbnan | n> 0 }. By using pumping lemma show that L is not context free language.
Solution:
Step 1: Let L is a context free language and we will get contradiction. Let n be a natural
number obtained by pumping lemma.
Step 2: Let w = anbnan where| w |>= n. By using pumping lemma we can write w = uvxyz
with |vy| >= 1 and |vxy| <= n.
Step 3: In step 3 we consider two cases:
Case 1: When both v and y contains equal number of a’s and b’s.
Let, i = 2
Then uv2xy2z = an+k b n+k a n or a n b n+k an+k which is not in L.
Case 2: Allwords in anbnan have one occurrence of substring ab or ba no matter what n
is.
Let, i = 2
Then uv2xy2z will have more than one substring ab or ba, so it cannot be in the form anbnan.
Hence, uv2xy2z ? L.
There is contradiction in both the cases, so L is not context free language.
These languages are exactly all languages that can be decided by a finite state
automaton. Additionally, this family of formal languages can be obtained by regular
expressions. Regular languages are commonly used to define search patterns and the
lexical structure of programming languages.
2 types of regular grammars
Right linear – production is of the form A →a B/a
Left linear - production is of the form A → Ba / a
Recognizer for regular language is finite automata