Theory of Computation: Computer Science
Theory of Computation: Computer Science
COMPUTATION
For
COMPUTER SCIENCE
THEORY OF COMPUTATION
Syllabus
Regular expressions and finite automata. Context-free grammars and push-down
automata. Regular and contex-free languages, pumping lemma. Turing machines and
undecidability.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
CONTENTS
Topics Page No
1. FINITE AUTOMATA AND REGULAR EXPRESSION
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
1 FINITE AUTOMATA AND REGULAR EXPRESSION
1.1 ALPHABETS, STRINGS & LANGUAGES It is not the case that a string over some
alphabet should contain all the symbols
The notion of natural languages like English, from the alphabet. For example, the string cc
Hindi, etc. is familiar to us. over the alphabet { a, b, c } does not contain
Informally, language can be defined as a the symbols a and b. Hence, it is true that a
system suitable for expression of certain string over an alphabet is also a string over
ideas, facts, or concepts, which includes a set any superset of that alphabet.
of symbols and rules to manipulate these.
The languages we consider for our Length of A String:
discussion is an abstraction of natural The number of symbols in a string w is
languages. That is, our focus here is on called its length, denoted by |w|.
formal languages that need precise and
formal definitions. Programming languages Example:
belong to this category. |011|=4, |11|=2, |b|=1
It is convenient to introduce a notation ε for
Symbols: the empty string, which contains no symbols
at all. The length of the empty string ε is
Symbols are indivisible objects or entity zero, i.e., |ε| = 0.
that cannot be defined. (Symbols are the
atoms of the world of languages) Some String Operations
A symbol is any single object such as , a, 0,
1, #, begin, or do. Let x = a1a2a3 ∈ an and y = b1b2b3 ∈bm be
two strings.
Alphabets: Concatenation: The concatenation of x and
y denoted by xy, is the string a1a2a3b1b2b3
An alphabet is a finite, nonempty set of That is, the concatenation of x and y
symbols. The alphabet of a language is denoted by xy is the string that has a copy
normally denoted by. When more than one of x followed by a copy of y without any
alphabets are considered for discussion, intervening space between them.
then subscripts may be used (e.g. 1, 2etc)
or sometimes other symbol like G may also Example
be introduced. Concatenation of the strings 0110 and 11 is
011011 and concatenation of the strings
Strings or Words over Alphabet good and boy is good boy.
A string or word over an alphabet is a finite Note:
sequence of concatenated symbols of. For any string w, wε=εw = w.
It is also obvious that if | x | = n and | y |= m,
Example Then | x + y | = n + m.
0110, 11, 001 are three strings over the Prefix: u is a prefix of v if v =ux for some
binary alphabet {0, 1}. aab,abcb, b, cc string x.
are four strings over the alphabet { a, b, c }. Suffix: u is a suffix of v if v =xu for some
string x.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Substring: u is a substring of v if v =xuy for Example
some strings x and y. If ∑ = { a, b }, then ∑* = {, a, b,aa,ab,ba,
bb,aaa,aab, aba,abb, baa, …}.
Example Please note that if ∑ = Ø, then ∑* that is
Consider the string 011 over the binary Ø*={ε}. It may look odd that one can proceed
alphabet. All the prefixes, suffixes and from the empty set to a non-empty set by
substrings of this string are listed below.
iterated concatenation. But there is a reason
Prefixes: , 0, 01, 011.
for this and we accept this convention. The
Suffixes: , 1, 11, 011.
Substrings: , 0, 1, 01, 11, 011. set of all nonempty strings over an alphabet
Note that x is a prefix (suffix or substring) to ∑ is denoted by ∑+. That is,
x, for any string x and is a prefix (Suffix or
substring) to any string. ∑+ = ∑1∪ ∑2 ∪ --- ∑* ∪ --- = ∪∑k (k is 1 to ∞)
A string x is a proper prefix (suffix) of string
Note that k is infinite. It contains no infinite
y if x is a prefix (suffix) of y and xy.
strings but strings of arbitrary lengths.
In the above example, all prefixes(suffixes)
except 011 are proper prefixes(Suffixes).
Reversal
For any string w = a1a2a3··· anthe reversal of
Powers of Strings
the string is wR = anan-1···a3 a2 a1.
For any string x and integer n ≥ 0, we use xn
For example if the string is x = abb then
to denote the string formed by sequentially
reverse of x = bba.
concatenating n copies of x. We can also give
an inductive definition of xn as follows: xn =
Languages
ε, if n = 0 ; otherwise xn = xxn-1
A language over an alphabet is a set of
Example strings over that alphabet. Therefore, a
If x = 011, then x 3= 011011011, x 1= 011 and language L is any subset of ∑*. That is, any L
x0 = ε ⊆ ∑* is a language.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Union of L with itself n times. This is defined
A stringx ∈ L1 ∪ L2 iff x ∈ L1 or x ∈ L2 formally as follows:
L0 = { ε}
Example Ln = LLn-1
{ 0, 11, 01, 011 } { 1, 01, 110 } = { 0, 1, 11,
01, 011, 110 } Example
Let L = {a,ab}.
Intersection Then according to the definition, we have
A string x ∈ L1 ∩ L2 iff x ∈ L1 and x ∈ L2 L0 = {ε}
Example L1 = L{ε} = L = { a, ab }
{ 0, 11, 01, 011 } { 1, 01, 110 } = { 01 } L2 = LL 1 = {a, ab } {a, ab} = { aa, aab, aba, abab
}
Complement L = LL2 = {a, ab} {aa, aab, aba, abab}
3
Usually, ∑* is the universe that a = { aaa, aaab, aaba, aabab, abaa, abaab,
complement is taken with respect to. Thus ababa,
for a language L, thecomplement is L(bar) = ababab } and so on.
{ x ∈ ∑* | x ∉ L }.
Kleene's Star operation
Example The Kleene star operation on a language L,
Let L = {x | |x| is even}. Then its complement denoted as L*is defined as follows:
is the language { x∈ ∑* | |x| is L*= ( Union in N and n>=0) Ln
odd}. Similarly we can define other usual set = L0∪ L1∪ L2 ∪ ···
operations on languages like relative = { x | x is the concatenation of zero or
complement, symmetric difference, etc. more strings from L }
Thus L* is the set of all strings derivable by
Reversal of A Language any number of concatenations of strings in
The reversal of a language L, denoted as LR, L.
is defined as: LR = { WR | W ∈ L} .
Example It is also useful to define L+=LL*, i.e., all
1. Let L = { 0, 11, 01, 011 }. Then LR = { 0, strings derivable by one or more
11, 10, 110 }. concatenations of strings in L.
2. Let L = { 1n0n| n is an integer }. Then LR That is L+= (Union n in N and n>0) Ln
= {0n1n | n is an integer }. = L1∪ L2∪ L3 ∪ ···
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
as powerful in principle as today's real state in some defined manner
computers, while the simpler ones are less determined by a transition function
powerful. (Some models are considered
even more powerful than any real
computers as they have infinite memory
and are not subject to physical constraints
on memory unlike in real computers).
Studying the simpler machines are still
worth as it is easier to introduce some
formalisms used in theory.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
and hence a restricted model of These concepts are generalized in formal
computation. language leading to formal grammars. The
word 'formal' here refers to the fact that the
Grammar specified rules for the language are
A grammar is a mechanism used for explicitly stated in terms of what strings or
describing languages. This is one of the most symbols can occur. There can be no
simple but yet powerful mechanism. There ambiguity in it.
are other notions to do the same, of course.
In everyday language, like English, we have Formal definitions of a Grammar
a set of symbols (alphabet), a set of words A grammar G is defined as a quadruple.
constructed from these symbols, and a set of G = ( N,∑ , P, S )
rules using which we can group the words N is a non-empty finite set of non-terminals
to construct meaningful sentences. The or variables, ∑ is a non-empty finite set of
grammar for English tells us what are the terminal symbols such that N ∩ ∑ = ∅.
words in it and the rules to construct S ∈ N, is a special non-terminal (or variable)
sentences. It also tells us whether a called the start symbol, and
particular sentence is well-formed (as per P:(N∪∑)+X(N∪∑)* is a finite set of
the grammar) or not. But even if one follows production rules.
the rules of the English grammar it may lead The binary relation defined by the set of
to some sentences which are not meaningful production rules is denoted by →, i.e. α → β
at all, because of impreciseness and if
ambiguities involved in the language. In α,β ∈ P. In other words, P is a finite set of
English grammar we use many other higher production rules of the form α → β, where
level constructs like noun-phrase, verb- α ∈ (N∪∑ )+ , α must contain at least one
phrase, article, noun, predicate, verb etc. non-terminal and β ∈ ( N∪∑ )*
A typical rule can be defined as < sentence
>→< noun-phrase ><predicate> meaning The production rules specify how the
that "a sentence can be constructed using a grammar transforms one string to another.
'noun-phrase' followed by apredicate". Given a string δαγ, we say that the
Some more rules are as follows: production rule α → β is applicable to this
string, since it is possible to use the rule α →
< noun-phrase >→< article >< noun > β to rewrite the α (in δαγ) to β obtaining a
<predicate>→< verb > new string δβγ We say that δαγ derives δβγ
and is denoted as δαγ ⇒ δβγ
with similar kind of interpretation given Successive strings are derived by applying
above. the productions rules of the grammar in any
If we take {a, an, the} to be <article>; cow, arbitrary order. A particular rule can be
bird, boy, Ram, pen to be examples of used if it is applicable, and it can be applied
<noun>; and eats, runs, swims, walks, are as many times as described.
associated with <verb>, then we can We write α ⇒*β if the string β can be
construct the sentence- a cow runs, the boy derived from the string α in zero or more
eats, an pen walks- using the above rules. steps; α ⇒+β if β can be derived from α in
Even though all sentences are well-formed, one or more steps.
the last one is not meaningful. We observe By applying the production rules in
that we start with the higher level construct arbitrary order, any given grammar can
<sentence> and then reduce it to <noun- generate many strings of terminal symbols
phrase>, <article>, <noun>, <verb> starting with the special start symbol, S, of
successively, eventually leading to a group the grammar. The set of all such terminal
of words associated with these constructs.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
strings is called the language generated (or Chomsky Hierarchy
defined) by the grammar. The famous linguistic Noam Chomsky
Formally, for a given grammar G = (N, ∑, P, attempted to formalize the notion of
S) the language generated by G is grammar and languages in the 1950s. This
L(G) w * | S *
w effort, due to Chomsky, resulted in the
definition of the "Chomsky Hierarchy", a
That is W ∈ L(G) if S ⇒ G. If,W ∈ L(G) we
hierarchy of language classes defined by
must have for some n ≥ 0,
gradually increasing the restrictions on the
S = α1 ⇒ α2 ⇒ α3 ⇒···⇒ αn, denoted as a
form of the productions. Chomsky
derivation sequence of w, The strings
numbered the four families of grammars
S = α1, α2, α3 ···, αn = w are denoted as
(and languages) that make up the hierarchy
sentential forms of the derivation
and are defined as below.
Let G = ( N , , P, S ) be a grammar
Example
Consider the grammar G = (N, ∑, P, S) ,
1. G is called a Type-0 or unrestricted, or
where N = {S}, ∑ ={a, b} and P is the set of
semi-there or phrase-structure
the following production rules { S →ab, S →
grammar if
aSb}
Some terminal strings generated by this all productions are of the form α → β ,
where α ∈ (N ∪ ∑ )+and β ∈ (N ∪ ∑ )*
grammar together with their derivation is
given below.
2. G is a Type-1 or context-sensitive
S ⇒ ab
grammar if each production α → β in P
S ⇒ aSb⇒ aabb
satisfies |α|≤|β| such that α ∈ (N ∪ ∑ )+
S ⇒ aSb⇒ aaSbb⇒ aaabbb
α must contain at least one non-terminal
It is easy to prove that the language
and β ∈ (N ∪ ∑ )*. Type-1 grammar, by
generated by this grammar is
specification it is allowed to have the
L(G) aiSbi ,i 1 production S → ∈ (esplin), provided S
By using the first production, it generates does not appear on the right-hand side
the string ab( for i =1 ). of any production.
To generate any other string, it needs to
start with the production S → aSb and then 3. G is a Type-2 or context-free grammar if
the non-terminal S in the RHS can be each production α → β in P, α ∈ N, |α| =
replaced either by ab(in which we get the 1 satisfies |α| i.e. α is a single non
string aabb) or the same production S →aSb terminal and β ∈ (N ∪ ∑)*.
can be used one or more times. Every time it
adds an 'a' to the left and a 'b' 4. G is a Type-3 or regular grammar if each
to the right of S, thus giving the sentential production has one of the
form a iSbi ,i 1 . When the non-terminal is Following forms: N→N∑*, N→∑* or
replaced by ab (which is then only N→∑*N, N→∑* where N is the set of
possibility for generating a terminal string) Non-Terminals and ∑ is the set of
we get a terminal string of the form Terminal symbols.
a iSbi ,i 1 . The language generated by a Type-i
There is no general rule for finding a grammar is called a Type-i language, i =
grammar for a given language. For many 0,1,2,3. A Type-0 language is also called
languages we can devise grammars and unrestricted language. A Type-1 language is
there are many languages for which we also called a context-sensitive language
cannot find any grammar. (CSL). We have already observed that a
Type-2 language is also called a Context-
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Free Language (CFL) and a Type-3 language expressions exactly capture the behaviors of
is also called a regular language. Each class finite automata. In 1959, Dana Scott and
of language in the Chomsky hierarchy is Michael Rabin introduced non-
characterized as the language generated by deterministic automata and showed the
a type of automata. These relationships have surprising theorem that they are equivalent
been summarized in the following table for to deterministic automata. We will study
convenience. these fundamental results. Since those early
years, the study of automata has continued
Grammars Languages Automata to grow, showing that they are indeed a
Type-0 , phrase-struct fundamental idea in computing.
Recursively
, semi- Turing
enumerable
true,Unrestricted
language
Machine States, Transitions And Finite-State
grammars Transition System
Linear-
Type-1 , Context Context-sensitive
bounded
Senstive Grammar language
automata Let us first give some intuitive idea about a
Type-2, Context-Free Context-free Pushdown state of a system and state transitions
Grammars language Automata before describing finite automata.
Type-3, Regular, right-
Finite
linear,left-linear Regular Language Informally, a state of a system is an
Automata
grammar
instantaneous description of that system
which gives all relevant information
Example
necessary to determine how the system can
Find a grammar for the language
evolve from that point on. Transitions are
L = {anbn+1|n ≥ 1}. It is possible to find a
changes of states that can occur
grammar for L by modifying the previous
spontaneously or in response to inputs to
grammar since we need to generate an extra
the states. Though transitions usually take
b at the end of the string anbn , n ≥ 1. We can
time, we assume that state transitions are
do this by adding a production S → Bb where
instantaneous (which is an abstraction).
the non-terminal B generates a iSbi ,i 1 as Some examples of state transition systems
given in the previous example. Using the are: digital systems, vending machines, etc.
above concept we devise the following A system containing only a finite number of
grammar for L. states and transitions among them is called
G = (N,∑,P,S) whereN = { S, B } a finite-state transition system. Finite-state
P = { S→Bb, B →ab, B → aBb} transition systems can be modeled
abstractly by a mathematical model called
1.4 FINITE AUTOMATA finite automation. We said that automata
are a model of computation. That means
Automata (singular: automation) are a that they are a simplified abstraction of `the
particularly simple, but useful, model of real thing'. So what gets abstracted away?
computation. They were initially proposed One thing that disappears is any notion of
as a simple model for the behavior of hardware or software. We merely deal with
neurons. The concept of a finite automaton states and transitions between states. The
appears to have arisen in the 1943 paper “A distinction between program and machine
logical calculus of the ideas immanent in executing it disappears. One could say that
nervous activity", by Warren McCullock and an automaton is the machine and the
Walter Pitts. In 1951 Kleene introduced program. This makes automata relatively
regular expressions to describe the easy to implement in either hardware or
behavior of finite automata. He also proved software. From the point of view of resource
the important theorem saying that regular consumption, the essence of a finite
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
automaton is that it is a strictly finite model input string is accepted ; otherwise, the
of computation. Everything in it is of a fixed, string is rejected. Summarizing all the
finite size and cannot be modified in the above we can formulate the following
course of the computation. formal definition:
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Formally, we can give an inductive 1. For each state in Q there is a node.
definition as follows: The language of the 2. There is a directed edge from node q to
DFA M is the set of strings that can take the node plabelled a ifδ(q, a)=p. (If there are
start state to one of the accepting states i.e. several input symbols that cause a
L(M) = { w ∈ ∑* | M accepts w } transition, the edge is labelled by the list
= { w ∈ ∑*|δ*(q0,w)ϵF} of these symbols.)
3. There is an arrow with no source into
Example of DFA thestart state.
M = ( Q, ∑, δ, q0 ,F) 4. Accepting states are indicated by double
Q = { q 0 , q1 } circle.
q0 is the start state A (State) Transition diagram for the
F={q1} language L is shown below.
δ(q0,0)= q0 δ(q1,0)= q1
δ(q0,1)= q1 δ(q1,1)= q1
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
1.4.2 Nondeterministic Finite
Few More Examples on DFA Automata (NFA)
Non determinism is an important
L1 = {Set of strings that ends with 01} abstraction in computer science.
Importance of non-determinism is found in
the design of algorithms. For examples,
there are many problems with efficient
nondeterministic solutions but no known
efficient deterministic solutions.
(Travelling salesman, Hamiltonian cycle,
clique, etc). Behavior of a process is in a
distributed system is also a good example of
L2 = {Set of strings that contains 01} nondeterministic situation. Because the
behavior of a process might depend on some
messages from other processes that might
arrive at arbitrary times with arbitrary
contents.
It is easy to construct and comprehend an
NFA than DFA for a given regular language.
L3 = {Set of strings that starts with 01} The concept of NFA can also be used in
proving many theorems and results. Hence,
it plays an important role in this subject.
In the context of FA non determinism can be
incorporated naturally. That is, an NFA is
defined in the same way as the DFA but with
the following two exceptions:
1. Multiple or No next state.
2. ∈ - Transitions.
∈ - Transitions
L4 = {Strings having second last symbol In an ∈-transition, the tape head doesn't do
0} anything- it does not read and it does not
move. However, the state of the automata
can be changed - that is can go to zero, one
or more states. This is written formally as δ
(q,∈) ={q1, q2, ···, qk} implying that the next
state could by any one of q1, q2, ··· qk w/o
consuming the next input symbol.}
Acceptance
Informally, an NFA is said to accept its input
L5 = (00+11)*
w if it is possible to start in some start state
and process w, moving according to the
transition rules and making choices along
the way whenever the next state is not
uniquely defined, such that when w is
completely processed (i.e. end of w is
reached), the automata is in an accept state.
There may be several possible paths
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
through the automation in response to an Note: In case of NFA, for string w there can
input w since the start state is not be many paths from the starting state. If any
determined and there are choices along the of the path is ending in accepting state, the
way because of multiple next states. Some of string is said to be accepted by NFA. If none
these paths may lead to accept states while of the path ends in accepting state the string
others may not. The automation is said to is said to be rejected by NFA.
accept w if at least one computation path on
input w starting from at least one start state The Extended Transition function δ*,
leads to an accept state- otherwise, the
automation rejects input w. Alternatively, To describe acceptance by an NFA formally,
we can say that, w is accepted if there exists it is necessary to extend the transition
a path with label w from some start state to function, denoted as δ*, takes a state q ∈ Q
some accept state. Since there is no and a string w∑*, and returns the set of
mechanism for determining which state to states, S⊆ Q, that the NFA is in after
start in or which of the possible next moves processing the string w if it starts in state q.
to take (including the w - transitions) in Formally, δ̂is defined as follows:
response to an input symbol we can think
that the automation is having some 1. δ*(q,∈)={q} that is, without rending any
"guessing" power to choose the correct one input symbol, an NFA does not change
in case the input is accepted. state.
2. Let y = xa some∞, xϵ∑* and aϵ∑. δ*(q,y)
Example = δ*(q,xa)= U { δ(r,a), where r ϵ δ*(q,x) }
Consider the language L = {wЄ{a,b}*| Strings .
ending in ab}. The following NFA accepts L.
Formal definition of NFA
Formally, an NFA is a quintuple
M = ( Q, ∑, δ , q0, F) where Q, ∑, q0, and F bear
the same meaning as for a DFA, but δ, the
transition function is redefined as follows:
δ : Q x ( ∑ ∪ {∈}) → P (Q) where P(Q) is the
power set of Q i.e.2Q.
The m/c is not deterministic since there are
two transitions from state 1 on input a, no The Language of an NFA:
transition (zero transition) from state 2 for From the discussion of the acceptance by an
symbol a and no transition from state 3 for NFA, we can give the formal definition of a
symbols a & b. For any string w which ends language accepted by an NFA as follows :
with ab, there exists a sequence of legal If N = (Q, ∑, δ, q0, F ) is an NFA, then the
transitions leading from the start state 1, to language accepted by N is written as L(N)
the accept state 3. But for any string w which given by L(N) = {w | δ*(q,w) ∩ F ≠ Φ} .
does not end with ab, there is no possible That is, L(N) is the set of all strings w in
sequence of legal transitions leading from 1 ∑* such that δ*(q,w)contains at least one
to 3. Hence m/c accepts L. accepting state.
If you observe the NFA, you will find that for Few More Examples on NFA
string aab it ends in state 1 as well as state 3
but one of the state from 1 and 3 is accepting L1 = {Set of strings that ends with 01}
state, hence the string is said to be accepted
by NFA.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
L. Given two DFAs accepting the same
language L, it is now natural to ask - which
one is more simple? In this case, obviously,
the one with less number of states would be
simpler than the other. So, given a DFA
accepting a language, we might wonder
L2 = {Set of strings that contains 01} whether the DFA could further be simplified
i.e. can we reduce the number of states
accepting the same language?
Consider the following DFA M1,
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
but at this point we assume that merging f q0 , y q x L y .
these states would not change the
accepted language. Inaccessible states A Minimization Algorithm
can easily be found out by using a simple
We now produce an algorithm to construct
research e.g. depth first search.
the minimal state DFA from any given DFA
Removing trap states are also simple. In
accepting L by merging states inductively.
the example, states 5 and 6 are
The algorithm assume that all states are
inaccessible and hence can be removed;
reachable from the start state i.e. there is no
states 1 and 2 are equivalent and can be
inaccessible states. The algorithm keeps on
merged. Similarly states 3 & 4 are also
marking pairs of states (p, q) as soon as it
equivalent and can be merged together
determines that p and q are distinguishable
to have the minimal DFA M2as produced
i.e. p ≢ q. The pairs are, of course, unordered
above.
i.e. pairs (p, q) and (q ,p) are considered to
To construct the minimal DFA we need
be identical. The steps of the algorithm are
to see how to find out indistinguishable
given below.
or equivalent states for merging. we
start with a definition and then proceed 1. For every p, q ∈ Q , initially unmark all
to find method to construct minimal pairs (p, q ).
state DFAs. 2. If p∈ F and q F (or vice versa) then
mark (p, q).
Note: For any regular language L there is a
3. Repeat the following step until no more
unique DFA that has a minimum number of
changes occur: If there exists an
states. In fact, the minimum DFA has as
unmarked pair (p, q) such that
many states as the equivalence classes of L.
(as defined in the context of Mayhill-Nerada p,a , q,a is marked for some
Theorem). a , then mark (p, q).
4. p q iff (p, q) is unmarked.
Definition of Indistinguishability: The algorithm correctly computes all pairs
States p and q are indistinguishable if of states that can be distinguished i.e.
unmarked. It is easy to show (by induction)
x * p, x F if f q, x F , and is that thepair (p, q) is marked by the above
denoted as p q . It is easy to see that algorithm if x * s.t.
indicting usability is an equivalence p, x F and q, x F (or vice versa ) i.e.
relation.
if p ≢ q
In other words we say that sates p and q are
"distinguishable" if x * s.t
Example:
p, x Fand q, x F is denoted as Consider the following DFA which we need
p q. to minimise:
We say that, states p and q of a DFA M
accepting a language L can be merged safely
(i.e. without changing the accepted language
L) if p q i.e. if p and q are
indistinguishable. We can prove this by
showing that when p and q are merged.
Then they correspond to the same state in
M L Formally, p q iff
x, y *, q0 , x p andx
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Initially, all cells are unmarked. (i.e. at step q3 ,q4
1
q5 ,q5
1 of the algorithm). After step 2, all cells The resulting table after this pass is given
representing pairs of states of which one is below.
accepting and the other is non-accepting are
marked by putting an X. The table below
shows the status after this step.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Transitions are adjusted appropriately to Example
obtain the following minimal DFA. Let = {0,1,2}. Then (0+21)*(1+ ∅) is a RE,
because we can construct this expression by
applying the above rules as given in the
following step.
Steps RE Constructed Rule Used
q12 is a final state, since both q1 & q 2 were 1 1 Rule 1(iii)
2 ∅ Rule 1(i)
final states. Similarly q34 is a non-final state. Rule 2(i) & Results
q 0 Goes to q12 on input 0 and 1, since q 0 go 3 1+∅ of Step 1, 2
4 (1+∅) Rule 2(iv) & Step 3
to q1 and q 2 respectively on 0 and .Similar, 5 2 1(iii)
justifications suffice for other adjusted 6 1 1(iii)
transitions.
7 21 2(ii), 5, 6
8 0 1(iii)
1.6 REGULAR EXPRESSION: FORMAL 9 0+21 2(i), 7, 8
DEFINITION 10 (0+21) 2(iv), 9
11 (0+21)* 2(iii), 10
We construct REs from primitive 12 (0+21)* 2(ii), 4, 11
constituents (basic elements) by repeatedly
applying certain recursive rules as given 1.7 LANGUAGE DESCRIBED BY RES
below. (In the definition)
Each describes a language (or a language is
Definition associated with every RE). We will see later
Let Σ be an alphabet. The regular that REs are used to attribute regular
expressions are defined recursively as languages.
follows.
Notation
BASIS If r is a RE over some alphabet then L(r) is
the language associated with r. We can
i) is a RE define the language L(r) associated with (or
described by) a REs as follows.
ii) ∈ is a RE
1. ∅ is the RE describing the empty
iii) ∀ a ∈ ∑ , a is RE.
language i.e. L(∅) =∅.
These are called primitive regular 2. ∈ is a RE describing the language {∈} i.e.
expression i.e. Primitive Constituents L(∈) = {∈} .
3. ∀ a ∈ ∑, a is a RE denoting the language
RECURSIVE STEP {a} i.e . L(a) = {a} .
4. If r1 and r2 are REs denoting language
If r1 and r2 are REs over Σ* , then so are L(r1) and L(r2) respectively, then
i) r1 r2 ii) r1r2 i) r1 r2 is a regular expression denoting
iii) r1* iv) (r1) the language L( r1 r2 ) = L(r1) + L(r2)
ii) r1r2 is a regular expression denoting
CLOSURE
the language L( r1r2 )=L(r1) L(r2)
r is RE over Σ* only if it can be obtained from iii) r1*is a regular expression denoting
the basic elements (Primitive REs) by a the language L(r1*) = (L(r 1))*
finite no of applications of the recursive step iv) (r1) is a regular expression denoting
(given in 2.1.2). the language L((r1)) = L(r1)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Example Example
Consider the RE (0*(0+1)). Thus the The RE (ab)*+b represents the language
language denoted by the RE is (L(a)L(b))* ∪L(b).
L(0*(0+1)) = L(0*) L(0+1) ..................... ..by
4(ii) Example
= L(0)*{L(0) + L(1)} It is easy to see that the RE (0+1)*(0+11)
= { , 0,00,000,........} {0} ∪{1} represents the language of all strings over
= { , 0,00,000,........} {0,1} {0,1} which are either ended with 0 or 11.
={0,00,000,0000,........,1,01,001, 0001,........} Example
The regular expression r =(00)*(11)*1
Precedence Rule denotes the set of all strings with an even
number of 0's followed by an odd number of
Consider the RE ab + c. The language
described by the RE can be thought of either 1's i.e. L(r) {02n12m1 | n 0, m 0}
L(a)L(b+c) or L(ab)∪ L(c) as provided by Note:
the rules (of languages described by REs) The notation r+ is used to represent the RE
given already. But these two represents two rr*. Similarly, r2 represents the RE rr, r3
different languages lending to ambiguity. To denotes rr2, and so on. An arbitrary string
remove this ambiguity we can either over ∑= {0,1} is denoted as (0+1)*.
1) Use fully parenthesized expression- Exercise:
(cumbersome) or Give a RE r over {0,1} s.t. L(r)={ x∈{0,1}*|x
2) Use a set of precedence rules to evaluate has at least one pair of consecutive 1's}
the options of REs in some order. Like
other algebras mod in mathematics .For Solution
REs, the order of precedence for the Every string in L(r) must contain 11
operators is as follows: somewhere, but what comes before and
i) The star operator precedes what goes before is completely arbitrary.
concatenation and concatenation Considering these observations we can
precedes union (+) operator. write the REs as (0+1)*11(0+1)*.
ii) It is also important to note that
concatenation & union (+) operators Example
are associative and union operation Considering the above example it becomes
is commutative. Using these clear that the RE (0 + 1) * 11 (0 + 1) * + (0 +
precedence rule, we find that the RE 1)*00(0+1)* represents the set of string
ab+c represents the language over {0,1} that contains the substring 11 or
L(ab)∪L(c) i.e. it should be grouped 00.
as ((ab)+c).
We can, of course change the order Example
of precedence by using parentheses. Consider the RE 0*10*10*. It is not difficult
For example, the language to see that this RE describes the set of
represented by the RE a(b+c) is strings over {0,1} that contains exactly two
L(a)L(b+c). 1's. The presence of two 1's in the RE and
any no of 0's before, between and after the
Example 1's ensure it.
The RE ab*+b is grouped as ((a(b*))+b)
which describes the language L(a)(L(b))*∪ Example
L(b) Consider the language of strings over {0,1}
containing two or more 1's.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Solution RE = 00(0+1)*00 + 00 + 000
There must be at least two 1's in the RE
somewhere and what comes before, L = {Strings starting with 00 or 11}
between, and after is completely arbitrary. RE = 00(0+1)* + 11(0+1)*
Hence we can write the RE as = (00+11) (0+1)*
(0+1)*1(0+1)*1(0+1)*. But following two
REs also represent the same language, each L = {Strings starting with 00 and 11}
ensuring presence of least two 1's RE = ∅
somewhere in the string
i) 0*10*1(0+1)* L = {Strings containing 00 or 101}
ii) (0+1)*10*10* RE = (0+1)*00(0+1)* + (0+1)*101(0+1)*
= (0+1)*(00+101)(0+1)*
Example
Consider a RE r over {0,1} such that L(r) = L = {Strings containing 00 and 11}
{x∈{0,1}*|x has no pair of consecutive 1's} RE = (0+1)*00(0+1)*11(0+1)* +
(0+1)*11(0+1)*00(0+1)*
Solution = (0+1)*[00(0+1)*11+11(0+1)*00] (0+1)*
Though it looks similar to ex ……., it is harder
to construct to construct. We observer that, L = {Strings having second last symbol 0}
whenever a 1 occurs, it must be immediately RE = (0+1)*0(0+1)
followed by a 0. This substring may be
preceded & followed by any no of 0's. So the L = {Strings having even length}
final RE must be a repetition of strings of the RE = ((0+1) (0+1))* or (00+11+01+10)*
form: 00…0100….00 i.e. 0*100*. So it looks L = {Strings having odd length}
like the RE is (0*100*)*. But in this case the RE = ((0+1)(0+1))*(0+1) or
strings ending in 1 or consisting of all 0's are (00+11+01+10)* (0+1)
not accounted for. Taking these
observations into consideration, the final RE If we take ∑ = {0,1,2} then:
is r = (0*100*)(1+∈)+0*(1+∈). L = {Strings ending in 01}
RE = (0+1+2)*01
Alternative Solution:
The language can be viewed as repetitions L = {Strings starting with 01}
of the strings 0 and 01. Hence get the RE as RE = 01(0+1+2)*
r = (0+10)*(1+∈). This is a shorter
expression but represents the same L = {Strings having second last symbol 0}
language. RE = (0+1+2)*0(0+1+2)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
∅* = ∈ If L(r) is a language described by the RE r,
∈* = ∈ then it is regular i.e. there is a FA such that
r∈=∈r=r L(M)≅ L(r).
r∅= ∅r =∅
∅+r= r Proof
r1 + r2 = r2 + r1 To prove the lemma, we apply structured
r1 r2 ≠ r2 r1 index on the expression r. First, we show
r+ r=r how to construct FA for the basic
r* + r* = r* elements:∅, ∈ and for any ∑. Then we
r*r* = r* show how to combine these Finite Automata
r r* = r* r = r + into Complex Automata that accept the
r+ + ∈ = r* Union, Concatenation, Kleen Closure of the
p(qr) = (pq)r languages accepted by the original smaller
p+(q+r) = (p+q) + r automata.
p (q+r) = pq + pr Use of NFAs is helpful in the case i.e. we
(q+r) p = qp + rp construct NFAs for every REs which are
(pq)* p = p (qp)* represented by transition diagram only.
(p+q)* = (p* + q*)* = (p*q*)* =
(q*p*)* = (p* + q*)+ = (p+ + q+)* = (p* Basis
+ q+)* = (p+ + q*)* = (p+ + q*)+ = (p* + Case (i) :
q+)+ r=∅. Then L(r)=∅. Then L(r)=∅ and the
following NFA N recognizes L(r).
1.8 REGULAR EXPRESSION & REGULAR Formally N (Q,{q}, , ,F, ) where Q =
LANGUAGE: {q} and (q,a) S,F .
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Induction consuming any input. WLOG, assume
Assume that the start of the theorem is true that, it enters the start state of M1 . From
for REs r1 and r2. Hence we can assume that this point onward it has to follow only
we have automata M1 and M2 that accepts the transition of M1 to enter the final
languages denoted by REs r1 and r2 , state of M1 , because this is the only way
respectively i.e. to enter the final state of M by following
the e-transition.(Which is the last
L(M1 ) L(r1 ) and L(M2 )=L(r2 ) . transition & no input is taken at the
The FAs are represented schematically as transition). Hence the whole input w is
shown below. Each has an initial state and a considered while traversing from the
final state. There are four cases to consider. start state of M1 to the final state of M1.
Therefore M1 must accept w3.
Case (i) : Union Say w L(M1 )or w L(M2 ) .
Consider the RE r3 r1 r2 denoting the WLOG, say w L(M1 )
language L(r1 ) L(r2 ) . Therefore when M1 process the string w,
it starts at the initial state and enters the
final state when w consumed totally, by
following its transition. Then M3 also
accepts w, by starting at state q’ and
taking ∈ -transition enters the start state
of M1 -follows the moves of M1 to enter
the final state of M1 consuming input w
thus takes ∈-transition tof’ . Hence
We construct FA M3, from M1 and M2 to proved.
accept the language denoted by RE r3 as
follows : Case(ii): Concatenation
Create a new (initial) start state q’ and Consider the RE r3 r1r2 denoting the
give ∈ - transition to the initial state
of M1 and M2.This is the initial state of language L(r1 )L(r2 ) .
M3.
Create a final state f’ and give -
transition from the two final state of
M1and M2. F’is the only final state of M3
and final state of M1 and M2 will be
ordinary states in M3. We construct FA M3 from M1 & M2 to accept
All the state of M1 and M2 are also state L(r3 ) as follows :
of M3. Draw ∈ - transitions from the
All the moves of M1 and M2 are also accepting states of M1 to the starting
moves of M3. [ Formal Construction]
states of M2.
It is easy to prove that L(M3 ) L(r3 ) Convert the accepting states of M1 to
Proof: To show that L(M3 ) L(r3 ) we non-accepting states.
must show that Accepting states of M3 will be the
L(r1 ) L(r2 ) accepting states of M2 only.
Starting state of M3 will be starting
L(M1 ) L(M2 ) by following transition state of M1 only.
of M3.Starts at initial state q’ and enters
the start state of either M1 or M2
following the transition i.e. without
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Case(iii): Kleene Star Left linear grammar:
Consider the RE r3 =(r1)* denoting A grammar G is left-linear if each production
the language L(r3) = L(r1)* has one of the following forms.
V -> VT* or V->T*
where V is the set of variables and T ∈ ∑.
Example:
G2 = < V, { a, b }, S, P > , where V = {S} ,
P = { S -> Sa, S -> Sb, S -> } is a left linear
grammar.
We can construct FA for L(r) as follows: Hence G2 is regular grammar.
Create a new state. Make it starting
state. Make it accepting state. Let us Example:
call this state as q. G3 = < V, { a, b }, S, P > , where V = {S} ,
Draw ∈ - transition from q to the P = { S -> aSb, S -> } is neither right
starting state of M1. linear nor left linear.
Draw ∈ - transition from the Hence G3 is not regular grammar.
accepting state of M1 to q.
Convert the accepting state of M1 to 1.10 REGULAR LANGUAGE
Non-accepting states. Definition:
A language L is said to be regular if :
L(M3 ) (L(M1 ))* | (L(r)1)* r1* . It has a regular grammar. Or
Its regular expression exist. Or
Case (iv): Parenthesis Its DFA exist. Or
Let r3 (r1 ) . Then the FA M1 is also the FA for Its NFA exist.
(r1), since the use of parentheses does not So Regular grammar, Regular expression,
change the language denoted by the DFA and NFA are all equivalent in the sense
expression. that any language which can be defined by
any of these can also be defined by others.
1.9 REGULAR GRAMMARS
For the example in the previous topic we
A grammar is said to be regular grammar if can say that the language((a+b)*)
it is either left linear or right linear. represented by G1 and G2 is regular but the
language ((anbn|n>=0)) represented by G3 is
Right linear grammar: not.
A grammar G=(V, ∑,S,P)is right-linear if each
production has one of the following forms: All languages we have seen in topic 2.2 are
V -> T*V or V->T* regular.
where V is the set of variables and T ∈ ∑.
Closure properties of Regular
Example: Languages:
G1 = < V, { a, b }, S, P > , where V = {S} , Regular languages are closed under:
Union, Intersection, Concatenation, Kleene
P = { S -> aS, S -> bS, S -> } is a right
Closure, Difference, Complement, Reversal,
linear grammar.
Homomorphism, Inverse Homomorphism
Hence G1 is regular grammar.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
i) Union:
If L and M are regular languages, so is Example:
L M. L = (a+b)* and M = a*
L M = (a+b)*a*
Let L and M be the languages of
regular expressions R and S, iv) Kleene Star:
respectively. If L is a regular language then L* will
Then R+S is a regular also be a regular language.
expression whose language is L
M. Let the regular expression for
the language L is r then the
Example: regular expression of
L = (a+b)* and M = a* language L* will be r*.
L U M = (a+b)* + a* = (a+b)*
Example:
ii) Intersection: Let L = (a+b) then L* = (a+b)*
If L and M are regular languages, then
so is L M. v) Difference:
If L and M are regular languages, then
Let D1 and D2 be DFA’s whose so is L – M = strings in L but not M.
languages are L and M,
respectively. Let D1 and D2 be DFA’s whose
Construct D3, the product languages are L and M,
automaton of D1 and D2. respectively.
Make the final states of D3 be Construct D3, the product
the pairs consisting of final automaton of A and B.
states of both D1 and D2. Make the final states of C be
the pairs where A-state is
Example: final but B-state is not.
Example:
iii) Concatenation:
If L and M are regular languages, so is
L M. vi) Complement:
Let L is the regular language then L’
Let L and M be the languages will also be a regular language.
of regular expressions R and
S, respectively. Let D is the DFA for language
Then R+S is a regular L.
expression whose language is
L
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Convert accepting states of D viii) Homomorphism:
to non-accepting states and If L is a regular language, and h is a
non-accepting states to homomorphism on its alphabet,
accepting states to get the then h(L) = {h(w) | w is in L} is also
DFA for language L’. a regular language.
Example: A homomorphism on an
Consider the DFA D for alphabet is a function that
language L: gives a string for each
symbol in that alphabet.
Let E be a regular expression
for L.
Apply h to each symbol in E.
Language of resulting RE is
h(L)
Example:
The DFA D’ for language L’ will be: Let h(0) = ab; h(1) = ε and L =
01* + 10* then h(L) will be abε*
+ ε(ab)* = (ab)*
vii) Reversal:
If L is regular then L R will also be Example:
regular language. Let h(0) = ab; h(1) = ε. Let L = {abab,
baba}.
Let D be the NFA for h-1(L) = the language with two 0’s
language L. and any number of 1’s =
Convert starting state of D to L(1*01*01*)
accepting state and
accepting state of D to Here, no string maps to baba; any
starting state. string with exactly two 0’s maps to
If D has more than one abab.
accepting state then create
new state, make it starting 1.11 NON-REGULAR LANGUAGES:
state and draw null We have learned regular languages, their
transitions to the old properties and their usefulness for
accepting states. describing various systems. There are,
Reverse the direction of however, languages that are not regular
transtitions. and therefore require devices other than
finite automata to recognize them.
Example:
Let L = 01* + 10*then L R = 1*0 + 0*1 In this section we are going to study some
of the methods for testing given
languages for regularity and see some of
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
the languages that are not regular. The language.
main idea behind these test methods is
that finite automata have only finite Using this concept of indistinguishability,
amount of memory in the form of states the following theorem by Myhill and
and that they can not distinguish Nerod gives a criterion for
infinitely many strings. (non)regularity of a language.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
conditions of Myhill-Nerode theorem. The following theorem which is called
Hence L 2 is nonregular. Pumping Lemma is based on this
observation. It states that if a language is
Pumping Lemma: regular, then any long enough string of
Let us consider the NFA given below. the language has a substring which can
be repeated any number of times with the
resultant strings still in the language. It is
stated without a proof here.
Pumping Lemma :
Suppose that a language L is regular.
Then there is an FA that accepts L. Let n
be the number of states of that FA. Then
for any string x in L with |x| ≥ n, there are
strings u, v and w which satisfy the
following relationships:
x = uvw
This NFA accepts among others some |uv| ≤ n
strings of length greater than 5 such as |v| > 0 and
abbabbb, abbabbabbb etc. Those strings for every integer m ≥ 0,
which are accepted by this NFA and uvmw ∈ L.
whose length is greater than 5 have a
substring which can be repeated any Note that Pumping Lemma gives a
number of times without being rejected necessity for regular languages and that
by the NFA. it is not a sufficiency, that is, even if there
is an integer n that satisfies the
For example the string abbabbb is conditions of Pumping Lemma, the
accepted by the NFA and if one of its language is not necessarily regular. Thus
substrings bba is repeated any number of Pumping Lemma can not be used to
times in abbabbb, the resultant strings prove the regularity of a language. It can
such as abbb (bba repeated 0 times), only show that a language is nonregular.
abbabbabbb, abbabbabbabbb etc. are
also accepted by the NFA. Example 4: As an example to illustrate
In general if a string w (such as abbabbb how Pumping Lemma might be used to
in the example above) is accepted by an prove that a language is nonregular, let us
NFA with n states and if its length is prove that the language L = a kbk is
longer than n, then there must be a cycle nonregular, where k is a natural number.
in the NFA along some path from the
initial state to some accepting state (such Suppose that L is regular and let n be the
as the cycle 2-3-4-2 in the above number of states of an FA that accepts L.
example). Consider a string x = a nbn for that n. Then
there must be strings u, v, and w such
Then the substring representing that that
cycle (bba in the example) can be
repeated any number of times within the x = uvw,
string w without being rejected by the |uv| ≤ n
NFA. |v| > 0 , and
for every m ≥ 0, uvmw ∈ L.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Since |v| > 0 , v has at least one symbol. Every finite subset of regular set is
Also since |uv| ≤ n, v = ap, for some p > 0, regular.
Let us now consider the string uv mw for Every subset of regular set need not
m = 2. be regular.
Then uv2w = an-pa2pbn = an+pbn . Since p > Subset of non regular set need not
0 , n + p ≠ n . Hence an+pbn can not be in be non regular.
the language L represented by a kbk . Every finite language has regular
This violates the condition that for every subset.
m ≥ 0, uvmw ∈ L. Hence L is not a regular Every finite language except ∅ has
language. regular proper subset.
If the language is defined over
single symbol then it will be regular
Few examples of Non-Regular only if the length of strings of the
Languages: language is in arithmetic
L = { w ∈ {a,b}* : w = aibi, for some i ≥ 0 } progression.
L = { w ∈ {a,b}* : w = ambn, for m > n } Let RL = Regular language and NRL
L = { w ∈ {a,b}* : w = ambn, for m < n } = Non-Regular language then:
L = { w ∈ {a,b}* : #a(w) = #b(w) } RL U NRL = RL/NRL
L = { wwR : w ∈ {a,b}* } RL NRP = RL/NRL
L = {Even length palindrome strings} NRL U NRL = RL/NRL
L = {Odd length palindrome strings} RL NRL = RL/NRL
L = { ww : w ∈ {a,b}* }
L = { w ∈ {a,b}* : w = ambncp, m=n+p }
L = { w ∈ {a,b}* : w = ambncp, m=n }
L = { w ∈ {a,b}* : w = ambncp, m=4n or
n=5p}
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
GATE QUESTIONS
sequence contains 11
a) L1 and L2 c) Outputs 00 whenever the input
b) All sequence contains 10
c) L3 and L4 d) None of the above
d) L3 only [GATE-2002]
[GATE-2001] Q.7 Consider the NFA, M, shown below:
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
accepting state and by changing the Q.11 Which one of the following regular
non-accepting states of M to accepting expressions is NOT equivalent to the
states. regular expression (a + b + c)*?
Which of the following statements is a) a * b* c* * b) a *b*c* *
true?
a) L1 = {0, 1}* - L b) L1 = {0, 1}* c) ab * c* * d) a *b* c* *
c) L1⊆ 1 d) L 1 =L [GATE-IT-2004]
[GATE-2003] Q.12 Let M K, , ,s,F be a finite state
Q.8 Consider the following deterministic automation, where K A, B ,
finite state automaton M a,b , s A, F B ,
A,a A, A, b B, B,a
Band B, b A
A grammar to generate the language
accepted by M can be specified as
Let S denotes the set of seven bit G V,Σ,R,S , Where V=K∪Σ, S = A
binary strings in which the first, the
fourth and the last bits are 1. The Which one of the following setoff
number of strings in S that are rules will make L(G)=L(M)?
accepted by M is a) A aB,A bA,B bA,B aA,B
a) 1 b) 5 b)
c) 7 d) 8 A aA, A bB,B aB,B bA, B
[GATE-2003]
c)
Q.9 The regular expression 0*(10*)*
denotes the same set as A bB,A aB,B aA,B bA,B )
a) (1*0)*1* d)
b) 0 + (0 + 10)* A aA,A bA,B aB,B bA,A
c) (0+1) *10 (0+1) * [GATE-IT-2004]
d) None of these
[GATE-2003] Q.13 Which of the following statements is
TRUE about the regular expression
Q.10 The following finite state machine 01*0?
accepts all those binary strings in a) It represents a finite set of finite
which the number of 1’s and O's are strings.
respectively b) It represents an infinite set of
finite strings.
c) It represents a finite set of infinite
strings.
d) It represents an infinite set of
infinite strings.
[GATE-IT-2005]
a) divisible by 3 and 2
Q.14 The language on 1n 2n 1 n 106 is
b) odd and even a) Regular
c) even and odd b) Context-free but not regular.
d) divisible by 2 and 3 c) Context-free but its complement
[GATE-2004] is not context-free.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
d) Not context-free. following statements about L is
[GATE-IT-2005] TRUE?
a) L is necessarily a regular
Q.15 Consider the non-deterministic finite
language.
automaton (NFA) shown in the b) L is necessarily a context-free
figure
language, but not necessarily a
regular language.
c) L is necessarily a non-regular
language.
d) None of the above
[GATE-IT-2005]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
c) w a b*| #a w #b (W)
and
w a b*| #a (w) #b w
d) ,wa w a b * and
wb w a b *
[GATE-IT-2006]
Consider the string u=abbaba, v=
Q.23 Which of the following statements
bab, and w=aabb. Which of the
about regular languages is NOT true?
following statements is true?
a) Every language has a regular
a) The automaton accepts u and v
superset
but not w
b) Every language has a regular
b) The automaton accepts each of
subset
u, v, and w
c) Every subset of a regular
c) The automaton rejects each of u,
language is regular
v, and w
d) Every subset of a finite language
d) The automaton accepts u but
is regular
rejects v and w
[GATE-IT-2006]
[GATE-IT-2006]
Directions for Q.24 to Q.25:
Q.21 Which regular expression best
Let L be a regular language. Consider the
describe the language accepted by
constructions on L below:
the non-deterministic automaton
I. repeat (L) = {ww | w ∈ L)
below?
II. prefix (L) = u v : uv L
III. suffix (L) = v u : uv L
a) a b *a a b b
IV. half (L) = u v : v u and uv L
b) abb * Q.24 Which of the constructions could
c) a b *a a b *b a b * lead to a non-regular language?
a) Both I and I V b) Only I
d) a b * c) Only IV d) Both II and III
[GATE-IT-2006] [GATE-IT-2006]
Q.22 Consider the regular grammar below Q.25 Which choice of L is best suited to
S bS aA support your answer above?
a) (a+b)* b) {ε,a, ab, bab}
A aS bA c) (ab)* d) {anbn | n ≥ 0}
The My hill-Nerode equivalence [GATE-IT-2006]
classes for the language generated by
the grammar are Q.26 Consider the regular language L=
a) w a b * #a w is even and (111+11111)*. The minimum number
of states in any DFA accepting this
w a b * #a (w)is odd language is
b) w a b*| #b w is even and a) 3
c) 8
b) 5
d) 9
{w a b*| #b (w)is odd [GATE-2006]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.27 If s is a string over (0+1)* then let L={W|W∈{0,1}*, number of 0's and
n0(s) denotes the number of 0's in s 1's in W are divisible by 3 and 5,
and n1 (s) the number of 1's in s. respectively} has
Which one of the following languages a) 15 states b) 11 states
is not regular? c) 10 states d) 9 states
a) L={s∈(0+1)*|n0(s) is a 3-digit [GATE-2007]
prime}
b) L= {s ∈ (0 + 1)* | for every prefix Q.32 Which of the following is true?
s' of s,| n0(s') – n1(s’) |≤ 2} a) Every subset of a regular set is
c) L = {s ∈ (0 +1)*| n0(s)–n1(s) | ≤ 4 regular
d) L = {s ∈ (0 + 1)* | n0(s) mod 7= b) Every finite subset of a non-
n1(s) mod 5=0} regular set is regular
[GATE-2006] c) The union of two non-regular
sets is not regular
Common Data for Questions 28 and 29 d) Infinite union of finite sets is
Consider the following Finite State regular
[GATE-2007]
Automation:
Q.33 The two grammars given below
generate a language over the
alphabet {x, y, z}
G1: S → x|z|xS|zS|yB
B→ y|z|yB|zB
G2: S→ y|z|yS|zS|xB
B→y|yS
Q.28 The language accepted by this Which one of the following choices
automaton is given by the regular describes the properties satisfied by
expression the string in these languages?
a) b* ab* ab* ab* b) (a+b)*
c) b* a(a + b)* d) b* ab* ab* a) G1 : No y appears before any x
[GATE-2007] G2 : Every x is followed by at least
one y
Q.29 The minimum state automaton b) G1 : No y appears before any x
equivalent to the above FSA has the G2 : No x appears before any y
following number of states c) G1 : No y appears after any x
a) 1 b) 2 G2 : Every x is followed by at least
c) 3 d) 4 one y
[GATE-2007] d) G1 : No y appears after any x
Q.30 Which of the following languages is G2 : Every y is followed by at least
regular? one x
[GATE-IT-2007]
a) {WWR | W 0,1 }
[GATE-2007]
Q.31 A minimum state deterministic finite
automaton accepting the language
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
What language does this DFA
recognize?
a) All strings of x and y
b) All strings of x and y which have The automation which recognize the
either even number of x and even language L(P)∩L(Q) is:
number of y or odd number or x a)
and odd number of y
c) All strings of x and y which have
equal number of x and y
d) All strings of x and y with either
even number of x and odd
number of y or odd number of x
b)
and even number of y
[GATE-IT-2007]
Q.35 Consider the grammar given below
S → xB|yA
A → x|xS|yAA
B →y|yS|yBB c)
Consider the following strings.
(i)xxyyv (ii)xxyyxv
(iii)xyxy (iv)yxxy
(v)yxx (vi)xyx
Which of the above strings are
generated by the grammar? d)
a) (i), (ii) & (iii) b) (ii),(v)& (vi)
c) (iii) & (iv) d)(i),(iii) &(iv)
[GATE-IT-2007]
Q.36 Consider the following finite
automata P and Q over the alphabet
{a,b,c}. the start states are indicated [GATE-IT-2007]
by a double arrow and final states Common Data for Q.37 to Q.38:
are indicated by a double circle. Let Consider the regular expression:
the languages recognized by them be
R a b * aa bb a b *
denoted by L(P) and L(Q)
respectively. Q.37 Which of the following non-
deterministic finite automata
recognizes the language defined by
the regular expression R? Edges
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
labelled λ denote transitions on the
empty string.
a)
b) d)
c)
[GATE-IT-2007]
b) a ba * b ab * * a b
*
c) a ba * a bb b ab * b aa
a b*
[GATE-IT-2007]
d) a ba * a bb b ab * b aa
Q.38 Which deterministic finite a b
automaton accepts the language [GATE-IT-2007]
represented by the regular
expression R? Q.40 Which of the following regular
a) expressions describes the language
over {0,1} consisting of strings that
contain exactly two 1’s?
a) 0 1 *11 0 1 *
b) 0*110*
b) c) 0*10*10*
d) 0 1 *1 0 1 *1 0 1 *
[GATE-IT-2008]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a) m 2n
b) n m
c) M has one accept state
d) m 2n
[GATE-IT-2008]
a) L1 L2 b) L1 L2
Q.42 If the final states and non-final states c) L1 L2 d) L1 L2 L1
in the DFA below are interchanged, [GATE-IT-2008]
then which of the following
languages over the alphabet {a, b} Q.45 Which of the following are regular
will be accepted by the new DFA? sets?
1. {anb2m | n 0, m 0}
2. {anbm | n=2m}
3. {anbm | n m}
4. {xcy |x, y, {a,b}*}
a) 1 and 4 b) 1 and 3
c) 1 only d) 4 only
[GATE-2008]
a) Set of all strings that do not end
with ab
Q.46 Match the following NFAs with the
b) Set of all strings that begin with
regular expressions they correspond
either an a or ab
to
c) Set of all strings that do not
contain t eh substring ab,
d) The set described by the regular
expression b*aa*(ba)*b*
[GATE-IT-2008]
Q.43 Which of the following languages is
(are) non-regular?
L1 0m1n 0 m n 10000
L2 {w w reads the same forward
and backward}
L3 {w 0,1 * w contains an even
number of 0’s and an even number of
1’s} 1. ε + 0 (01*1+00)*01*
a) L 2 and L 3 only b) L1 and L 2 only 2. ε + 0(10* 1 + 00)*0
3. ε + 0(10* 1+10)* 1
c) L 3 only d) L 2 only 4. ε + 0 (10* 1 + 10)* 10*
[GATE-IT-2008] a) P-2, Q-1, R-3, S-4
b) P-1, Q-3, R-2, S-4
Q.44 Consider the following two finite c) P-1, Q-2, R-3, S-4
automata. M1 accepts L1 and M 2 d) P-3, Q-2, R-1, S-4
[GATE-2008]
accepts L 2 . Which one of the following
is TRUE? Q.47 Given below are two finite state
automata (→indicates the start state
and F indicates a final state)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Y: a b Z: a b Q.48
→1 1 2 →1 2 2
2(F) 2 1 2(F) 1 1
Which of the following represents The above DFA accept the set of all
the product automation Z × Y? strings over (0, 1) that
a) a) begin either with 0 or 1
a b b) end with 0
c) end with 00
→P S R
d) contain the substrings 00
Q R S [GATE-2009]
R(F) Q P
Q.49 Given the following state table of an
FSM with two states A and B, one
S P Q input and one output.If the initial
state is A=0, B=0, what is the
b) minimum length of an input string,
a b which will take the machine to the
state A =0, B =1 with output =1?
→P S Q Presn Presn
t t Next
Q R S state state inpu state Next Outp
A B t A state B ut
0 0 0 0 0 1
R(F) Q P 0 1 0 1 0 0
1 0 0 0 1 0
S P Q 1 1 0 1 0 0
0 0 1 0 1 0
0 1 1 0 0 1
c) 1 0 1 0 1 1
a b 1 1 1 0 0 1
a) 3 b) 4
→P Q S c) 5 d) 6
[GATE-2009]
Q R S
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
number of states in a non-
deterministic finite automation that
accepts L?
a) n - 1 b) n
c) n + 1 d) 2n-1 [GATE-2011]
[GATE-2010]
Q.54 Definition of a language L with
Q.52 Let L = {W ∈ (0+1)* | W has even alphabet {a} is given as following
number of 1s }, i.e., L is the set of all L = { ank | k > 0, and n is a positive integer
bit strings with even number of 1's. constant} What is the minimum
Which one of the regular expressions number of states needed in a DFA to
below represents L? recognize L?
a) (0* 10* 1)* b) 0* (10* 10*)* a) k + 1 b) n + 1
c) 0* (10* 1*)*0* d)0*1(10*1)* 10* c) 2a + 1 d) 2k + 1
[GATE-2010] [GATE-2011]
Q.55 Which of the following pairs have
Q.53 A deterministic finite automation
different expressive power?
(DFA) D with alphabet {a, b} is given
a) Deterministic Finite Automata
below
(DFA) and Mon-determinis tic
Finite Automata (NPFA)
b) Deterministic Push Down
Automata (DPDA) and Non-
deterministic Push Down
Automata (NPDA)
c) Deterministic single-tape turing
Which of the following finite state
machine and non-deterministic
machines is a valid minimal DFA
single tape turing machine
which accepts the same language as D?
a) d) Single-tape Wring machine and
multi-tape turing machine
[GATE-2011]
Q.56 Let P be a regular language and Q be
a context free language such that Q
P. For example, let P be the
language represented by the regular
b) expression p* q* and Q be {p n qn | n ∈
N} Then which of the following is
always regular?
a) P∩ Q b) p - Q
c) Σ*- P d) Σ*- Q
[GATE-2011]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
c) Non-detreministic pushdown automata a)
d) Turing machine 00 01 10 11 q
[GATE-2011]
00 1 0
Q.58 What is the complement of the
language accepted by the NFA shown 01 1
below? Assume Σ = {a} and ε is the
10 0
empty string.
11 0
b)
00 01 10 11 q
a) ⊘ b) 00 0 1
c) a * d) a, 01 1
[GATE-2012]
Q.59 Given the language L ab,aa,baa , 10 0
11 0
[GATE-2012]
Q.61 Consider the DFA, A given below.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
1. Complement of L(A) is context- III) (0+1)*1
free. a) I and II only b) I and III only
2. L(A)=L (11 * 0 + 0) (0 + 1) * 0*1*) c) II and III only d) I, II and III
3. For the language accepted by A, A [GATE-2014]
is the minimal DFA.
4. A accepts all strings over (0,1} of Q.66 Let L 1={an|n>=0} and L 2={bn|n>=0}.
length at least 2. Consider
a) 1 and 3 b) 2 and 4 I) L1.L2 is a regular language
c) 2 and 3 d) 3 and 4 II) L 1.L2 = {anbn |n>=0}
[GATE-2013] Which of the following is correct?
a) only I b) only II
Q.62 Consider the languages L 1=ϕ and L 2
c) Both I and II d) Neither I nor II
= {a}. Which one or the following [GATE-2014]
represents L 1 L*2∪ L*1 ?
a) {ε} b)∅ Q.67 Let L1={w∈{0,1}* | w has at least as
c) a d) {ε,α} many occurrences of (110)’s as
[GATE-2013] (011)’s}. Let L2 = {w∈{0,1}* | w has
Q.63 Which one of the following is TRUE? at least as many occurrences of
(000)’s as (111)’s}. Which one of the
a) The language L={anbn|n>=0} is
following is TRUE?
regular
b) The language L={an|n is prime} is a) L1 is regular but not L2
regular b) L2 is regular but not L1
c) The language L ={w| w has 3k+1 c) Both L2 and L1 are regular
b’s for some k∈N with ={a,b}} is d) Neither L1 nor L2 are regular
regular [GATE-2014]
d) The language L={ww| w ∈ * with Q.68 The length of shortest string NOT in
={0,1}} is regular the language (over ={a,b}) of the
[GATE-2014] following regular expression
Q.64 Consider the finite automaton in the a*b*(ba)*a* is _______
following figure: [GATE-2014]
Q.69 The number of states in the minimal
deterministic finite automaton
corresponding to the regular
expression (0 + 1) * (10) is _______.
What is the set of reachable states for
the input string 0011? [GATE-2015]
a) {q0,q1,q2} b) {q0,q1}
Q.70 Consider the alphabet ∑ = {0,1}, the
c) {q0,q1,q2,q3} d) {q3}
null/empty string λ and the sets of
[GATE-2014]
strings X0, X1, and X2 generated by
Q.65 Which of the regular expressions the corresponding non-terminals of
given below represent the following a regular grammar X0, X1, and X2 are
DFA related as follows.
X0 = 1 X1
X1 = 0 X1 + 1 X2
X2 = 0 X1 + {λ}
Which one of the following choices
I) 0*1(1+00*1)* precisely represents the strings in
II) 0*1*1+11*0*1 X0?
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a) 10(0*+(10)*)1 b) {w a,b * w has equal number of
b) 10(0*+(10)*)*1 a’s and b’s }
c) 1(0*+10)*1
d) 10(0+10)*1+110(0+10)*1
c)
a n n 0 bn n 0
[GATE-2015] a b
n n
n0
Q.71 Let T be the language represented by d) a, b *
the regular expression Σ*0011Σ* [GATE-2016]
where Σ = {0, 1}. What is the
minimum number of states in a DFA Q.75 Which of the following decision
that recognizes L’ (complement of L)? problems are undecidable?
a) 4 b) 5 I. Given NFAs N1 & N 2 , is
c) 6 d) 8
L(N1 ) L N2 ?
[GATE-2015]
II. Given a CFG G = (N, Σ, P, S) and a
Q.72 string x * , does x L(G)?
III. Given CFGs G 1 and G 2 , is
L(G1 ) L(G2 )?
IV. Given a TM M, is L(M)
a) I and IV only b) II and III only
c) III and IV only d) II and IV only
[GATE-2016]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Which one of the following is TRUE? Q.82 Consider the following grammar over
a) Both P and Q are true the alphabet {a,b,c} given below, S
b) P is true and Q is false and T are non-terminals.
c) P is false and Q is true G1: S-->aSb|T
d) Both P and Q are false T--> cT|∈
[GATE-2016]
Q.79 Consider the following two statements: G2: S-->bSa|T
I. If all states of an NFA are T--> cT|∈
accepting states then the The language L1(G1) ∩ L2(G2).
language accepted by the NFA is a) Finite
b) Non-finite but Regular
Σ*.
II. There exists a regular language A c) Context Free but not Regular
such that for all languages B, A∩B d) Recursive but not Context-Free
is regular. [GATE-2017]
Which one of the following is correct?
a) Only I is true Q.83 If G is grammar with productions
b) Only II is true S → SaS | aSb | bSa | SS | ∈ where S is
c) Both I and II are true the start variable, then which one of
d) Both I and II are false the following is not generated by G?
[GATE-2016] a) abab
b) aaab
c) abbaa
Q.80 Consider the language L given by the d) babba
regular expression (a+b)*b(a +b) over [GATE-2017]
the alphabet {a, b}. The smallest
number of states needed in a
deterministic finite-state automaton
(DFA) accepting L is ______.
[GATE-2017]
mn >= 1 }
c) {(ab)n(cbm)n | n >= 1 }
d) {(ab)n(cbn)m | m, n >= 1 }
[GATE-2017]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
ANSWER KEY:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(d) (b) (d) (a) (c) (a) (b) (c) (a) (a) (c) (b) (b) (a) (a)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(b) (d) (b) (b) (d) (a) (a) (c) (b) (a) (d) (c) (c) (b) (c)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
(a) (b) (a) (d) (c) (b) (a) (a) (c) (c) (a) (a) (d) (a) (a)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
(c) (a) (c) (a) (c) (c) (b) (a) (b) (b) (c) (a) (b) (c) (d)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
(d) (a) (c) (a) (b) (a) (a) 3 3 (c) (b) 1 (a) (d) (c)
76 77 78 79 80 81 82 83
(b) 2 (c) (b) 4 (b) (b) (d)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
EXPLANATIONS
L4 0i i is an integer
2
C to A 10 00
Is context sensitive language (CSL)
(since the power is infinite and non Therefore, the finite state machine
outputs the sum of the present and
linear).
previous bits of the input.
Q.4 (a)
Q.7 (b)
Let’s consider both the statements
Even after changing non-final states
separately to find the correct option.
to final state and final state to non-
S1 :{02n | n 1|}
final state in NFA, still it accepts all
Applying the values of n, the strings with 0’s and 1’s.
S1 00,0000,000000,......
The behavior shown by the output is Q.8 (c)
regular and hence, the language is a The given bit pattern can be
regular language. represented as 1 _ _ 1 _ _ 1
S2 :{0m1n0mn | m 1 and n 1|} The four blanks can be filled in 2 4
Applying the values of m and n, =16 ways.
S2=0100,00110000, 000111000000, Therefore, there are 16 such strings
Here the values of m and n are kept in this pattern.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Not all of these are accepted by the In choice (c) the strings “a” and “b”
machine. cannot be generated separately since
The strings and its acceptance is as “ab” is always together.
follows Accepted So, choice (c) is not same as
1 0 0 1 0 0 1 √ (a + b + c)*.
1 0 0 1 0 1 1 √ Q.12 (b)
A,a A A aA
1 0 0 1 1 0 1 √
A,b B A bB
1 0 0 1 1 1 1 √ B,a B B aB
1 0 1 1 0 0 1 √ B,b A B bA
Since B is final state, so we need to
1 1 0 1 0 0 1 √ put
B . So the correct grammar is
1 1 1 1 0 0 1 √ choice (b) which is
{A aA, A bB, B aB,
Only these seven strings given above B bA,B }.
are accepted. All other strings in this
pattern are rejected. Q.13 (b)
Given regular expression is infinite
Q.9 (a) set (because of *) of finite strings. A
Given regular expression is 0*(10*)* regular expression cannot generate
A: (1*0)*1* any infinite string (Since string is
All strings that can be generated always finite in length by definition).
from given regular expression can
also be generated from this. Q.14 (a)
B: 0 + (0 + 10)* and Given language is finite. Hence it is
C: (0 + 1)* 10(0 + 1)* regular language.
We can generate 11 from given
regular expression which is not Q.15 (a)
possible with B and C. Writing Y and Z interms of incoming
C: (0 + 1)* 10(0 + 1)* arrows (Arden’s method), we get
Not possible as we can produce Y X0 Y0 Z1
{epsilon} from the given regular Z X0 Z1 Y0
expression but not from C. Clearly, Y =Z
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
So the language generated by the Q.21 (a)
grammar is the set of strings with a’s
such that number of a mod 3 is 2. So
the number of states required should
be 3 to maintain the count of number
of a’s mod 3. a b *a a b b.
Q.17 (d) Q.22 (a)
If L is regular⟹L satisfies the The given right-linear grammar can
pumping lemma for regular languages . be converted to the following DFA.
If L is CFL ⟹ L satisfies the pumping
lemma for CFLs.
By satisfying pumping lemma, we
can never say that a language is
regular or CFL. It can only be used to
prove that a certain language is not
regular or not CFL in case the The machine accepts all strings over
language violates the corresponding the alphabet {a,b} which have an
pumping lemma. So, both regular and even number of a’s . It is a minimal
non-regular languages can satisfy DFA. So, Myhill-Nerode equivalence
pumping lemma for regular language. classes for the language is nothing
Similarly, both CFLs and non-CFLs but the set of strings reaching S and
can satisfy pumping lemma for CFLs. A respectively.
So satisfying pumping lemma doesn’t
prove anything about the type of
S w a b * #a w is even
language. A w a b * # w is odd
a
Q.18 (b)
a is followed by two or more than 2 Q.23 (c)
b's so the language recognized by M a) Every language has a regular
is {W∈{a, b}*| every a followed by superset: True. * is such a superset.
b) Every language has a regular
atleast 2 b’s}.
subset:
True. Φ is such a subset.
Q.19 (b)
c) Every subset of a regular language
is regular. False a n bn *, but a n bn
is not Regular.
d) Every subset of a finite language is
regular. True. Every subset of a finite
The given machine, executes the set must be finite by definition. Every
algorithm for 2’s complement when finite set is regular. Hence, every
input is given from LSB. subset of a finite language is regular.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.25 (a) Option (d)
Option (A): If L a b *, then L {s (0 1)*| n 0 (s) mod 7=n1 (s) mod 5=0}
repeat (L) = ww w a b * is It is a regular language.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
language Lean be expressed as x z *y y z
r [0(0 1)*0] [1(0 1)*1]
G1 generates every string in which “
and follows the above convention,
no y appears before any x”.
therefore is regular.
G2 : S y z yS zS xB
Q.31 (a) B y yS
It is given that the 0 ’s and 1’s are Substitute B in S to get
divisible by 3 and 5 and we know
S y z yS zS xy xyS
that 3 and 5 do not have any factor
other than themselves or 1 i.e., these Now solution of S is
cannot be further breakdown. S y z xy *S
Therefore, number of states S y z xy * y z xy
=3×5 =15
So L G2 S y z xy
The schematic representation is as
follows: G2 generates every string in which
“every x followed by atleast one y” .
Q.34 (d)
Given DFA can be redesigned as S0
asq00, S1 as q10, S2 as q11, S3 as
q01.
Each state is
qab a na mod 2, b = n b mod 2 .
Q.32 (b) q00 as n a mod 2 = 0, n b mod 2 0
Finite subset of non-regular set is [Number of x is ever, number of y is
regular as we know that Pumping even].
Lemma can be applied on all the
finite sets that state that all finite sets
are regular.
Infinite union of finite set is not
regular because regular sets can
never be closed under infinite union.
Q.33 (a)
G1: S x z xS zS yB q01 is final state mean where
B y z yB zB number of x is even and number of
y is odd. q10 if final state mean
B y z
where number of x is odd and
Substitute in s to get number of y is even.
S x z xS zS y y z
Q.35 (c)
Now solution o f S is This grammar cannot generate any
S x z *S string starting with xx or ending with
S x z * x z y y z
xx so (i), (ii) and (v) cannot be
generated by the grammar. xyx also
So L(G1) S x z
cannot be generated by the
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
grammar. The derivation for (iii)
xyxy and (iv) yxxy is shown below.
S xB xyS xyxB xyxy
S yA yxS yxxS yxxy
So only (iii) and (iv) can we derived
from this grammar.
Q.36 (b)
L(P)∩L(Q) must contain all strings Which is equivalent Transition graph
common to P and Q. Note that `aa’ is [by removing transition from q1 to
common to both P and Q and hence q2 and q2 to q1 but does not effect on
must be accepted by any FA language]
accepting L(P)∩L(Q). However, all of
the given machine reject ‘aa’.
Therefore option (e) i.e. none of
these is the right answer.
Q.37 (a)
The language of the given regular
expression R is ‘containing the
substring aa or bb’. Option (a) is the That is equivalent to:
correct machine for this language.
Q.38 (a)
In option (a) S3 and S4 together act
as a permanent accept and can
therefore be collapsed into a single Which is equivalent to:
permanent accept state as shown
below.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.41 (a) even number of b’s. This can be
A state in a DFA will be a subset of the accepted by DFA. So it is regular.
set of states of the equivalent NFA. 2. There is a relation between
So, the maximum number of states in number of a’s and b’s which can be
the equivalent DFA of an NFA, will be solved by stack. So this is CFL.
2n , where n is the number of states in 3. There is a relation between
NFA, as a set with n elements has number of a’s and b’s which can be
maximum 2n subsets. solved by stack. So this is CFL.
So, number of states in equivalent 4. The given language is set of strings
minimal DFA ≤ number of states in having c in it. There exists DFA to
equivalent DFA ≤ 2n . accept all such strings. So it is
regular.
Q.42 (a)
Q.46 (c)
Interchanging final and non-final
states of DFA is used for The correct sequence is given as
follows:
complementation. P. 1.
Given D FA generates all strings end
with ab. Complement of DFA accepts 0(01*1 00)*01*
all strings do not end with ab.
Complement of given DFA is :
R. 2.
0(10*1 00)*0
It accepts all strings that do no end
with ab.
Q.43 (d)
L1 is regular, since 10000 is finite.
L3 is also regular (mod machine, Q. 3.
since finite number of residue
0(10*110)*1
combinations). L2 w w w R
which is the Palindrome language
which is known to be non regular.
Q.44 (a)
S. 4.
M1 is a DFA accepting all string
containing 2 consecutive 1’s 0(10*110)*10*
(containing the substring `11’).M2 is
a NFA accepting the same language.
Containing 2consecutive 1’s.
So, L1 = L2.
Q.45 (a)
1. There is no comparison between
number of a’s and b’s. We must have
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.47 (a) Therefore, the above DFA ends with
Given: Transition table for Y and Z 00.
The number of states of Z = 2
The number of states of Y = 2 Q.49 (a)
ZxY The initial state =00
Final state required =01
Let us construct the transition
diagram for the given.
R(F) Q P
S Q P
Table for Z x Y is
a B There can be 4 states 00, 01, 10, 11.
With this, the FSM can be designed as
→(1,2) (2,1) (2,2) the desired output is obtained with
the input string 101, however the
(1,2) (2,2) (2,1) concern is number of states which
we found to be 3.
(2,1) (1,1) (1,2)
Q.50 (c)
F(2,2) (1,2) (1,1) We have given the relation
(0 + 1)* 0(0 + 1)* 0(0 + 1)*
Here, the accepting languages are
Q.48 (c) L={00, 000, 100, 001, 010, 0000,
0001, 1000, 1001, 0100, 1100, 0010,
0011, 0110, 0101, 1010,…}
The common feature in the accepting
languages can be seen that they
consist of atleast two 0’s.
State Input Output
Q.51 (c)
q0 to q0 1, 0 00 The length of W is not defined. It is
given as n so let us take an example.
Q1 to q0 1, 0 00 Consider the length of W be 2.
Let W =01
Q2 to q0 1, 0 00 The sub-strings thus formed are 0, 1
and 01.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
The number of states required by Q.58 (b)
NFA as compared to the string will
give us the minimum number of
states in the NFA accepting L.
The automaton for the above is
Language for NFA L= a +
Now L * L
⟹ L a * a
Here the minimum number of states ⟹ L
required is 3 which is 1 greater than
the string of length 2. Therefore, n + Q.59 (c)
1 are the desired solution. L ab,aa,baa
Q.52 (b) The breakdown of the strings 1,2,4 in
It is given that L is the set of all bit terms of ab, aa and baa is shown
strings with even number of 1's, so below:
the regular expression should 1. a baa baa ab aa
exhibit the same. 2. aa aab aa aa
Now, the min string should be s and 3. baa aa a baa
the string should be e, 0, 11, 101... String no (3) has no breakdown in
The string obtained from such terms of strings in L and hence string
expression is 0* (10*10*)* (3) does not belong to L*. Only 1, 2
and 4 belongs to L*.
Q.53 (a)
As state (s) and (t) both are final Q.60 (d)
states and accepting a* + b*, we can Notice that the state names are given
combine both states and we will get based on ending bits of the string,
which has been processed.
The are from 00 labeled “0” should
go to trap state q (since at most 2
zeros are allowed in any substring).
Based on this fact, option (a) and (b)
are incorrect Between option (c) and
Q.54 (b) (d), if you look at arc labeled “I” from
As n is constant at least n + 1 states state 01, this arc should go to state 11
will be required to design a nk since the string at this point is ending
with 11. So option (c) is wrong and
Q.55 (b) option (d) is correct.
DPDA and NPDA because an NPDA The dfa corresponding to correct
cannot be converted into DPDA. option (d) is correct.
The dfa corresponding to correct
Q.56 (c)
option (d) is shown below with
*- P as *- P is the complement of P
missing arrows shown in dotted
and complement of regular language lines.
is also regular.
Q.57 (a)
Lexical analysis only requires the
power of FA.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
But s' is an empty language
,L
{} L* for all languages L.
As it indicates taking letters from the
language and concatenating them ‘0’
length string which is possible for all
languages.
is in *
L1.L2
Q.61 (d)
And L*1 {}
L1.L2 * L*1 (L1.L2 ) L*1
{} {}
Hence, the answer is option (a) = {𝛆}
Q.63 (c)
1. Element of L(A) is context free – Only for C we can build the finite
true As there exist a DFA, L(A) is automata
regular. Regular languages are
closed under complement. Q.64 (a)
∴ Complement of L(A) is regular The given automaton is NFA and
and therefore context free. clearly the states q 0, q1, q2 can be
2. reached with the input string 0011.
L(A) L((11*0 0)(0 1)*0*1*) true
AS L(A) L((11*0 0)(0 1)*) is Q.65 (b)
I and III are the expressions for DFA.
Equivalent to
But II is not representing the given
L((11*0 0)(0 1)*0*1*) For the
DFA as it accepts strings like 11011
language accepted by A, which is not accepted by regular
A is minimal DFA – false expression.
Minimal DFA
Q.66 (a)
Both L1 and L2 are regular. The
concatenation of two regular
3. A accepts all strings over {0, languages is regular.
1} of length at least 2 – false. But L1.L2 ={ambn | m, n>=0}
The given DFA A accepts the
string “0” Ans (d) 3 and 4 only Q.67 (a)
false. L1 is regular let us consider the
string 011011011011 In this string,
Q.62 (a) number of occurrences of 011 are 4
but when we see here 110 is also
Considering the languages L1
occurred and the number of
and L2 {a} for all languages L it is occurrence of 110 is 3. Note that if i
known that ∅. L =∅ add a 0 at the last of string we can
Suppose, ∃α string s . L ∃s’ Such have same number of occurrences of
that s=s’ s” 011 and 110 so this string is
And s' s" L accepted. We can say if the string is
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
ending with 011 so by appending a 0
we can make 110 also. Now string2 :
110110110110 in this number of
occurrences of 110 is 4 and 011 is 3
which already satisfy the condition
So we can observe here that Q.72
whenever 110 will be there string L M a b *a (strings ending with a)
will be accepted So with this idea we L(N) a b *b (strings ending with b)
can build an automata for this.
Therefore, it is regular.
L(M) L(N) (nothing in common)
∴ Number of states = 1
Q.68 (3)
Length 0 string is present as it
accepts epsilon, all length 1 strings Minimal DFA which accepts empty
are present (a,b) and also length two language.
string aa, ab, ba, bb are present, But
'bab ' is not present. So length of string Q.73 (a)
not accepted is 3.
L1 wxw R w, x a, b *and w , x 0
Q.69 (3) w cannot be put as ``ϵ” since w 0 .
The corresponding DFA is So we put w as its smallest string
which is `a’ and `b’and get the
regular expression:
r a a b a b(a b) b .
= 11 [Replacing X2 with λ]
So the given language
The string "11" is only possible with
a a b a b(a b) b which is
option (c)
clearly regular.
Q.71 (b) ∴ L1 is regular.
In regular language, DFA containing
sub-string of length n contains n+1
L2 a n bm m n . This language has
state. Complement of that DFA also infinite comparisons between
contain n+1 state. number of a’s and b’s . L 2 is not
DFA for the language is regular language.
L3 : a pbqcr p,q,r 0 a *b*c* is a
regular language.
Q.74 (d)
Following is the DFA for complement
of L which again contains 5 states. G: G :S aS bS
L(G) a, b *.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.75 (c) Q.77 (2)
I. Disjointedness problem of R.e (0+1)*(0+1)(0+1)*
regular = Decidable The number of states in minimal DFA
II. Membership of CFL’s = Decidable is 2
III. Equivalence of CFL’s =
Undecidable
IV. Emptiness of RE language’s =
Undecidable
So, III and IV only is correct answer. Q.78 (c)
L1: S1 → aS1 b | ε
Q.76 (b) L2: S2 → abS2 | ε
Option A represents those strings L1: {an bn | n > 0} → CFL
which either have 0011 or 1100 as L2: (ab)* → RL
substring. P is false and Q is true
Option C represents those strings
which either have 00 or 11 as Q.79 (b)
substring. I is true because consider the empty
Option D represents those strings lnguage which is regular. And its
which start with 11 and end with 00 intersection with any language is
or start with 00 and end with 11. regular. I is false because, if we do not
Option B represents those strings define the transition for an input ‘a’
having two consecutive 0s and two at a particular state but the next
consecutive 1s. character in string is ‘a’, then it
cannot be accepted by that NFA.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
2 CONTEXT-FREE GRAMMARS AND PUSHDOWN
AUTOMATA
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
10. L = {x | na(x) = nb(x) , Σ = {a,b}}
S → aSb | bSa | SS | ^ E → E+E
→ E+E*E
2.2 DERIVATION, PARSE TREE AND → E+E*id
AMBIGUITY → E+id*id
→ id+id*id
The right most non-terminal (underline)
Derivation:
gets replaced every time by one of right side
The process of deriving a string from the of its production.
starting non-terminal is called a derivation.
Here, E+E, E+E*E, E+E*id, E+id*id, id+id*id
Derivation can be of two types: are called right sentential forms – in general
Left Most Derivation: In the process of sentential forms.
derivation every time if left most non-
Parse Tree/ Derivation Tree:
terminal gets replaced by one of right side of Pictorial representation of derivation is
its production then it is called left most called parse tree.
derivation. Root Node: Starting non-terminal
Internal Nodes: Non-Terminals
Example: Leaf Nodes: Terminals
Consider the grammar E → E+E | E*E| id
Example: Parse tree for id+id*id is as
Left most derivation for the string id+id*id below.
is as follows:
E → E+E
→ id+E
→ id+E*E
→ id+id*E
→ id+id*id
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Because there exist more than one different Left Factoring:
parse tree for the string id+id*id which are A grammar is said to be left factored when it
shown below. is of the form :
A → αβ1 | αβ2 | αβ3 | …… | αβn | γ i.e the
productions start with the same terminal
(or set of terminals).
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
occurs in the grammar. [x is Terminal, x can Solution
be Null] (1) Since S appears in R.H.S, we add a new
Step 2 − Delete A → B from the grammar. state S0 and S0→S is added to the
Step 3 − Repeat from step 1 until all unit production set and it becomes −
productions are removed. S0→S, S→ ASA | aB, A → B | S, B → b | ε
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Hence we will apply step 4 and step 5 to get Step 3 − Remove unit productions. (Using
the following final production set which is in the Unit production removal algorithm
CNF − discussed earlier)
Step 2 − Remove Null productions. (Using Note: If G is a in GNF, then for any string w
the Null production removal algorithm belongs L(G) of length n ≥ 1, it
discussed earlier) requires exactly n steps to make any
derivation of w.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
2.4 PUSHDOWN AUTOMATA (PDA) As shown in figure, a PDA has three
components: an input tape with read only
Regular language can be characterized as head, a finite control and a pushdown store.
the language accepted by finite automata. The input head is read-only and may only
Similarly, we can characterize the context- move from left to right, one symbol (or cell)
free language as the language accepted by a at a time. In each step, the PDA pops the top
class of machines called "Pushdown symbol off the stack; based on this symbol,
Automata" (PDA). A pushdown automation the input symbol it is currently reading, and
is an extension of the NFA. It is observed its present state, it can push a sequence of
that FA have limited capability. (in the sense symbols onto the stack, move its read-only
that the class of languages accepted or head one cell (or symbol) to the right, and
characterized by them is small). This is due enter a new state, as defined by the
to the "finite memory" (number of states) transition rules of the PDA. PDA are
and "no external memory" involved with nondeterministic, by default. That is, ∈-
them. A PDA is simply an NFA augmented transitions are also allowed in which the
with an "external stack memory". The PDA can pop and push, and change state
addition of a stack provides the PDA with a without reading the next input symbol or
last-in, first-out memory management moving its read-only head. Besides this,
capability. This "Stack" or "pushdown store" there may be multiple options for possible
can be used to record a potentially next moves.
unbounded information. It is due to this
memory management capability with the Formal Definitions
help of the stack that a PDA can overcome
the memory limitations that prevents a FA Formally, a PDA M is a 7-tuple
to accept many interesting languages like M =(Q,∑, Γ, δ, q0, z0, F )
a n bn | n 0 . Although, a PDA can store an where,
Qis a finite set of states,
unbounded amount of information on the
∑is a finite set of input symbols (input
stack, its access to the information on the
alphabets),
stack is limited. It can push an element onto
Γ is a finite set of stack symbols (stack
the top of the stack and pop off an element alphabets),
from the top of the stack. To read down into
δ is a transition function from
the stack the top elements must be popped
Q to subset of Q
off and are lost. Due to this limited access to
the information on the stack, a PDA still has q0 Q is the start state
some limitations and cannot accept some z0 , is the initial stack symbol, and, F
other interesting languages.
is the final or accept states.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
go to state p1 entire input, starting in the start
pop z off the stack configuration on input x.
push 1 onto the stack (where 1 * )
2. Acceptance by empty stack (or Null
(The usual convention is that if stack)
1 X1X2 ...Xk , then X1 will be at the top The PDA M accepts its input x by empty
and X k at the bottom.) stack if starting in the start configuration on
move read head right one cell past the input x , it ever empties the stack w/o
current symbol a. If a = , then pushing anything back on after reading the
(q,, z) {(p1 , 1 ),(p2 , 2 ),...(pk , k )} entire input.
Note that the set of final states, F is
means institutively that whenever the
irrelevant in this case and we usually let the
PDA is in state q with z on the top of the
stack regardless of the current input F to be the empty set i.e. F = ∅ .
symbol, it can non deterministically for
Following is the PDA for language L = {a nbn |
any i, 1 i k ,
go to state pi n>=0}
pop z off the stack
1. (q1 ,a, z) {(q 2 ,az)}
push i onto the stack, and
leave its read-only head where it is. 2. (q 2 ,a,a) {(q 2 ,aa)}
3. (q2 , b,a) {(q3 ,)}
State Transition Diagram 4. (q3 , b,a) {(q3 ,)}
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a from the top of the stack and enters in More Examples:
state q3 (to remember that the comparison L1 = {wcwr|w∈{a,b}*}
process has begun). On state q3 , it expects
only b's in the input (if it sees any more a in Sr State I/P Stack Move
the input thus the input will not be in the 1 qo a z0 (qo,az0)
proper form of a nbn). Hence there is no more 2 qo b z0 (qo,bz0)
on input a when it is in state q3 . On state q3 3 qo a a (qo,aa)
it pops off an a from the top of the stack for 4 qo b a (qo,ba)
every b in the input. When it sees the last b
5 qo a b (qo,ab)
on state q3 (i.e. when the input is
exhausted), then the last a from the stack 6 qo b b (qo,bb)
will be popped off and the start symbol z is 7 qo c z0 (q1 ,z0)
exposed. This is the only possible case when 8 qo c a (q1 ,a)
the input (i.e. on ∈ -input ) the PDA M will 9 qo c b (q1 ,b)
move to state q4 which is an accept state. 10 q1 a a (q1 ,^)
we can show the computation of the PDA on 11 q1 b b (q1 ,^)
a given input using the IDs and next move 12 q1 ^ z0 (q2 ,z0)
relations. For example, following are the
computation on two input strings.
Let the input be aabb. We start with the start
configuration and proceed to the
subsequent IDs using the transition function
defined
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Sr State I/P Stack Move
1 qo [ z0 (q1, [z0) Power of DPDA and NPDA in terms of
2 q1 [ [ (q1, [[) language acceptance:
For every CFL there exist a non-
3 q1 ] [ (q1, ^)
deterministic PDA or simply PDA. But for
4 q1 ^ z0 (q1, z0)
every CFL deterministic PDA does not exist.
It means there are few CFL for which DPDA
2.5 DETERMINISTIC AND can’t be constructed but NPDA can be.
NON-DETERMINISTIC PDA
For example:
Deterministic Moves/Choices: L = {x | x is Palindrome String over {a,b}*}
Deterministic PDA (DPDA): Step 3 − The start symbol of CFG will be the
If all moves in PDA are deterministic then it start symbol in the PDA.
is called deterministic PDA.
Step 4 − All non-terminals of the CFG will be
Non-Deterministic PDA (NPDA): the stack symbols of the PDA and all the
If any move of PDA is non-deterministic terminals of the CFG will be the input
then it is called non-deterministic PDA. symbols of the PDA.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Example: L = {x ∈ {a, b, c}∗ | na(x) = min
Construct a PDA from the following CFG. {nb(x), nc(x)}}
G = ({S, X}, {a, b}, P, S) where the productions {anbmanbn+m | m, n ≥ 0}
are −
S → XS | ε , A → aXb | Ab | ab
Deterministic Context Free Language
Solution (DCFL)
Let the equivalent PDA, A CFL is said to be DCFL if there exist DPDA
P = ({q}, {a, b}, {a, b, X, S}, δ, q, S) which accepts it.
where δ −
δ(q, ε , S) = {(q, XS), (q, ε )} 2.8 CLOSURE PROPERTIES OF CFL
δ(q, ε , X) = {(q, aXb), (q, Xb), (q, ab)}
δ(q, a, a) = {(q, ε )} Context-free languages are closed under
δ(q, 1, 1) = {(q, ε )} union, concatenation, and Kleene star but
not under intersection and
complementation.
2.7 CONTEXT FREE LANGUAGES
A language is said to be context free if there
Suppose G1 = (V1, Σ1, R1, S1) and G2 = (V2,
exist a PDA which accepts it.
Σ2, R2, S2).
Informally, PDA can remember one
Example: For G1 we have S 1 → aS1b, S1 → ^.
condition/comparison but it can’t
For G2 we have S2 → c S2d, S2 → ^.
remember more than one conditions
Then L(G1) = {anbn : n ≥ 0}.
simultaneously.
Also, L(G2) = {cndn : n ≥ 0}
For example:
Union:
L = {aibjck | i = j or j = k } is context free but L
G = (V1 ∪ V2 ∪ {S}, Σ1 ∪ Σ2, R, S) where
= {aibjck | i = j and j = k} is not context free.
R = R1 ∪ R2 ∪ {S → S1, S → S2} and S is a new
symbol.
Following is the list of context free
Then L(G) = L(G1) ∪ L(G2).
languages:
Example:
{x ∈ {a, b}∗ | na(x) < nb(x)}
S1 → a S1b, S1 → ^. S2 → c S2d S2 → ^.
{x ∈ {a, b}∗ | na(x) ≠ nb(x)} S → S1 | S2
{x ∈ {a, b}∗ | na(x) = 2nb(x)} Then L(G) = {an bn : n ≥ 0} ∪ {cndn : n ≥ 0}.
{anbn+mam | n,m ≥ 0}
The set of even-length palindromes Concatenation
over {a, b} G = (V1 ∪ V2 ∪ {S}, Σ1 ∪ Σ2, R, S) where
The set of odd-length palindromes R = R1 ∪ R2 ∪ {S → S1S2} and S is a new
over {a, b} symbol. Example:
{x ∈ {a, b}∗ | na(x) = nb(x)} S1 → aS1b, S1 → ^. S2 → c S2d S2 → ^.
{x ∈ {0, 1}∗ | na(x) = 2nb(x)} S → S1S2
Then L(G) = {ambmcndn : m, n ≥ 0}.
Following is the list of non context free
languages: Kleene Star
L = {aibjck | i < j <k} G = (V1 ∪ {S}, Σ1, R, S) where R = R1 ∪ {S →
L = {x ∈ {a, b}∗ | nb(x) = na(x)2 ^, S → SS1} and S is a new symbol.
L = {anb2nan | n ≥ 0} Example:
L = {x ∈ {a, b, c}∗ | na(x) = max S1 → aS1b S1 → ^.
{nb(x), nc(x)}} S → ^, S → SS1
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Then L(G) = {anbn : n ≥ 0}∗ .
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
GATE QUESTIONS
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.7 The language {a m bn cm n | m, n 1} is [GATE-2005 (IT)]
a) regular
b) context-free but not regular Q.10 Consider the languages :
c) Context-sensitive but not L1 {WWR | W 0, 1 *}
context-free L2 {W # WR | W 0,1)* where #
d) type-0 but not context-sensitive is a special symbol
[GATE-2004]
L3 {WW | W0, 1*} Which one
Q.8 Let L be a regular language and M be of the following is true?
a context-free language, both over a) L1 is a deterministic CFL
the alphabet . Let Lc and Mc b) L 2 is a deterministic CFL
denote the complements of L and M
respectively. c) L 3 is a CFI but not a deterministic
Which of the following statements CFL
about the language Lc Mc is TRUE? d) L 3 is a deterministic CFL
a) It is necessarily regular but not [GATE-2005]
necessarily context-free.
b) It is necessarily context-free. Q.11 Consider the languages :
c) It is necessarily non-regular. L1 a n bncm | n, m 0 and L2 a n bmcm | n, m 0
d) None of the above Which one of the following
[GATE-2005 (IT)] statements is false?
Q.9 Let P be a non-deterministic push- a) L1 L2 is a context-free language
down automation (N PDA) with b) L1 L2 is a context-free language
exactly one state, q, and exactly one c) L1 and L2 arecontext-free
symbol, Z, in its stack alphabet. State
languages
q is both the starting as well as the
d) L1 L2 is a context-sensitive
accepting state of the PDA. The stack
is initialized with one Z before the language
start of the operation of the PDA. Let [GATE-2005]
the input alphabet of the PDA be .
Let L P be the language accepted Q.12 Let Nf and Np , denote the classes of
by the PDA by reading a string and languages accepted by non-
reaching its accepting state. Let deterministic finite automata and
non - deterministic push - down
N P be the language accepted by
automata, respectively. Let D f and
the PDA by reading a string and
emptying its stack. Dp denote the classes of languages
Which of the following statements is accepted by deterministic finite
TRUE? automata and deterministic push-
a) L P is necessarily Σ* but down automata respectively.
Which one of the following is true?
N P is not necessarily Σ* .
a) Df Nf and Dp Np
b) N P is necessarily Σ* but
b) Df Nf and Dp Np
L P is not necessarily Σ* c) Df Nf and Dp Np
c) Both L P & N P is necessarily Σ *
d) Df Nf and Dp Np
d) Neither L P nor N P are [GATE-2005]
necessarily Σ* .
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.13 In the context-free grammar below, S after propping the top of stack and
is the start symbol, a and b are pushing the symbols Z 0 and X (in
terminals, and denotes the empty that order) on the stack.
string S aSa bSb a b s,a, Z0 s, XXZ0
Which of the following string is NOT
generated by the grammar?
s, , Z0 f ,
a) aaaa b) baba s,a, X s, XXX
c) abba d) babaaabab s, b, X t,
[GATE-2006 (IT)]
t, b, X t,
Q.14 Which of the following languages is t,c, X u,
accepted by a non-deterministic u,c, X u,
pushdown automaton (PDA) but
NOT by deterministic PDA? u, , Z0 f ,
a) a n bn cn n 0 The language accepted by the PDA is
b) a b c l m or m n
1 m n
a) a1bmcn l m = n
b) a b c
1 m n
lm
c) a b n 0
n n
c) a b c
1 m n
2 lm+n
d) a b m,n 0
m n
[GATE-2006 (IT)] d) a b c
1 m n
m=n
[GATE-2006 (IT)]
Q.15 Let L be a context-free language and
M a regular language. Then the Q.17 In the context-free grammar below, S
language L M is is the start symbol, a and b are
a) always regular terminal, and ε denotes the empty
b) never regular string.
c) always a deterministic context- S aSAb
free language A bA
d) always a context-free language
[GATE-2006 (IT)] The grammar generates the language
a) a b *b *
b) a mbn m n
Q.16 Consider the pushdown automaton
(PDA) below which runs over the
c) a mbn m n d) a*b*
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
G {S SS,S ab,S ba,S } Q.22 The language L 0i 21i i 0 over
1. G is ambiguous. the alphabet {0, 1, 2) s
2. G produces all strings with equal a) not recursive
number of a's and b's b) is recursive & is a deterministic CFL
3. G can be accepted by a c) is a regular language
deterministic PDA. d) is not a deterministic CFL but a
Which combination below expresses CFL
all the true statements about G? [GATE-2007(IT)]
a) 1 only b) 1 and 3
c) 2 and 3 d) 1, 2 and 3 Q.23 Which of the following problems is
[GATE-2006] undecidable?
a) Membership problem for CFGs
Q.20 Consider an ambiguous grammar G b) Ambiguity problem for CFGs
and its disambiguated version D. Let c) Finiteness problem for FSAs
the languages recognized by the two d) Equivalence problem for FSAs
grammars be denoted b y L(G) and [GATE-2007]
L(D)respectively. Which one of the
Q.24 Consider the following languages.
following is true?
a) L(D) L(G) b) L(D) L(G)
L1 ai b jck i j, k 1
c) L(D) L(G) d) L(D) is empty L2 a bi j
j 2i, i 0
[GATE-2007] Which of the following if true?
Q.21 Consider the following grammars, a) L1 is not a CFL but L 2 is
Names representing terminals have b) L1 L2 and L1 is non-regular
been specified in capital letters. c) L1 L2 is not a CFL but L 2 is
G1: stmnt WHILE expr stmnt d) There is a 4 state PDA that accepts
stmnt OTHER L1 , but there is no DPDA that
expr ID accepts L 2
G2: stmnt WHILE expr stmnt [GATE-2008(IT)]
stmnt OTHER
expr expr expr Q.25 Consider CFG with the following
expr exper * expr productions.
S AA B
expr expr * expr
expr ID A 0A A0 1
Which one of the following B 0B00 1
statements is true? S is the start symbol, A and B are
a) G 1 is context-free but not regular non-terminals and 0 and 1 are the
and G 2 is regular terminals. The language generated
b) G 2 is context-free b ut not by this grammar is
regular and G 1
a) 0n102n n 1
c) Both G 1 and G 2 are regular b)
d) Both G 1 and G 2 are context-free
0i 10j 10k i, j,k 0 0n102n n 1 c)
but neither of them is regular 0 10
i j
i, j, 0 0n102n n 1
[GATE-2007(IT)] d) The set of all strings over {0, 1}
containing at least two 0’s
[GATE-2008(IT)]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Directions for Question Q.26 to Q.27: Q.30 Match List I with List II and select
A CFG G is given with the following the correct answer using the codes
productions where S is the start symbol, A is a given below the lists
non-terminal and a and b are terminals. List I List II
S aS A
E. Checking that P.L {anbmcndm | n 1, m 1|}
A aAb bAa identifiers are
declared before thei r
Q.26 Which of the following strings is use
generated by the grammar above?
a) aabbaba b) aabaaba F. number of formal Q.
c) abababb d) aabbaab parameters in the X XbX XcX dXf | g
[GATE-2008(IT)] declaration of function
agrees with the
Q.27 For the correct answer in above number of actual
Question, how many steps are parameters in use of
that function
required to derive the string and
how many parse trees are there? G.Arithmetic R.L={WcW | W∈ (a|b)*}
a) 6 and 1 b) 6 and 2 expressions with
c) 7 and 2 d) 4 and 2 matched pairs of
[GATE-2008(IT)] parameters
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a) 1, 2, 3 & 4 b) 2, 3 & 4 string which will take the machine to
c) 1, 3 & 4 d) 1, 2 & 4 the state A =0, B =1 with Output =1?
[GATE-2008] a) 3 b) 4
c) 5 d) 6
Q.32 Which of the following statements is [GATE-2009]
false? Q.35 Let L1 L1 L2 , where L 1 and L 2 are
a) Every NFA can be converted to an languages as defined below
equivalent DFA L1 {a mbmc a n bn | m, n 0}
b) Every non-deterministic Turing
machine can be converted to an L2 {ai b jck | i, j,k 0}
equivalent deterministic Wring Then L is
machine a) not recursive
c) Every regular language is also a b) regular
context-free language c) context-free but not regular
d) Every subset of a recursively d) recursively enumerable but not
enumerable set is recursive context-free
[GATE-2008] [GATE-2009]
Q.33 Which one of the following is FALSE? Q.36 Match all items in List I with correct
a) There is a unique minimal DFA options from those given in List II.
for every regular language List-I List-II
b) Every NFA can be converted to an
P. Regular expression 1. Syntax analysis
equivalent PDA
c) Complement of every context- Q. Push-down 2. Code
free language is recursive automata generation
d) Every nondeterministic PDA can
be converted to an equivalent R. Dataflow analysis 3. Lexical
deterministic PDA analysis
[GATE-2009]
S. Register allocation 4. Code
Q.34 Given the following state table of an optimization
FSM with two states A and B, one
input and one output: a) P-4, Q-1, R-2, S-3
b) P-3, Q-1, R-4, S-2
Present Present Input Next Next Output c) P-3, Q-4, R-1, S-2
State A State B State A Stat B d) P-2, Q-1, R-4, S-3
0 0 0 0 0 1
[GATE-2009]
0 1 0 1 0 0
Q.37 Which one of the following is false?
1 0 0 0 1 0 a) There is unique minimal DFA for
1 1 0 1 0 0 every regular language
0 0 1 0 1 0 b) Every NFA can be converted to an
0 1 1 0 0 1 equivalent PDA.
c) Complement of every context-
1 0 1 0 1 1
free language is recursive
1 1 1 0 0 1 d) Every non-deterministic PDA can
be converted to an equivalent
If the initial state is A = 0, B = 0, what deterministic PDA
is the minimum length of an input [GATE-2009]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.38 S→aSa|bSb|a|b; the language Q.42 Consider the following languages
generated by the above grammar over the alphabet ∑={0,1,c}
over the alphabet {a, b} is the set of L1 ={0n1n∣ n ≥ 0}
a) All palindromes L2 ={wcwr | w∈ {0,1}*}
b) All odd length palindromes L3 = {wwr | w∈ {0,1}*}
c) Strings that begin and end with Here, wr is the reverse of the string
the same symbol w. Which of these languages are
d) All even length palindromes deterministic context free
[GATE-2009] languages?
a) None of the languages
Q.39 Consider the languages L 1 = {0i1j | i b) Only L1
<> j}, L 2 = {0i1j | i = j}, L3 = {0i1j | i = 2j
c) Only L1 and L2
+1}, L 4 = {0i1j | i 2j}. Which one of d) All the three languages
the following statements is true? [GATE-2014]
a) Only L 2 is context-free
b) L2 and L 3 are Context-free Q.43 Consider the NPDA
c) L1 and L 2 are context-free Q q0 ,q1,q2 , 0,1 , Γ =
d) All are context-free 0,1, , ,q0 , , F q2 , where (as
[GATE-2010]
per usual convention)Q is the set of
Q.40 Consider the languages L 1, L2 and L 3 states, Σ is the input alphabet, Γ is
as given below stack alphabet, δ is the state
L1 = {0p1q | p, q N} transition function, 𝑞0 is the initial
L2 = {0p 1q | p, q N and p= q} and state, ⊥ is the initial stack symbol,
and F is the set of accepting states,
L3 = {Op1q0r|p, q r N and p=q=r}
The state transition is as follows:
Which of the following statements is
not true?
a) Push Down Automata (PDA) can
be used to recognize L 1 and L 2
b) L1 is a regular language
c) All the three languages are
context-free Which one of the following
d) Turing machines can be used to
sequences must follow the string
recognize all the languages 101100 so that the overall string is
[GATE-2011] accepted by the automaton?
Q.41 Consider the following languages. (a) 10110 (b) 10010
L1 {0p1q0r | p,q,r 0} (c) 01010 (d) 01001
[GATE-2015(1)]
L2 = {0p1q0r | p,q,r >=0 and p ≠ r}
Which one of the following
Q.44 Which of the following languages are
statements is false?
context-free?
a) L2 is context-free
L1 = {ambnanbm | m,n>=1}
b) L1 L2 is context-free L2 = {ambnambn | m,n>=1}
c) Complement of L 2 is recursive L3 = {ambn | m = 2n+1}
d) Complement of L 1 is context-free a) L1 and L2 only
but not regular b) L1 and L3 only
[GATE-2013] c) L2 and L3 only
d) L3 only
[GATE-2015]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.45 Language L1 is defined by the denote the language accepted by the
grammar: PDA.
S1 aS1b
Language L 2 is defined by the
grammar:
S2 abS2
Consider the following statements: Which one of the following is TRUE?
P : L1 is regular a) L ={anbn | n ≥ 0} and is not
Q : L2 is regular accepted by any finite automata
Which one of the following is TRUE? b) L {an|n ≥ 0} ∪ {anbn |n≥0} and is
a) Both P and Q are true not accepted by any
b) P is true and Q is false deterministic PDA
c) P is false and Q is true c) L is not accepted by any Turning
d) Both P and Q are false machine that halts on every input
[GATE-2016(2)] d) L {an | n ≥ 0} ∪ {anbn | n ≥ 0} and
is deterministic context-free
Q.46 Which of the following languages is [GATE-2016]
generated by the given grammar?
S → aS |bS| ε Q.49 Consider the following languages:
a) {anbm |n,m ≥ 0} L1 = {anbmcn+m : m, n ≥ 1}
b) {w ϵ {a,b}* | w has equal number L2 = {anbnc2n : n ≥ 1}
of a’s and b’s} Which one of the following is TRUE?
c) {an | n ≥ 0} ∪ {b n | n ≥ 0} ∪ {anbn | a) Both L1 and L2 are context-free.
n ≥ 0} b) L1 is context-free while L2 is not
d) {a, b}* context-free.
[GATE-2016] c) L2 is context-free while L1 is not
context-free.
Q.47 Consider the following context-free d) Neither L1 nor L2 is context-free
grammars: [GATE-2016]
G1: S→aS|B, B→b|bB
G2: S→aA|bB, A→aA|B|ε, B→bB|ε Q.50 Which one of the following grammars
Which one of the following pairs of is free from left recursion?
languages is generated by G 1 and G2, a) S → AB b)S →Ab| Bb |c
respectively? A → Aa | b A → Bd | ε
a) {ambn|m>0 or n > 0} and {a mbn|m B→c B→e
> 0 and n > 0} c) S → Aa | B d) S → Aa|Bb|c
b) {ambn|m>0 and n>0} and {a mbn|m A → Bb | Sc | ε A → Bd | ε
> 0 or n≥0} B→d B → Ae | ε
c) {ambn|m≥0 or n > 0} and {a mbn|m [GATE-2016]
> 0 and n > 0}
d) {ambn|m≥0 and n>0} and Q.51 Identify the language generated by
{ambn|m>0 or n>0} the following grammar, where S is
[GATE-2016] the start variable.
S→ XY
Q.48 Consider the transition diagram of a X → aX|a
PDA given below with input alphabet Y→ aYb|∈
Σ= {a, b} and stack alphabet Γ = {X,Z}. a) {a m bn | m n, n>0}
Z is the initial stack symbol. Let L b) {a m bn | m n, n 0}
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
c) {a m bn | m>n, n 0} a) ϕ b) (q0, q1, q3)
d) {a m bn | m>n, n>0} c ) (q0, q1, q2) d) (q0, q2, q3)
[GATE-2017(2)]
[GATE-2017(2)]
Q.55 Consider the following context-free
Q.52 Let L 1 , L2 be any two context-free grammar over the alphabet
languages and R be any regular {a,b,c} with S as the start
language. Then which of the symbol:
following is/are CORRECT ? S -> abScT | abcT
I. L1 L2 is context-free . T -> bT|b
II. L1 is context –free.
Which one of the
following
III. L1 R is context –free. represents the language generated by
IV. L1 L2 is context –free. the above grammar?
a) I, II and IV only b) I and III only a) {(ab)n(cb)n | n >= 1 }
c) II and IV only d) I only b) {(abncbm cbm …cbm | n, m1, m2, ….., mn >= 1 }
1 2 n
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
following are context – free Q.60 Given a language L, define L i as
languages? follows:
I. L1 L2
II. L1 L2
a) I only b) II only
c) I and II d)Neither I nor II
[GATE-2017(1)] The order of a language L is defined
as the smallest k such that L k = Lk+1.
Q.59 Consider the following languages: Consider the language L1 (over
I. {ambncpdq | m+p = n+q , where alphabet 0) accepted by the
m,n,p,q >= 0} following automaton.
II. {ambncpdq | m=n and p=q , where
m,n,p,q >= 0}
III. {ambncpdq | m=n=p and p!=q ,
where m,n,p,q >= 0}
IV. {ambncpdq | mn = p+q , where The order of L1 is _____.
m,n,p,q >= 0} [GATE-2018]
ANSWER KEY:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(b) (b) (c) (c) (b) (c) (b) (d) (d) (b) (a) (d) (b) (b) (d)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(c) (b) (d) (b) (c) (d) (b) (b) (b) (b) (d) (a) (b) (d) (c)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
(c) (d) (d) (a) (c) (b) (d) (b) (d) (c) (d) (c) (b) (b) (c)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
(d) (d) (d) (b) (b) (c) (b) (d) (c) (c) (b) (d) (a) (b) 2
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
EXPLANATIONS
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
The string “aabab” is odd length but Q.8 (d)
centre bit is not “a”. LC MC (Reg)C (CFL)C
So, this string is not a member of
Reg (CSL)C Reg CSL CSL
L(M)
A CSL may or may not be
regular. So, options (a) and (c) are
Q.6 (c)
false. A CSL need not be a CFL. So,
Here, we have
option (b) is false. So, answer is (d)
S → bS
none of these.
S → baA (S → aA)
S → baaB (A → aB)
Q.9 (d)
S → baaa (B → a)
In NPDA we may a dead
Therefore, | Na (w) | = 3.
configuration. This mean we may not
Also, if we use A → bA instead of A →
give any transition to any alphabet
aB,
from this state.
S → baA
We say that a string is accepted if
S → babA
PDA is in final state after reading the
To terminate A,
final symbol in the string or after it
we would have to use A → aB as only
has read `$ symbol denoting end of
B terminates at a (B → a).
the string and it is in final state.
S → baA
S → babA Question never says that we have
transitions defined for all the
S → babaB
alphabet symbols in the PDA. Neither
S →babaa
L(P) nor N(P)are necessarily * .
Q.10 (b)
L1 is CFL but not a DFCL, since
accepting WW R necessarily involves
finding the middle of the string,
which involves non-determinism.
Thus, here also, |Na(w)|=3. Therefore, (a) is false.
So, C is the correct choice. L2 is a DFCL is true since # is a special
symbol and middle string can now be
Q.7 (b) surely found by using #, thereby
L a mbn cmn | m,n eliminating the need for non-
A DPDA can accept this language. deterministic guessing. So, (b) is
When a's and b's are in input, these true.
are pushed into the stack and when L3 is a CSL and not a CFL. So (c) is
c's appear in input the a’s and b's are false.
popped out. If after all c's are L3 is not a DCFL either. So, (d) is false.
finished, if stack is empty, this means
nc(W) = na{W)+nb(W) and the string Q.11 (a)
is accepted. Else it is rejected. L1 and L 2 are context-free languages
Now, since a DPDA exists, the and therefore, L1 L2 may or may
language is context-free. Clearly the not be context-free, since CFLs are
language is not regular, since not closed under intersection.
we must count and compare c's with Now, let us look at L1 L2 .
a's and b's which cannot be done by
L1 L2 {a n bncn | n 0}
any FA.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Which is clearly not context-free but Sum of number of b’s and number of
is context sensitive. c’s = twice of number of a’s
Q.12 (d)
i.e. L a l bmcn 2l m+n
We know that; the languages
Q.17 (b)
accepted by non-deterministic finite
automata are also accepted by A bA
deterministic-finite automata. This L(A) b*
may not be in the case of context-free S aSAb
languages. Now, substituting A Qution into this
Therefore, Df Nf and Dp Np gives
S aSAb
Q.13 (b)
No, substituting A Qution into this
L(G) =Set of all palindrome strings.
gives
“baba” is not a palindrome string.
S aSb*b
Q.14 (b) S aSb aSbb aSbbb...
To be accepted by NPDA but not
DPDA, the language must be a C FL
L(S) a mbn m n
but not DCFL. Q.18 (d)
a) is wrong, it is not context free. The language is context free or not,
b) L a l bmcn l m or m n this can be proved by finding out the
This language has double grammar for all the languages.
comparison on m with `or’. So
L 0nm1n 0m n,m 0
the language is CFL but not DCFL. The production for L 1 as follows:
c) In this language only one S 0S0 | 0A1|
comparison is there and push
and pop position are clear. This is A 0A1|
a DCFL. Now, we need to apply these values
d) a*b* is regular. Every regular of the production individually to
language is a DCFL. So this generate
language is also a DCFL. 0m0n1n0m→to prove
This can be verified by using stack.
Q.15 (d) Hence, proved, So L 1 is context-free.
L is CFL and M is Regular. Going through the same procedure,
Intersection of CFL and Regular is we can see that two comparisons are
always a CFL, since all languages are made in the L 2 language, so, it is not
closed under regular intersection. context-free.
L3→ Going through the same
Q.16 (c) procedure again, we can see that two
For every a, we put two X in stack comparisons are made in the L 3
[at state s] language, so it is not context-free.
For every b we pop out one X [reach
to state (getting b after a)] Q.19 (b)
For every c we pop out one X [reach a) G would be ambiguous if
to state u (getting c after b)] replacement of 5 add equal a ’s
If all X are popped out then reached and b's.
to final state f, means t hat,
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
b) The grammar cannot generate 1, a zero is popped out of the stack. In
string aabb though they have the end, if stack has start stack
equal number of a’s and b’s. symbol only, then the string is
c) The language exhibiting such accepted. Else it is rejected. Since
nature is accepted by every DCFL is recursive, we can say
deterministic push- down that the language is recursive, and is
automata. a DCFL.
Example of string abba
Now, S→SS→εS→εSS→SS abS→abba Q.23 (b)
Also, S→SS→abS→abba Option (a) Decidable: Due to
Here, we can see two derivations of presence of CYK algorithm, the
same string. So it is ambiguous. membership problem for CFGs
becomes decidable.
Q.20 (c)
Option (b) Undecidable: The
Grammar may change but language
ambiguity problem for CFGs cannot
remain the same in the grammar and
be decided.
its disambiguated version. Option (c) Decidable : Like
L(D) L(G) pumping lemma is used to check
whether the language is regular or
Q.21 (d) not, similarly algorithms are
Using capital letters for variables and employed and implemented to check
small letters for terminals, the given for the regular language whether the
grammar G1 becomes regular languages are finite or not.
S w ES Option (d) Decidable: Equivalence
So problem for FSAs are always
E i decidable.
Since LHS of every production is a Q.24 (b)
single variable, G1 is context free L1 is CFL [push a’s onto stack, and
grammar. pop a with each b]
G2 becomes L2 is CFL [push b’s onto stack and
S w ES pop b with each c]. So, option (a) is
So false.
E EE In L1, every string has atleast one “c” .
E E*E In L2, every string has no “c” .
E i So, L1 ∩ L2 = ϕ. So option (b) us true.
Since LHS of every production is a Union of two CFLs is a CFL and so
single variable, G2 is also a context option (c) is false.
free grammar. RHS of some of the L2 is DCFL and hence acceptable b y
productions in G1 and G2 has two a DPDA . So, option (d) is false.
non-terminals, hence it is not regular
grammar. Q.25 (b)
SB
Q.22 (b) B 0B00 1
0i 21i i 0 is a DCFL since, a DPDA
So, S generates 0n102n n 1
can accept this language. 0’s are S AA
pushed into the stack and then when
A 0A A0 1
2 appears in input, state is changed
and immediately after that for e very
A 0m10n m,n 0
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
So, S generates 0m10n 0p10q m,n,p,q 0 . Statement 4 Decidable : If the LHS
of each production has one and only
0m10x10q m, x,q 0 one variable then it is a context-free
010 10 i, j, k 0
i j k grammar.
G. Arithmeti c
expressions with
matched pairs of
parentheses
H. Palindromes
Q. X→XbX| XcX|
dXf|g
Q.28 (b)
Statement 1 Decidable: The
algorithm can be used to check the
finiteness/infiniteness on the DFA
and also the two given DFAs, a
product DFA can be constructed.
S. X→bXb|cXc|ε
Statement 2 Undecidable: It is not
decidable since the language is
context-free. Q.31 (c)
Statement 3 Undecidable : It is also Statement 1 True: Left recursive and
undecidable that whether two push right recursive grammar can be
down automata accept the same converted into each other.
language.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Statement 2 False: We can remove all In fact the minimum length input
epsilon productions only if grammar string is “101”. Which will give an
doesn't contain epsilon in the output of1, while reaching state 01.
language.
Statement 3 True: It is the definition Q.35 (c)
of regular grammar. The language L1 accept strings {c,
Statements 4 True: The derivation abc, abcab, aabbcab, aabbcaabb, …}
trees in CNF are binary trees. and L2 accept strings {a, b, c, ab, abc,
aabc, aabbc, … }. Intersection of these
Q.32 (d) two languages is L1∩L2 = {a kbkc | k
Option (a) True: Non-deterministic >= 0} which is context free, but not
finite automata can be converted into regular.
the deterministic finite automata.
Option (b) True: With reference to Q.36 (b)
option (a), same is with the non- Regular expression A regular
deterministic turing machine. expression is a way for a computer
Option (c) True: Regular language is programmer to express, how a
always context-free but the reverse computer program should look for a
is not true. specified pattern in text and then
Option (d) False: We know that a set what the program is to do when each
is a subset of itself and hence, every pattern match is found. This is done
subset of recursively enumerable set using lexical analysis.
is not recursive. Push-down automata PDAs are
finite automatons with a data
Q.33 (d) structure that can be used to store an
Since it is known that the set of DCFL’ arbitrary number of symbols but
are a proper sub class of the set of which can be only.
CFL’s NPDA’s which corresponds in Accessed in a Last-In-First-Out
general to class of CFL’s cannot in (LIFO) fashion. PDA follows syntax
general be converted to equivalent analysis.
DPDA’s which correspond to the Dataflow analysis It is the process
class of DCFL’s of collecting information about the
way the variables are used, defined
Q.34 (a) in the program. The analysis is done
The transition diagram for the at basic block granularity . Collected
given FSM is given below: information is represented as a set of
dataflow equations. The technique is
useful for performing several
optimizations such as constant
propagation and copy propagation.
Q.37 (d)
There need not be an equivalent
DPDA for each NPDA.
Q.38 (b)
As can be seen from above diagram The possible palindrome generated
the minimum length of the input by above grammar can be of odd
string that will take machine from 00 length only as there is no rule.
to 01 with output 1, is three.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Example generated palindromes are a) L 2 is context Free - true
aba, aaa, bab, ababa, aaaaa, .. We can accept or reject L 2 with single
Q.39 (d) stack. Insert P 0's into stack skip q
A context-free language is 1’s.
For each 0 corresponding to r, remove
L a b : n 1 that is the language
n n
0 from stack.
of all non-empty even-length strings. b) L1∩ L2 is context Free — true
It consists of Here L 1∩ L2 = L2 which is context Free.
1. The entire first halves of which are c) Complement of L 2 is recursive —
a's. true L2 is Context-Free language
2. The entire second halves of Complement of CFL may or may not be
which are b's. CFL. Complement by CFL is definitely
L is generated by the grammar recursive.
S→aSb|ab, and is accepted by the d) Complement of L 1 is Context Free, but
push-down, automaton. , not regular false.
M q0 ,q1,q1,a,b, a,z, ,q0 , q1
L1 0p1q0r |p,q,r0
is regular and
M q0 ,q1,q1,a,b, a,z ,q0 , q1 regular languages are closed under
, where δ are defined as follows: complement.
q0 ,a, z q0 ,a, z
q0 ,a,a q0 ,a
q0 , b,a q1, x
q1, b,a q1, x
δ(q1 ,λ,z)=(qf ,z)
(state1 , read pop) = (state 2 , push)
Where z is initial stack symbol and x
means pop action. Hence, the answer is (d).
The given languages follow all the
rules of the context-free languages Q.42 (c)
and also these languages are accepted L3 is non-deterministic context free
by push-down automata, therefore language.
all languages are context-free.
Q.43 (b)
Q.40 (c) The language accepted is
L1 0p1q | p,q, N is regular
L(M) {wxw
R
x 0,1, , where w
language.
is context-free language is the 1's complement of w} .
L2 0p1q | p,q, Nand p q Only the string “10110010010” is
in the language and hence will be
L3 0 1 0 | p,q, Nand p q r
p q r
accepted.
is not context free. The following diagram shows how
this string will be accepted by the
PDA.
Q.41 (d) 101100 10010
L1 0p1q0r | p,q,r 0 Given string Option(b)string
L2 0 1 0 | p,q,r 0,p r
p q r
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.47 (d)
G1 : S → aS | B
B→ b | b B which generates strings
with RE b+
The above grammar can be written
as S → aS | b + which represents the
strings with RE a* b + = {am bn | m≥0,
n >0}
G2 : S → aA | bB
A→ aA | B | ϵ
Q.44 (b) B→ bB | ϵ
L1 is CFL because there is only one The minimum strings obtained from
comparison at a time. First we will starting symbol are a, b
push 'a' into the stack m number of S →aA, A→aA| ϵ generates strings a+
times and then push 'b', n number of S→bB, B→bB | ϵ generates strings b+
times. Now when 'a' comes, don't Also, the combination of these
push it into stack, pop b's for every productions generates strings start
a's. When b comes don't push then with at least one a and followed by
into the stack, pop a's for every b's. any number of b’s.
L2 is not CFL. because here we are So it is the language L = {a m bn | m >
not able to check equal numbers of 0, n ≥0} ∪ { bn | n > 0} which can also
a's and equal number of b's. be written as {a mbn|m > 0 or n > 0}.
L3 is CFL. We can rewrite it like
{a2n+1bn}={a2nabn}={aa2nbn}. This can Q.48 (d)
be implemented using PDA. L = {an | n ≥ 0} ∪{an bn | n ≥ 0} and L
is DCFL.
Q.45 (c)
G1 :S1 aS1b Q.49 (b)
L1: {an bm cn+m | m, n >= 1} – CFL
G2 :S2 abS2
L2: {an bn c2n | n >= 1} – CSL
L1 L(G1 ) a n bn n 0 L1 is CFL but L2 is Not CFL because
in L2 comparison is needed twice
L2 L(G2 ) ab n 0 ab *
n
which cannot be done using one stack.
Clearly L1 is regular is false of L2 is
regular is True. So correct answer is Q.50 (b)
(c). S → Ab | Bb | ε
A → Bd | ε
Q.46 (d) B→e
S → aS |bS | ϵ This generates finite language and
S → ϵ there is no left recursion.
S→aS generates all strings with RE a* C and D have indirect left recursion.
S→ aS generates all strings with RE b*
S→ aS | bS generates all strings with Q.51 (c )
RE ab* and ba* and then any S→ XY
combination of a and b. X→ aX|a⇒X→{am |m ≥1}
So given grammar represents RE Y→ aYb|∈⇒Y→{anbn |n ≥0}
{a,b}* S→ XY⇒ S → {ambn |m>n,n>0}
m > n because at least 1 will be
attached on left of a nbn.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.52 (b) Q.55 (c)
I. L1 L2 is context –free = CFL S → abScT|abcT
CFL = CFL . So, True T→bT|b
Qving T →bb*
II. L1 is context- free = CFL = CSL
Substitute in S to get
but not CSL but not CFL. So, false. S→abScbb*|abcbb*
III. L1 R is context –free CFL So, Qution of S would be
Regular CFL CFL = CFL
(ab)n (cbm )n | m,n 1
.So, True So, option (c ) is correct
IV. L1 L2 is context-free
CFL CFL CSL. So, False Q.56 (b)
G1 :S aSb | T,T cT |
Q.53 (d) G 2 :S bSa | T,T cT |
L1 = {ap |p prime} is a CSL but not
CFL(prime number checking involve L(G1 ) a ncmbn | m,n, 0
division) L(G2 ) bn cma n | m,n 0
L2 {a n bmc2m | n 0, m0} is CFL (one L(G1 ) L(G2 ) a ncmbn bncma n cm | m 0 C*
comparision) Since the only common strings will
L3 {a n bnc2n | 0}is CSL (two be those strings with only ‘c’, since in
comparision) the first language all the other
L4 {a n bn | n1} is a DCFL strings start with ‘a’ and in the
So, second language all the other strings
I. L1 is CFL but not regular is false start with ‘b’ Clearly the intersection
II. L2 is not CFL is false is not finite but regular.
III. L3 is not CFL but recursive is true
since every CSL is recursive. Q.57 (d)
IV. L4 is true DCLF is true. The given grammar is
So, only III and IV are true and S SaS| aSb| bSa | SS|
correct. Now S aSb | bSa | SS|
Generated all s strings with equal
Q.54 (c) number of ‘a’ and ‘b’. Now S SaS
Covering the table to a state diagram, can only generated strings where ‘a’
we get , is more than ‘b’ since on left and
right of ‘a’ in SaS, S will have only
strings with n b n a is not possible
to generate by the given grammar
Q.58 (a)
L1 is a CFL.
L 2 also a CFL.
𝛿̂(q2,abc) = All states reachable from Union of 2 CFL is always as CFL, but
q2 by “aba” If aba is broken as intersection may or may not be
𝜀.a. 𝜀. 𝜀.b.a.Then from q2 we can So, I is clearly true.
reach q1 and from there by null Let us intersect and check II
transition we can reach state q 2 as
well as q0 .
a n bn cm a n bmcm a n bncn
𝛿̂(q2,aba) = { q0, q1, q2}
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Which is clearly not a CFL but CSL. Q. 60 2
So option (a) which is I only, is the L1 = ε + 0(00)*
answer. L0 = ε
L1 = ε . (ε + 0(00)*)
Q. 59 (b) = ε + 0(00)* = L1
I. {ambncpdq ∣ m + p = n + q, where m, n, L = L1 . L1 = L1 . L1
2
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
3 TURING MACHINE, UNRESTRICTED LANGUAGES,
COMPLEXITY
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Note that, although there is no limit on how
far right the head may move and write
nonblank symbols on the tape, at any finite
TM, the TM has visited only a finite prefix of
the infinite tape.
An ID (or configuration) of a TM M is
denoted by α qβ
where , *
is the tape contents to the left of the
head
q is the current state. 3.2 TYPES OF TURING MACHINE
is the tape contents at or to the right of There are a number of other types of Turing
the tape head. machines in addition to the one we have seen
That is, the tape head is currently scanning such as Turing machines with multiple tapes,
the leftmost tape symbol of β . ones having one tape but with multiple heads,
(Note that if , then the tape head is ones with two dimensional tapes,
nondeterministic Turing machines etc. It turns
scanning a blank symbol), If q 0 is the start
out that computationally all these Turing
state and w is the input to a TM M then the machines are equally powerful. That is, what
starting or initial configuration of M is on one type can compute any other can also
piously denoted by q0w . compute. However, the efficiency of
computation, that is, how fast they can compute,
Examples: may vary.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
q0, >. The transition function is a partial
function
: Q X { H1 , H2 ... , Hn } X ( { } ) -> (
Q { h } ) X( { }X{ R , L , S } ,
where H1 , H2 ... , Hn denote the tape heads.
Here the numbers indicate the Turing Machines with Infinite Tape:
correspondence of squares in the two
tapes: square i of the two dimensional tape is This is a kind of Turing machines that have
mapped to square i of the one dimensional one finite control and one tape which extends
infinitely in both directions.
tape. h and v are symbols which are not in the
It turns out that this type of Turing machines
tape alphabet and they are used to mark the
are only as powerful as one tape Turing
left and the top end of the tape, respectively. machines whose tape has a left end.
Turing Machines with Multiple Tapes: Nondeterministic Turing Machines:
This is a kind of Turing machines that have A nondeterministic Turing machine is a
one finite control and more than one tapes Turing machine which, like nondeterministic
each with its own read-write head. It is finite automata, at any state it is in and for the
denoted by a 5-tuple < Q, , , q0, > . Its tape symbol it is reading, can take any action
transition function is a partial function selecting from a set of specified actions rather
: QX ( { } )n -> ( Q { h } than taking one definite predetermined
) X( { }) X { R , L , S }n .
n action. Even in the same situation it may take
A configuration for this kind of Turing different actions at different times. Here an
machine must show the current state the action means the combination of writing a
machine is in and the state of each tape. symbol on the tape, moving the tape head and
It can be proven that any language accepted going to a next state. For example let us
by an n-tape Turing machine can be accepted consider the language L = {ww: w ∈ {a, b}*}.
by a one tape Turing machine and that any Given a string x, a nondeterministic Turing
function computed by an n-tape Turing machine that accepts this language L would
machine can be computed by a one tape first guess the midpoint of x that is the place
Turing machine. Since the converses are where the second half of x starts. Then it
obviously true, one can say that one tape would compare the first half of x with the
Turing machines are as powerful as n-tape second half by comparing the i-th symbol of
Turing machines. the first half with the i-th symbol of the second
half for i = 1, 2, ... . A deterministic Turing
Turing Machines with Multiple Heads: machine, on the other hand, can not guess the
This is a kind of Turing machines that have midpoint of the string x. It must find the
one finite control and one tape but more midpoint by for example pairing off symbols
from either end of x.
than one read-write heads. In each state
Formally a nondeterministic Turing
only one of the heads is allowed to read and machine is a Turing machine whose transition
write. It is denoted by a 5-tuple < Q, , , function takes values that are subsets of
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
(Q { h } ) X( { }X { R,L,S}. So, on any input strings w L , M enters
an accepting ID and halts and
As in the case of NFA, it is understood that a On an input string w L , M halts
nondeterministic Turing machine at any entering in a blocking ID (or entering in
configuration selects one combination of next a reject state).
state, tape symbol and head movement out of
the set of triples without following any Informally, a language is said to be
specific predetermined rule. recursively enumerable if there exists a TM
which accepts it and a language is said to be
It can be shown that a nondeterministic recursive if there exist a TM which halts on
Turing machine is only as powerful as a every input.
deterministic Turing machine.
Every recursive language is recursively
3.3 RECURSIVE AND RECURSIVELY enumerable.
ENUMERABLE LANGUAGES:
Output of turing machine can be one of the
following three.
It will halt and accept the string
It will halt and reject the string
It will go into an infinite loop
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Example: brackets or to move its tape head to the left
A Grammar Generating the language of the [ or to the right of the ].
Example:
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
It is usually much easier to compute worst- Finding the shortest path between two
case complexity. vertices in a graph.
Drop all terms except the highest-ordered Finding Hamiltonian cycle in a graph is not
one, and a decision problem, whereas checking a
graph is Hamiltonian or not is a decision
Drop the coefficient of the highest-ordered problem.
term.
Justifications for this procedure are: What is Language?
Every decision problem can have only two
For very large values of n, the effect of the answers, yes or no. Hence, a decision
highest-order term completely swamps the problem may belong to a language if it
contribution of lower-ordered term. We are provides an answer ‘yes’ for a specific input.
interested in large values of n because, from A language is the totality of inputs for which
a strictly practical point of view, it is the the answer is Yes. Most of the algorithms
large problems that give us trouble. Small discussed in the previous chapters are
problems are almost always feasible to polynomial time algorithms.
compute.
For input size n, if worst-case time
Tweaking the code can improve the complexity of an algorithm is O(n k), where k
coefficients, but the order statistic is a is a constant, the algorithm is a polynomial
function of the algorithm itself. time algorithm.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
P-Class Every problem in this class can be solved in
The class P consists of those problems that exponential time using exhaustive search.
are solvable in polynomial time, i.e. these
problems can be solved in time O(n k) in P versus NP
worst-case, where k is constant. Every decision problem that is solvable by a
deterministic polynomial time algorithm is
These problems are called tractable, while also solvable by a polynomial time non-
others are called intractable or deterministic algorithm.
superpolynomial.
All problems in P can be solved with
Formally, an algorithm is polynomial time polynomial time algorithms, whereas all
algorithm, if there exists a polynomial p(n) problems in NP - P are intractable.
such that the algorithm can solve any
instance of size n in a time O(p(n)). It is not known whether P = NP. However,
many problems are known in NP with the
Problem requiring Ω(n50) time to solve are property that if they belong to P, then it can
essentially intractable for large n. Most be proved that P = NP.
known polynomial time algorithm run in
time O(nk) for fairly low value of k. If P ≠ NP, there are problems in NP that are
neither in P nor in NP-Complete.
Regarding O(n log n) time, note that
The problem belongs to class P if it’s easy to
The base of the logarithms is find a solution for the problem. The problem
irrelevant, since the difference is a belongs to NP, if it’s easy to check a solution
constant factor, which we ignore; that may have been very tedious to find.
and
Although n log n is not, strictly Polynomial-Time Reducibility:
speaking, a polynomial, the size of n Let L1 and L2 be languages over alphabets
log n is bounded by n2, which is a Σ1 and Σ2, respectively. We say that L1 is
polynomial. polynomial-time reducible to L2 if and only
if there is a function f from Σ1* to Σ2* such
Probably all the programming tasks you are that for any string x ∈ Σ1* , x ∈ L1 if and only
familiar with have polynomial-time if f(x) ∈ L2 and f can be computed in
solutions. This is not because all practical polynomial time.
problems have polynomial-time solutions.
Rather, it is because your courses and your NP-Hard
day-to-day work have avoided problems for A problem is said to be NP-Hard if every
which there is no known practical solution. problem in NP are polynomially reducible to
it.
NP-Class
The class NP consists of those problems that NP-Complete
are verifiable in polynomial time. NP is the A problem is said to be NP-Complete if it is
class of decision problems for which it is both NP and NP-Hard.
easy to check the correctness of a claimed
answer, with the aid of a little extra NP-complete Problems:
information. Hence, we aren’t asking for a 1. Satisfiability Problem for
way to find a solution, but only to verify that Propositional Logic
an alleged solution really is correct. 2. Graph Color Problem
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
3. Committee Meeting Schedule 9. Knapsack Problem: Given a knapsack
Problem. In fact most scheduling of size S, a set of objects, their sizes,
problems are NP-complete. their values and an integer V, is it
4. Traveling Salesman Problem: Given possible to select objects so that the
cities and traveling times between sum of their sizes does not exceed S
cities, a traveling salesman wants to and the sum of their values is V or
know a shortest route to visit all larger ?
cities exactly once and come back to 10. 3-Dimensional Matching : Given
where he/she started. three sets A, B and C of the same size,
5. Bin Packing Problem: Given a set of and a subset S of the Cartesian
objects, their sizes and a number of product A X B X C. Is there a subset
bins of the same size, find out T, called a matching, of S such that
whether or not the objects can be put every element of A, B, and C appears
into the bins. exactly once in T ?
6. Partition Problem: Given a set of
integers, group them into two groups For example, let A = {1,2}, B = {a,b},
so that the sum of the numbers of one and C = {x,y}, and S = {(1,b,x),(1,b,y),
group is equal to that of the other (2,a,x), (2,b,y)}.
group.
7. Subgraph Isomorphism Problem: Then T = {(1,b,y), (2,a,x)} is a
Given two graphs, find out whether desired set satisfying all the
or not one is a subgraph of the other. requirements. Note that
8. Set Cover Problem: Given a set S, a {(1,b,x),(2,a,x)} is not a matching.
collection of subsets of S and an
integer k, find out whether or not
there are k or less subsets in the
collection whose union is S.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
GATE QUESTIONS
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.6 If the strings of a language L can be decidable and P2 is undecidable.
effectively enumerated in Which one of the following is true?
lexicographic (i.e., alphabetic) order, a) P3 is decidable if P1 is reducible
which of the following statements is
true? to P3
a) L is necessarily finite b) P3 is undecidable if P3 is
b) L is regular but not necessarily reducible to P2
finite
c) P3 is undecidable if P2 is reducible
c) L is context-free but not
necessarily regular to P3
d) L is recursive but not necessarily d) P3 is decidable if P3 is reducible
context-free to P2 ’s complement.
[GATE-2003]
[GATE-2005]
Q.7 Nobody knows yet, if P=NP. Consider
Q.10 Let L1 be regular language, L 2 be a
the language L de as follows:
deterministic context-free language
and L 3 a recursively enumerable,
Which of the following statement is but not recursive, language. Which
true? one of the following statements is
a) L is recursive false?
b) L is recursively enumerable but a) L1 L2 is a deterministic CFL
not recursive
b) L3 L1 is recursive
c) L is not recursively enumerable
d) Whether L is recursive or not will c) L1 L2 is context free
be known after we find out if P = d) L1 L2 L 3 is recursively
NP enumerable
[GATE-2003] [2006:2 Marks]
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
[2007:1 Marks] a) Diterministic finite automata
Q.13 Which of the following is true for the (DFA) and non-deterministic
language {ap| p is a prime}? finite automata (NFA)
a) It is not accepted by a Turning b) Deterministic push down
Machine automata (DPDA) and non-
b) It is regular but not context-free deterministic push down
c) It is context -free but not regular automata (NPDA)
d) It is neither regular nor context c) Deterministic single-tape Turing
free, but accepted by a Turning machine and Non-deterministic
machine single-tape Turing machine
[2008:1 Marks] d) Single-tape Turing machine and
multi-tape Turing machine
Q.14 Which of the following are [2011:1 Marks]
decidable?
1. Whether the intersection of two Q.18 Which of the following problem are
decidable?
regular languages in infinite
1. Does a given program ever
2. Whether a given context-free
produce an output
language is regular
3. Whether two push-down 2. If L is a context-free language,
automata accept the same then is L also context-free?
language 3. If L is a regular language, then is
4. Whether a given grammar is L also regular
context-free 4. If L is a recursive language, then
a) 1 and 2 b) 1 and 4 is L also recursive?
c) 2 and 3 d) 2 and 4 a) 1,2,3,4 b) 1,2
[2008:1 Marks] c) 2,3,4 d) 3,4
[2012:1 Marks]
Q.15 If L and L' are recursively
enumerable, then L is Q.19 Which of the following is/are
a) regular b) context-free undecidable?
c) context-sensitive d) recursive 1. G is CFG. Is L G ?
[GATE-2008] 2. G is a CFG. Is L G *?
Q.16 Let L1 be a recursive language Let 3. M is a Turing machine. Is L(M)
L 2 and L 3 be languages that are regular?
4. A is a DFA and N is an NFA. Is
recursively Enumerable but not L(A)=L(N)?
recursive. Which of the following a) 3 only b) 3 and 4 only
statements is not necessarily true? c) 1, 2 and 3 only d) 2 and 3 only
a) L2 – L1 is recursively enumerable. [2013:1 Marks]
b) L1 – L3 is recursively enumerable
c) L2 ∩ L1 is recursively enumerable Q.20 Which of the following statements
Is/are false?
d) L2 ∪ L1 is recursively enumerable
1. For every-non-deterministic
[GATE-2010] Turing machine, there exists an
equivalent deterministic Turing
Q.17 Which of the following pairs have machine.
DIFFERENT expressive power? 2. Turing recognizable languages
are closed under union and
complementation.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
3. Turing decidable languages are c) If A m B and B is recursively
closed under intersection and enumerable then A is recursively
complementation. enumerable.
4. Turing recognizable languages d) If A m B and B is not recursively
are closed under anion and
enumerable then A is not
intersection.
recursively enumerable.
a) 1 and 4 b) 1 and 3
[GATE-2014]
c) Only 2 d) Only 3
[GATE-2013]
Q.24 Let be a
finite non-empty
Q.21 Let L be a language and L be its
alphabet and let 2 be the power
complement. Which one of the
following is NOT a viable possibility? set of *. Which one of the following
a) Neither L nor L is recursively is TRUE?
enumerable (r.e.) a) Both 2 and *. are countable
b) One of L and L is r.e. but not b) 2 is countable and * is
recursive; the other is not r.e. uncountable
c) Both L and L are r.e. but not
c) 2 is uncountable and * is
recursive.
countable
d) Both L and L are recursive
d) Both 2 and * are
*
[GATE-2014]
uncountable
Q.22 Let M be the encoding of a [GATE-2014]
Turing machine as a string over
Q.25 Which one of the following problems
0, 1. is undecidable?
Let L { M | M is a Turing a) Deciding if a given context-free
machine that accepts a string of grammar is ambiguous.
length 2014}. Then, L is b) Deciding if a given string is
a) decidable and recursively generated by a given context-free
enumerable grammar.
b) undecidable but recursively c) Deciding if the language
enumerable generated by a given context-free
c) undecidable and not recursively grammar is empty.
enumerable d) Deciding if the language
d) decidable but not recursively generated by a given context-free
enumerable grammar is finite.
[GATE-2014] [GATE-2014]
Q.23 Let A m B denotes that language A
Q.26 Consider the following statements.
is mapping reducible (also known as I. The complement of every Turing
many-to-one reducible) to language decidable language is Turing
B. Which one of the following is decidable
FALSE? II. There exists some language
a) If A m B and B is recursive then which is in NP but is not Turing
A is recursive. decidable
b) If A m B and A is undecidable III. If L is a language in NP, L is Turing
then B is undecidable. decidable
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Which of the above statements is/are a) W can be recursively enumerable
true? and Z is recursive.
a) Only II b) Only III b) W can be recursive and Z is
c) Only I and II d) Only I and III recursively enumerable.
[GATE-2015] c) W is not recursively enumerable
and Z is recursive.
Q.27 For any two languages L1 and L2 d) W is not recursively enumerable
such that L1 is context-free and L2 is and Z is not recursive.
recursively enumerable but not [GATE-2016]
recursive, which of the following
is/are necessarily true? Q.30 Consider the following types of
I. L1 (complement of L1) is recursive languages:
L1: Regular,
II. L2 (complement of L2) is recursive
L2:Context-free,
III. L1 is context € free L3:Recursive
IV. L1 L2 is recursively enumerable L4: Recursively enumerable.
a) I only b) III only Which of the following is/are TRUE?
c) III and iv only d) I and IV only I. L3’ L4 is recursively enumerable
[GATE-2015] II. L2 L3 is recursive
Q.28 Consider the following languages. III. L1 * L2 is context-free
L1 {M | M takes at least 2016 IV. L1 L2 ’ is context-free
steps on some input} a) I only b) I and III only
L2 {M | M takes at least 2016 c) I and IV only d) I, II and III only
steps on all inputs} and [GATE-2016]
=L3{ M M accepts }
Q.31 Let L(R) be the language represented
Where for each turning machine M, by regular expression R. Let
M denotes a specific encoding of M. L(G) be the language generated by a
Which one of the following is TRUE? context free grammar G. Let L(M) be
a) L1 is recursive and L 2 , L 3 are the language accepted by a Turning
not recursive machine M.
b) L 2 is recursive and L1 , L 3 are not Which of the following decision
problems are undecidable ?
recursive
I. Given a regular expression R and
c) L1 , L 2 are recursive and L 3 is
a string w, is w ∈ L (R) ?
not recursive II. Given a context-free grammar G,
d) L1 , L 2 , L 3 are recursive is L(G) = Φ?
[GATE-2016(2)] III. Given a context-free grammar G,
is L(G)= ∑* for some alphabet ∑ ?
Q.29 Let X be a recursive language and Y IV. Given a Turning machine M and a
be a recursively enumerable but not string w, is w ∈ L(M) ?
recursive language. Let W and Z be a) I and IV only b) II and III only
two languages such that Y reduces to c) II,III and IV d)III and IV only
W, and Z reduces to X (reduction [GATE-2017(2)]
means the standard many-one
Q.32 Let A and B finite alphabets and let
reduction). Which one of the
following statements is TRUE? # be a symbol outside both A and B.
Let f be a total function from A*to B*.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
We say f is computable if there exists
a Turing machine M which given an
input x in A*, always halts with f(x )
on its tape. Let L f denote the
language {x#(f(x))|x ∈ A*}.
ANSWER KEY:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(b) (a) (b) (a) (a) (d) (a) (b) (c) (b) (d) (b) (d) (b) (d)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(b) (b) (d) (d) (c) (c) (b) (d) (c) (a) (d) (d) (c) (c) (d)
31 32 33
(d) (a) (b)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
EXPLANATIONS
Q.1 (b)
The C language is context sensitive Option (d) False: The complement of
language. All the feature of C context free language is never
language comes under CFL except context free.
following two which makes the C
language as CSL: Q.5 (c)
a) Declaration of variable before Transition function of M
use 0 1 B
b) The matching of actual and
formal parameters. q0 q1 ,1, R q1 ,1, R Halt
Q.2 (a)
P1 is membership of FSM i.e., regular q1 q1 ,1, R q1 ,1, R q1 , B, L
language. P2 is finite/infiniteness of
The graphical representation of M is
context free grammar. Membership as
of FSM and finiteness of CFG, both
are decidable problems.
So P1 and P2 both are decidable.
Q.3 (b)
Problem X is state entry problem.
Halting problem of turing machine
can be reduced to state entry
problem. Since halting problem of The original configuration of tape of
turing machine is undecidable , the M is as follows
state-entry problem must also be BBB q0 000 . 111 . BBB
undecidable. The language
corresponding to state-entry BBB1q1 00 .. 111 .... BBB
problem is RE but not REC. So X is S(q0 ,0 q1,1, R
undecidable but partially decidable. BBB1q1 00 . 111 .. BBB
Q.4 (a) BBB11q1 00 .. 111 . BBB
Option (a) True: The complement of S(q0 ,0) q1,1, R
recursive language is always
recursive. If tape is finite, then after K right
Option (b) False: The recursively move all 0's will be changed to 1's
enumerable language is the language, and M remains in state q1 .
when taken its complement; lose its BBB 111 . q1111 BBB
recursively enumerable nature. BBB 111 . q01111 BBB
Option (c) False: The complement of
recursive language is always S(q1,1) q0 ,1, L
recursive and never recursively BBB 111 .1q1 11111 BBB
enumerable. S(q0 ,1) q1 ,1, R
BBB 111 . q01111 BBB
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
S(q1,1) q0 ,1, L Consider (b) L1 as REC & L2 is not
So, machine M moves one step right RE:
and one step left and goes in infinite If L 1 is REC, then L1 is REC.
loop
So M cannot reach a configuration Also, if L 2 is RE but not REC, then L2
(q 0 , B) and M does not halt on any is not RE.
Therefore (b) is true.Clearly, (c) and
string in 0 1 .
(d) false since L2 is not RE.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
nature of the language therefore L is ∴ 1 and 4 are decidable.
regular.
Q.15 (d)
As per the theorem, a language is
Q.12 (b) recursive if that language and its
a) Membership problem for CFG’s is
complement are recursively
decidable (CYK algorithm exists). enumerable. Therefore, L is
b) Ambiguity problem of CFG’s is
recursive.
undecidable.
c) Finiteness problem of FSA’s is
Q.16 (b)
decidable, since there exist an (a)L2−L1=L2∩L1'
algorithm to check if a given
Recursive languages are closed
regular language L is finite or
infinite. under complement, and so L1' is
d) Equivalence problem for FSA’s is recursive and hence recursively
decidable, since there exist an enumerable also. So, L2∩L1' is
algorithm to check where recursively enumerable is always
L M1 L M2 or not. TRUE.
(b)L1−L3=L1∩L3'
Q.13 (d)
Recursively enumerable languages
Let L a P | p is a prime . There is no are not closed under complement. So,
DFA which recognizes L, since to
L3' may or may not be recursively
check whether a number is prime or
enumerable and hence we can't say
not requires division to be
performed, which neither FA nor anything if L1∩L3' is recursively
PDA can do. It is a CSL and can be enumerable or not.
accepted by a turing machine. Option (c) Intersection of two
recursive enumerable is recursive
Q.14 (b) enumerable.
1. “Intersection of two regular
Option (d) Union of two recursive
languages is infinite” is decidable,
since we can construct a product enumerable is recursive enumerable.
DFA of the 2 given DFAS and then, This implies that option (b) is
using the algorithm to check incorrect
finiteness or infiniteness on this
DFA, we can Qve the problem. Q.17 (b)
2. “Whether a given CFL is regular” DFA NFA
is undecidable. DPDA NPDA
3. “Whether two PDA’s accept the DTM NTM
same language” is undecidable, Single tape TM ≡ Multi-tape TM
since equivalence of CFL’s is
Q.18 (d)
undecidable.
Statement (1) is undecidable (since it
4. “Whether a given grammar is
is the halting problem of TM).
context-free” is decidablesince
Complement of a context free
we can easily check using a TM,
language, may or may not be context
whether the LHS of every
free. So statement number (2) is not
production has a single variable
only a non trival problem but is also
and, then it is a CFG, else it is not
a CFG. undecidable..
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
If L is regular, L is surely regular. Q.21 (c)
So statement number (3) is If both L and its complement are Re
(trivially) decidable. Also if L is then both are REC.
recursive, L is also surely recursive.
Q.22 (b)
So statement number (4) is also
There are finite numbers of strings of
(trivially) decidable.
length ‘2014’. So, a turing machine
So, correct option is (d) i.e. only 3 and
will take the input string of length
4 are decidable.
‘2014’ and test it. If, input string is
Q.19 (d) present in the language then turing
1. G is CFG, is L G ? machine will halt in final state. But, if
2. This is the emptiness problem of turing machine is unable to accept
CFLs which is decidable. the input string then it will halt in
non-final state or go in an infinite
3. G is CFG, is L G *.
loop and never halt.
This is the Kleene closeness Thus, ‘L’ is undecidable and
problem of CFL’s which is recursively enumerable
undecidable.
4. M is turning machine, Is L M Q.23 (d)
regular. This is the regularity A mB means language A is
problem of REs which is mapping reducible to language B.
undecidable. Thus, A cannot be harder than B.
5. A is a DFA and N is NFA, Is L A Since, A can be reduced to B, instead
L N ?. of deciding A we can now decide
B. So, the first three options are
This is the equivalence problem of
correct.
regular languages which is As B is not recursively enumerable, it
decidable.
doesn't guarantee A is not
So, only 2 and 3 are undecidable. recursively enumerable. Thus, if
A m B and B is not recursively
Q.20 (c) enumerable then A is not recursively
1. Non - deterministic Turing
enumerable. Therefore, answer is D
Machine can be simulated by a is correct.
deterministic Turing Machine
with exponential time true.
Q.24 (c)
2. Turing recognizable language are
“not” closed under
2* is uncountable and * is
complementation. For any Turing countable
recognizable language the Turing
Machine T recognizing ‘L’ may Q.25 (a)
not terminate on inputs L Ambiguity is not an operation and
hence we can never say that CFG is
False
closed under ambiguity. Thus,
3. Turing decidable languages are
deciding ambiguity of CFG is
CLOSED under union and
undecidable.
complementation. It is easy to
determine if Turing machine is
Q.26 (d)
decidable – True
I and III are true. The definition of NP
So, answer is option (c) only 2.
itself says Qvable in polynomial time
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
using non-deterministic Turing Turing machine will make 2017th
machine. move depends on its initial state and
Q.27 (d) the contents of the first 2016 cells of
1. L1' (complement of L1) is the tape.
recursive is true L1 is context
free. Every context free language Now the first 2016 cells can have |Σ +
is also recursive and recursive 1|^2016 (+1 for the blank symbol)
languages are closed under different combinations. Out of these
complement. only some combinations will be
4. L1' L2 is recursively
valid(eg. if the first square is blank
enumerable is true Since L1' is
then any subsiquent square can't
recursive, it is also recursively
enumerable and recursively have an input symbol).
enumerable languages are closed
under union. So we can simulate the machine on
3. L1' is context-free: Context-free all these valid combinations and if it
languages are not closed under does not make 2017th move in any of
complement, intersection, or those combinations then we accept
difference. <M> in L1' and reject it otherwise.
2. L2' (complement of L2) is
Hence L1' and thus L1 is Recursive.
recursive is false: Recursively
Similarly, we can prove that L2' is
enumerable languages are not
closed under set difference or Recursive. L3 is not Recursive(Rice
complementation Theorem).
Q.28 (c)
Consider L1 = {<M>| M halts in < Q.29 (c)
2017 steps on some input}. Then L' = X recursive
Y REL but not recursive
{<M>|M takes >= 2017 steps for all
Y reduces to W
inputs}. Now whether or not a Turing Z reduces to X
Machine makes 2017th move By the following theorem:
depends on the state it is in after the Theorem: If P1 reduces to P2 then,
2016th move and the content of the • If P1 is Non-Recursively
first 2016 cells of the input tape(as enumerable then so is P2.
• If P2 is Non-Recursively
the Turing machine could have
enumerable then so is P1.
processed the atmost n cells after n
• If P1 is Recursive then so is P2.
moves). • If P2 is Recursive then so is P1.
Z is recursive and W is REL but not
However the state that a Turing recursive.
machine is after the 2016th move
depends on its state after the 2015th Q.30 (d)
move and the contents of the first L1: Regular
L2: CFL
2015 cells. L3: Recursive language
L4: REL
Reasoning like this all the way back
(i) L3 ’ is Recursive
to before the first move was made we
can conclude that whether the L3’ L4 is REL
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
(ii) L 2 ’ is recursive Q.32 (a)
L3 ’ is recursive If f is computable and let M be the
Turing machine that computes it
L2 ’ L3 is also recursive then when given a string of the form
(iii) L1 * is regular x#y we can calculate f(x) using M and
L 2 is CFL accept it if y = f(x) or else reject it.
Hence if f is computable then L is
L1 * L2 is CFL
recursive. Now assume that L is
Since CFL is closed under recursive. Then we can list all of it
intersection with RL. strings in lexciographical order.
RL CFL is CFL Then when we are given x we can
(iv) L1 is RL & L 2 ’ is recursive compare it with the left part of each
L1 L2 ’ is CFL is not possible string(the part before #). Once we
So (i), (ii), & (iii) are correct find a match we return the right hand
portion as f(x). Hence if L is recursive
Q.31 (d) then f is computable. Hence f is
I. Membership of regular language computable iff L is recursive.
(Decidable)
II. Emptiness of CFL (Decidable)
III. L=∑* problem of
CFL(Undecidable)
IV. Membership of RE language
(Undecidable)
So ,only III and IV are undecidable
.So, correct answer is (d).
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
ASSIGNMENT QUESTIONS
Q.1 The word “formal” in formal d) For a given input string, length of
languages the output string generated by a
means Moore machine is one more than
a) the symbols used have well- the length of the output string
defined meaning generated by that of a Mealy
b) they are unnecessary, in reality machine.
c) only the form of the string of
symbols is significant Q.6 The recognizing capability of
d) none of the above NDFSM and DFSM
a) may be different
Q.2 Let A = {0, 1} the number of possible b) must be different
strings of length “n” that can be c) must be the same
formed by the elements of the set A d) none of the above
is
a) n! b) n2 Q.7 FSM can recognize
c) n n d) 2n a) any grammar
b) only CFG
Q.3 Choose the correct statements c) any unambiguous grammar
a) Moore and Mealy machines are d) only regular grammar
FSM’s with output capability. Q.8) Pumping lemma is generally used
b) Any given Moore machine has an for proving
equivalent Mealy machine. a) a given grammar is regular
c) Any given Mealy machine has an b) a given grammar is not regular
equivalent Moore machine. c) whether two given regular
d) Moore machine is not an FSM. expressions are equivalent
d) none of the above
Q.4 The major difference between a
Moore and a Mealy machine is that Q.9 Which of the following are not
a) The output of the former regular?
depends on the present state and a) string of 0’s whose length is a
the current input perfect square
b) The output of the former b) set of all palindromes made up of
depends only on the present 0’s and 1’s
state c) strings of 0’s, whose length is a
c) The output of the former depends prime number
only on the current input d) string of odd number of zeroes
d) None of the above
Q.10 Which of the following pairs of
Q.5 Choose the correct statements. regular expressions are equivalent?
a) A Mealy machine generates no a) 1(01) * and (10) * 1
language as such b) x(xx) * and (xx) * x
b) A Moore machine generates no c) (ab) * and a*b
language as such d) x+ and x*x+
c) A Mealy machine has no terminal
state.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.11 Choose the correct statements. c) of finite tape length, without
a) A = {anbn|n=0, 1, 2, 3,…..} is a rewinding capability and
regular language. bidirectional tape movement
b) The set B, consisting of all d) of finite tape length, rewinding
strings made up to only a’s and capability and bidirectional tape
b’s having equal number of a’s movement
and b’s defines a regular
language. Q.16 TM is more powerful than FSM
c) L(a*b*) B gives the set A. because
d) none of the above a) the tape movement is confined
to one direction
Q.12 Pick the correct statements. b) it has no finite state control
The logic of pumping lemma is a c) it has the capability to remember
good example of arbitrary long sequence of input
a) The Pigeon-hole principle symbols.
b) The divide & conquer technique d) none of the above
c) Recursion
d) iteration Q.17 The FSM pictured in below figure
recognizes
Q.13 The basic limitation of an FSM is
that
a) it can’t remember arbitrary large
amount of information
b) it sometimes recognizes
grammars that are not regular a) all strings b) no string
c) it sometimes fails to recognize c) ε- alone d) none of above
grammars that are regular
d) all of the above Q.18 The FSM pictured in below shown fig
is a
Q.14 Palindromes can’t be recognize by
any FSM because
a) an FSM can’t remember
arbitrarily large amount of
information
b) an FSM can’t deterministically fix a) Mealy machine
the mid-point b) Moore machine
c) even if the mid-point is known, c) Keene machine
an FSM can’t find whether the d) none of the above
second half of the string matches Q.19 The above machine
the first half a) complements a given bit pattern
d) None of the above b) generates all strings of 0’s and 1’s
Q.15 An FSM can be consider a TM c) adds 1 to a given bit pattern
a) of finite tape length, rewinding d) none of the above
capability and unidirectional Q.20 The language of all words (made up
tape movement of a’s and b;s ) with at least two a’s
b) of finite tape length, without can be described by the regular
rewinding capability and expression
unidirectional tape movement a) (a+b)*a(a+b)*a(a+b)*
b) (a+b)*ab*a(a+b)*
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
c) b* ab* a(a+b)*
d) a(a+b)* a(a+b) * a(a+b)*
Pick the correct statement Q.27 Any given transition graph has an
a) Both are equivalent equivalent
b) The second FSM accepts only a) regular expression
b) DFSM
c) The first FSM accepts nothing
c) NDFSM
d) None of the above
d) none of the above
Q.23 Set of regular languages over a given
Q.28 The following CFG S →aS|bS|a|b
alphabet set, is not closed under
Is equivalent to the regular
a) union b) complementation
expression
c) intersection d) none of above
a) (a* + b)* b) (a + b)+
Q.24 The machine pictured in fig. c) (a + b)(a + b)* d) (a + b)* (a + b)
Q.29 Any string of terminals that can be
generated by the following CFG
S →XY
X →aX |bX|a
a) Complements a given bit pattern Y →Ya |Yb|a
b) Finds 2’s complement of a given a) Has at least one b
c) Increments a given bit pattern by 1 b) should end in an ‘a’
d) Change the sign bit c) Has no consecutive a’s or b’s
d) has at least two a’s
Q.25 For which of the following
application regular expressions Q.30 The following CFG
can’t be used? S→aB|bA
a) Designing compliers A →a|aS|bAA
b) Developing text editors B→b|bS|aBB
c) Simulating sequential circuits Generates strings of terminals that
d) Designing computers have
a) Equal number of a’s and b’s
Q.26 The FSM pictured in fig. recognizes b) Odd number of a’s and odd
number b’s
c) Even number of a’s and even
number of b’s
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
d) Odd number a’s and even Q.36 The set A = {anbnan | n = 1, 2, 3, …….}
number of a’s is an example of grammar that is
a) regular
Q.31 Let L(G) denote the language b) context free
generated by the grammar G. to c) not context free
prove set A=L(G) d) none of the above
a) it is enough to prove that an
arbitrary member of A can be Q.37 Let L1 = {anbnam | m, n = 1, 2, 3, ….}
generated by grammar G L2 = {anbmam | m, n = 1, 2, 3, …….}
a) It is enough to prove that an L3 = {anbnan | n = 1, 2, 3, …….}
arbitrary string generated by G, Choose the correct statements,
belongs to set A a) L3 = L1 L2
b) Both the above comments (a) b) L1 and L2 are CFL but L3 is not
and (b) are to be prove a CFL
c) Either of the above comments c) L1 and L2 are not CFL but L3 is
(a) or (b) is to be proved a CFL
d) L1 is a subset of L3
Q.32 The set {anbn | n = 1, 2, 3…..} can be
generated by the CFG Q.38 L = {anbnan|n = 1,2,3,…….} is an
a) S→ ab | aSb example of a language that is
b) S→aaSbb | ab a) context free
c) S →ab | aSb |ε b) not context free
d) S→aaSbb | ab | aabb c) not context free but whose
complement is CF
Q.33 Choose the correct statements. d) context free but whose
a) All languages can be generated complement is not CF
by CFG
b) Any regular language has an Q.39 The intersection of a CFL and a
equivalent CFG regular language
c) Some non-regular languages a) need not be regular
can’t be generated by any CFG b) need not be context free
d) Some regular languages can’t be c) is always regular
generated by any CFG d) is always CF
Q.34 Which of the following CFG’s can’t
be simulated by an FSM? Q.40 A PDM behaves like an FSM when
a) S → Sa | a the number of auxiliary memory it
S abX has is
a) 0 b) 1
b) X cY b) 2 d) none of above
Y d | aX
c) S → aSb| ab Q.41 A PDM behaves like a TM when the
d) None of the above number of auxiliary memory it has
is
Q.35 CFG is not closed under a) 0 b) 1 or more
a) union c) 2 or more d) none of the above
b) Kleene star
c) complementation Q.42 Choose the correct statements.
d) concatenation a) The power of DFSM and NDFSM
are the same
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
b) The power of DFSM and NDFSM a) proving whether a primitive
are different recursive function is turning
c) The power of DPDM and NDPDM computable
are different b) proving whether a primitive
d) The power of DPDM and NDPDM recursive function is a total
are the same function
c) generating primitive recursive
Q.43 Which of the following is accepted functions
by an NDPDM, but not by a DPDM? d) generating partial recursive
a) All strings in which a given functions
symbol is present at least twice.
b) Even palindromes Q.48 Which of the following is not
c) Strings ending with a particular primitive recursive but computable?
terminal. a) Carnot function
d) none of the above b) Riemann function
c) Bounded function
Q.44 CSG can be recognized by a d) Ackermann function
a) FSM
b) DPDM Q.49 Which is the following is not
c) NDPDM primitive recursive but partially
d) linearly bounded memory recursive?
machine a) Carnot function
b) Riemann function
Q.45 Choose the correct statements. c) Bounded function
a) An FSM with 1 stack is more d) Ackermann function
powerful than an FSM with no
Q.50 Choose the correct statements.
stack
a) A total recursive function is also
b) An FSM with 2 stack is more
a partial recursive function
powerful than an FSM with 1
b) A partial recursive function is
stack
also a total recursive function
c) An FSM with 3 stack is more
c) A partial recursive function is
powerful than an FSM with 2
also a primitive recursive
stack
function
d) All of these.
d) A primitive recursive function is
also a partial recursive function
Q.46 Choose the correct statements
a) An FSM with 2 stacks is as Q.51 A language L for which there exists a
powerful as a TM TM, T that accepts every word in L
b) DFSM and NDFSM have the same and either rejects or loops for every
power word that is not in L is said to be
c) A DFSM with 1 stack and an a) recursive b) recursively
NDFSM with 1 stack have the enumerable
same power c) NP-HARD d) none of the above
d) A DFSM with 2 stack and an
NDFSM with 2 stacks have the Q.52 Choose the correct statements
same power a) L = { anbnan | n = 1, 2, 3, …….}
is recursively enumerable
Q.47 Bounded minimization is a b) recursive languages are closed
technique for under union
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
c) every recursive language is yes and may or may not terminate
recursively enumerable otherwise is said to be
d) recursive languages are closed a) stable b) unsolved
under intersection c) partially solved d) unstable
Q.53 Choose the correct statements Q.60 The number of states of the FSM
a) Set of recursively enumerable required to simulate the behavior of
languages is closed under union a computer, with a memory capable
b) if a language and its complement of storing ‘m’ words each of length
are both regular then language ‘n’ bits is
must be recursive a) M × 2n b)2mn
c) recursive languages are closed c) 2 m + n d) none of the above
under complementation
d) none of the above Q.61 The vernacular language English, if
considered a formal language is a
Q.54 pick the correct answers. Universal a) regular language
TM influenced the concept of b) context free language
a) Stored-program computers c) context sensitive language
b) Interpretive implementation of d) none of the above
programming languages
c) Computability Q.62 Let P, Q and R be three languages. If
d) None of the above P and R are regular and if PQ = R
then
Q.55 The number of internal states of a a) Q has to be regular
UTM should be at least b) Q cannot be regular
a) 1 b) 2 c) Q need not be regular
c) 3 d) 4 d) Q has to be a CFL
Q.56 The number of symbols necessary to
simulate a TM with m symbols and n Q.63 Consider the grammar
states is S PQ | SQ | PS
a) m + n b) 8mm + 4m P x
c) mn d) 4mn + m Q y
To get a string of n terminals the
Q.57 Any TM with m symbols and n states
number of production to be used is
can be simulated by another TM
a) n2 b) n + 1
with just 2 symbols and less than
c) 2n d) 2n – 1
a) 8mn states b) 4mn + 8 states
b) 8mn + 4 states d) mn states
Q.64 Choose the correct statements.
A class of languages that is closed
Q.58 The statements – “A TM can’t solve
under
halting problem” is
a) Union and complementation has
a) true
to be closed under intersection
b) false
b) Intersection and
c) still an open question
complementation has to be
d) none of the above
closed under union
c) Union and intersection has to be
Q.59 If there exists a TM which when
closed under complementation
applied to any problem in the class,
d) Al of the above
terminates if the correct answer is
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.65 The following grammar is c) non-deterministic PDA to
S→ a α b|b α c|aB deterministic PDA
S→ aS|b d) non-deterministic Turing machine
S→ α bb| ab to deterministic Turing machine
bα→bdb| b
a) Context free b) regular Q.70 An FSM can be used to add two
c) context sensitive d) LR (k) given integers. This remark is
a) true b) false
Q.66 Which of the following definitions c) may be true d) none of the above
generates the same language as L,
where Q.71 A CFG is said to be in Chomsky
L = {xnyn, n ≥ 1} ? normal
I. E →xEy | xy form(CNF), if all the productions are
II. xy | x+xyy+ of the form A→BC or A→a. let G be a
III. x+y+ CFG in CNF. To derive a string of
a) I only b) I and II terminals of length x, the number of
c) II and III d) II only production to be said is
a) 2x – 1 b) 2x
Q.67 A finite states machine with the c) 2x + 1 d) 2x
following state table has a single
input X and a single output Z Q.72 Determine the regular expression
over ∑ = {0, 1}
a) 1* 2* b) 0+ 1-
c) 0 – 1 d) None of these.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.76 Obtain the regular expression for Q.82 Which of the following equation will
L a b2n 2m1
| n 0,m 0 be generated using Arden's
Method to the automata ?
a) (a)2n (b)2m1
b) (aa)* (bb)* b
c) No regular expression exists for
the language a) A= ε
d) None of these. b) B= A ε
c) Both a) and b) above
Q.77 Describe the set represented by the d) None of these.
regular express (00 + 1)* (11 + 0)*.
a) The set of all strings having 0's Q.83 Which of the following equation will
and 1's occuring in pairs be generated using Arden's Method
b) The set of all strings having 0's to the automata?
in pairs
c) The set of all strings having 1's
in pairs
d) None of these. a) B = aA
b) C = aB
Q.78 Given r.e. for strings over {0, 1, 2} c) Both a) and b) above
containing at 7 single 1. d) None of these.
a) (0 + 2)* 1 b) 1 (0+ 2)*
c) (0 +1 + 2)* d) None of these. Q.84 What are the sub expression to be
joined by + operator of the regular
Q.79 Find the regular expression for the expression accepted by the
language following automata?
L = {w : w I mod 2 = 0}, wϵ {a, b, c}*.
a) aa+ab+ac+ba + bb+bc+ ca+cb +cc
b)(a + b + c) (a + b + c)
c) Both a) and b) above
d) None of these. a) a b) ab
c) aab d) None of these.
Q.80 Given P and Q two regular
expression. Which of following Q.85 In the following automata
identity hold ?
a) A* = A
b) (PQ)* P = P (QP)*
c) Both a) and b) above
d) None of these.
a) the r.e corresponding to the
Q.81 Find the incorrect identity of regular states A and B are same
expression f: the following : b) the r.c. corresponding to the
a) (R + S)* = R* + S* states B and C are same
b) ϕ*= ε c) the r.c. corresponding to the
c) Both a) and b) above are wrong states C and A same
d) None of these. d) None of these
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.86 Find the regular expression for the Should be removed first from the
automata following automata?
a) A →B b) B→C
c) C→B d)Noneof these
b)
a) (a b(b ab)*aa)*
c)
b) (0 1(1 01)*00)*
c) Both a) and b)
d) None of these
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a) b)
b)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.102 In a finite automata of n states , a
str0ng of length more than
a) will always be accepted
b) will result in revist of a set of
states
b) c) Both a) and b) above
d) None of these
Q.103 Which of the following in a regular
language?
a) L {a n b : n 0}
c) Both a) and b) above
d) None of these b) L {a n b : n 0}
c) Both a) and b) above
Q.100 Convert the following Moore d) None of these
machine to a DFA
Q.104 Which of the following is a regular
language?
a) L {a n bn : n 0}
b) L {a n bn : n 0}
a) c) Both a) and b) above
d) None of these
Q.105 Which of the following is a regular
language?
a) L ={w:wϵ{a,b}*}
b) L ={ww:wϵ{a,b}*}
b) c) L ={w3:wϵ{a,b}*}
d) None of these
b)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
d) None of these. Q.115 The intersection of the two regular
Language L1 a b *a &
Q.107 Let L’ be complement of a language.
L2 b a b *b is
Find the language L for which
corresponding L’ is regular. a) L b a b *a
a) L w2 : w a,b* b) L a a b *b
b) L w : w a, b * c) Both a) and b) above
d) None of these.
c) Both a) and b) above
d) None of these.
Q.116 Let a language L 0* 0 11* and a
Q.108 Is L 02n : n 1 regular? mapping f given by f(0) =a & f(1)
=b*.
a) Yes b) No Find f (L).
c) Can’t be known d) None of these.
a) ab * ba *3*
Q.109 Is the set of prime numbers regular? b) ab * ba *
a) Yes c) Both a) and b) above
b) No, as it is infinite set d) None of these.
c) Can’t be known
d) None of these. Q.117 Let L is language of regular
expression 10*1, and
Q.110 Let L be a regular set, Is the set homomorphism defined by
a1 a3 a5...a2n 1: a1 a2 a3..a2n are in L h 0 ab and h 1 then h(L) is
a) Yes b)No a) h(L)() b) h(L)(ab)
c) Can’t be known d) None of these. c) h(L)((ab)*) d) None of these
Q.111 Is the set strings not containing two
consecutive zeros regular? Q.118 Find h 1 L , where language is
a) Yes b) No L a a b * and homomorphism h
c) Can’t be known d) None of these is defined by h(0) = ab and h (1) = a.
Q.112 Given L1 a b *a and a) h 1 (L)((0 1))
L2 a b *b . Is L1 L2 regular? b) h 1 (L)((0 1)*)
a) Yes b) No c) h 1 (L)((0 1) 0 1)
c) Can’t be known d) None of these d) None of these.
Q.113 Given L1 a b *a & L2 a b *b Q.119 Let L1 / L2 denote the Quotient of
is L1 L2 regular? the languages L1 and L 2 . Find it for
a) Yes b) No
L1 (0*0*)and L2 (10*1)
c) Can’t be known d) None of these
a) ϕ
Q.114 Let L a a b * be regular b) ε
language over a, b Then L'is c) Both a) and b) above
d) None of these
a) L’(ϕ) b) L'((a b)*)
c) L'((a b)*b) d) None of these
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.120 Given
1
L {x for some y such Q.126 Let L w : w 10, w a,b*,
2 then L may be accepted by an
that x y , xy is in L}, find such L. automata of at least…states
a) ϕ a) 8 b) 9
b) ε c) 10 d) None of these
c) Both a) and b) above.
Q.127 Given a language L and a relation
d) None of these.
RLsuch that xRLy iff for each z,
either both or neither xz and yz are
Q.121 Find L/a for L a,aabb, baa
in L, where x ,y ϵ L. The relation RL
a) b) ba is.
c) , ba d) None of these. a) irreflexive b) asymmetric
c) non-transitive d) None of these
Q.122 Let a / L w : aw L. Find a/L for Q.128 Let a language L(0)* and are a
relation RL as defined in above
L a,aab baa equation. Find the number of
a) b) ab, ba equivalence classes of L.
c) , ba d) None of these a) 2 b) 3
c) 1 d) None of these
Q.123 Which of the following identities are
Q.129 Let M Q, , ,qo, F be a DFA and
true?
a) L / a a L a relation RM such that xRMy if f
q0, x q0y . Find the index of
b) La / a L
the relation RM for the following
c) Both a) & b) above automata
d) None of these.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
T a and Q.136 Determine the automata for the
grammar
P v0 aav0, v0 aa.
S aSA,S bS,A c,S
a) type 0 b) type 1 a)
c) Type 2 d) None of these
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Construct the automata
corresponding to G.
a) Automata cannot be constructed
as the grammar is of type 1
b) Automata cannot be constructed
as the grammar is of type 2
c) Automata cannot be constructed
as the grammar definition is
incomplete
d) None of these.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
a) C 0B 1D 0, D 0D 1D
Will correspond to a dead state in
the automata of the grammar?
a) A b) B
c) C d) None of
these.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.157 The L(G){a n ba n } for G given b c) Both a) and b) above
S aAa, A aAa | b. Find the d) None of these
condition on n.
Q.164 Given a grammar G with
a) n >0
productions S aaB,A bBb | Aa
b) n ≥ 1
c) Both a) and b) above then
d) None of these a) aabbabba ∉ L(G)
b) aabbabab ∈ L(G)
Q.158 True or False L(G) = Φ c) aabbabbb ∈L(G)
a) True b) False d) None of these
c) Can’t be known d) None of these
Q.165 True or False: A regular grammar
Q.159 Construct the grammar generating can be ambiguous
a) True b) False
L{xax r : w {0.1}*} Where x r is
c) Can’t be know d) None of these
reverse of string x
a) A 0A0|1A1| 0 Q.166 Which variable does not drive a
b) A 0A0|1A1|1 terminal string in the grammar
c) A 0A0|1A1| a S AB,A a,B b,B C,E C
d) None of these a)A b) B
c) S d) None of these
Q.160 Construct the grammar of
palindromes of odd length Q.167 Modify the grammar S AB,
generated over {0,1}. A a, B b, E C such that
a) A | a | b | aAa | bAb *
Q.163 Find the grammar for {abc,bca,cab} Q.169 Find the grammar with non-null
Whose terminals are in {a,b,c} productions from the grammar
a) S acb | bac | cba S aAb,A aAb |
b) S aS| bS| cS| a) S aAb | ab,A aAb
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
b) S ab,A aAb | ab Q.174 How many minimum new variables
c) S ab,A aAb will be added to convert the
d) None of these S ab,A aAb grammar S ABa,A aab,B Ac
into CNF.
Q.170 Determine the nullable variable in a) 1 b) 2
the grammar given by c) 3 d) None of these
S ABaC,A BC,B b| ,C D| ,D d
Q.175 Convert the grammar
a) A b) B
c) Both a) and b) d) None of these S ABa,A aab,B Ac into CNF:
Q.171 Find the equivalent grammar of S AB, B CD, A DF, D a,
a)
S Aa | B,B A| bb,A a | bc | B F DE, E b,C AG,G c
free from unit – productions. S AB, B CD, A DF, D a,
S a | bc | bb | Aa, A a | bb | bc, b)
a) F DE, E b,C A
B a | bb | bc c) Both (A ) and b) above
S a | bc | bb |, A a | bb | bc, d) None of these
b)
B a | bb | bc
c)Unit-free productions can’t obtained Q.176 Which of the following productions
d) None of these are not in Greibach Normal Form?
a) A AAa b) A aAaA
Q.172 Which of the following productions c) Both a) and b) d) None of these
are in Chomsky Normal From?
a) A→a|b b) S → AB|c
c) Both a) and b) d) None of these
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
ANSWER KEY:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(c) (d) (a) (b) (a) (c) (d) (B) (a) (a) (c) (a) (a) (a) (b)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
(c) (c) (a) (a) (a) (d) (d) (d) (c) (a) (c) (a) (b) (d) (a)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
(c) (a) (b) (c) (c) (c) (a) (b) (c) (a) (c) (a) (b) (d) (a)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
(a) (c) (d) (d) (a) (b) (a) (a) (a) (b) (d) (a) (a) (c) (b)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
(b) (c) (d) (a) (c) (a) (b) (c) (c) (b) (a) (d) (d) (c) (c)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
(b) (d) (d) (c) (c) (a) (d) (d) (d) (d) (a) (d) (d) (d) (b)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
(c) (a) (a) (c) (d) (b) (b) (a) (b) (c) (d) (b) (c) (d) (a)
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
(d) (b) (a) (d) (a) (a) (a) (a) (d) (d) (c) (c) (d) (a) (b)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
(d) (d) (c) (c) (d) (d) (d) (c) (c) (b) (c) (d) (d) (c) (d)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
(d) (b) (b) (c) (d) (d) (c) (b) (d) (c) (d) (d) (c) (a) (c)
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
(a) (d) (d) (c) (a) (d) (c) (a) (c) (b) (c) (d) (d) (a) (a)
166 167 168 169 170 171 172 173 174 175 176
(d) (b) (b) (b) (c) (c) (c) (d) (c) (a) (c)
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
EXPLANATIONS
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.29 (d) disproved by the following
S is the start state. X→a, Y→a are counter-example. Let the universal
the only production that could set be (a, b, c, d}. Let A = {{a},
terminate a string derivable from X {d}, {a, d}, {b, d}, {a, b, d}, {}}. A is
and Y respectively. So at least two closed under union and
a’s have to come anyway. Hence intersection but is not closed
the answer is (d). under complementation. For
example complement of {a, d} is {b,
Q.30 (a) c}, which is not a member of A.
We have S→aB → aaBB → aabB →
aabb. Q. 66 (a)
So (b) is wrong. II generates strings like XXYYY,
A careful observation of the which are not supposed to be III
productions will reveal a generates strings like XYY, which
similarity. Change A to B, B to A, a are not supposed to be. I can be
to b and b to a. The new set of verified to generate all the strings
productions will be the same as the in L and only those.
original set. So (d) is false
and (a) is the correct answer. Q. 67 (b)
Draw the transition diagram and
Q.32 (a) verify that the using 1 0 from A,
(b) is wrong because it can’t leads to C.
generate aabb (in fact any even
power). (c) is wrong since it Q. 68 (c)
generates Ɛ also. Both (a) and (d) L is the set of all possible strings
are correct made up of 0’s and 1’s (including
the null string).
Q.34 (c) So L R is L, which can be
(c) generates the set {a nbn,n = 1, 2,
generated by the regular
3,….} which is not regular. (a) and expression (a + b)*, and hence a
(b) being left linear and right linear
regular language. R is not a regular
respectively. Should have
expression. This can be proved by
equivalent regular expressions.
using Pumping Lemma or simply
by the fact that finite state
Q.60 (b) automata, that recognizes regular
Totally there are mn bits. Each bit
expressions, has no memory to
will be in one of the two possible
record the number of 0’s or 1’s it
states- 1 or 0. So the entire has scanned. Without this
memory made up of mn bits will be information 0n1n cannot be
in one of the possible 2 mn states.
recognized.
Q.62 (c) Q. 69 (c)
For example, p = a*; Q = a nbnb*; R = In general, a language (or
PQ = a*b*
equivalently the machine that
recognize it) cannot be converted
Q. 64 (a) to another language that us less
The first two positions can be powerful
proved to be correct using De
Morgan’s laws. (c) can be
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q. 70 (b) Q.80 (c)
FSM is basically a language Follows from the definitions of
acceptor. As such, it does not have regular expressions.
any output capability. So it cannot Q.81 (a)
add and output the result. The correct identity is
(R+S)*=(R*+S*)*.
Q. 71 (a)
This can be proved using induction Q.82 (d)
An important assumption in the
Q.72 (d) method is non-existence of e
The regular expression must moves.
contain only members of input
alphabet set and predefined Q.83 (d)
operators. A term on the right hand side of
the equation should have a state
Q.73 (d) followed by a input alphabet.
The expression represents the set
{ab, bb, ac, bc}. Q.84 (d)
The sub expression are a and
Q.74 (c) a(ab)*.
Follows from definition.
Q.85 (d)
Q.75 (c) None of the states are equivalent,
The members of input alphabets so their corresponding r.e.'s
set can be anything, even the cannot be same.
symbol ∑ itself.
Q.86 (a)
Q.76 (b) On solving the equations A = Aa +
Language L contains the strings Bb + A, B = Aa + Bb + Ca and C = Ba
having any number of pairs of a's using Arden's theorem, the
followed by at least one but odd expression will be obtained.
number of b's.
Q.87 (d)
Q.77 (d) The strings of any number of 0's
The set of all strings of the xy, (possibly A) followed by string of
where 0's are in pairs in x and l's any number of l's (possibly A).
are in pairs in y.
Q.88 (d)
Q.78 (d) The automata is :
The regular expression is
(0+2)*+(0 +2)* 1(0+2)*.
Q.79 (c)
The (b) when expanded will result Q.89 (d)
in (a), and the strings are of length Here either of the two can be
exactly two. removed.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.90 (b) the string in corresponding Mealy
The moves should be removed Machine for the same input string.
first, which does not have ε-moves
from the destination state. Q.98 (a)
Every time we reach to state A
Q.91 (c) even number of total I's are
As (b) above is obtained from (a) encountered and for state B they
by the removal of ε-moves. must be odd.
Q.103 (c)
In fact (a) and (b) above are a *b
and a+ b respectively, which are
obviously regular.
Q.104 (d)
Q.96 (b) The automata corresponding to a
Because we split the states which regular expression could not
remember anything.
correspond to different outputs in
this conversion.
Q.105 (a)
The language in (a) above contains
Q.97. (b)
all strings over { a, b }
The length of output string in
Moore Machine is one more than
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.106 (d) Q.117 (c)
The language is not regular and no Here h drops the 1's, since they are
automata can be designed for such replaced by ε, and turns each 0 into
languages. ab.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.129 (c) Q.140 (d)
The index will always be equal to Set of terminals contains only one
number of states in the automata. element denoted by 'a+'. The
corresponding automata is
Q.130 (b)
Every finite automata induces such
right invariant relation.
Q.131 (c)
All productions contain a variable
on the left hand side and one or Q.141 (d)
more variables or terminals on For a production ϕ A ψ → ϕ α ψ,
the right hand side. left and right contexts are ϕ and ψ
respectively. Hence here ϕ=A, ψ=A
Q.132 (d) and α = A.
For the grammar |β|≤|α|
Q.142 (c)
Q.133 (d) Follows from the Chomsky
The language is L (x* yy*z). Classifications.
Q.138 (d)
Braces can be introduced only in
the beginning and the end.
Q.139 (c)
Braces are optional, and the
production of A, B, C introduces at
one a each.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.151 (a)
Grammar in (a) is obtained from
the automata directly and the
variables have been renamed.
Q.152 (d)
The corresponding automata is
shown below and the dead state is D:
Q.147 (d)
The yield is aabbaa and is obtained
by the taking leaf nodes from left
to right of the derivation tree. Q.153 (d)
The corresponding left linear
Q.148 (c) grammar is S →S10|0.
Both the trees has the same yield
abab. Q.154 (c)
The grammar is (b) above is
Q.149 (a) directly obtained from the
The string abababa has two automata and in (a) it is further
derivation trees as shown below: simplified.
Q.155 (a)
As production S→Abbb
introduces at least three b's and
production A→4 aa introduces at
least two a's in the derived strings.
Q.156 (d)
The L (G) = {anbn: n ≥0} , as the
production S →A is present.
Q.157 (c)
After the first production if we
apply A→b, we get aba, otherwise
equal number of a's are added on
both side of b.
Q.158 (a)
Consider the grammar S→SS
Q.150 (c)
having no terminal on the right
The sentential forms are obtained
hand side, which will generate
in the derivation of the string
language ϕ.
aabbaa.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission
Q.159 (c) Q.168 (b)
The strings in L are such that nth The corresponding reduced
symbol from the start and end are grammar is S →aS| A, A →a.
same.
Q.169 (b)
Q.160 (b) The productions are obtained by
In a palindrome nth symbol from substituting for A wherever it
either end is same, and in the end occurs on the right hand side.
of the derivation the variable must
be replaced by a terminal, to get Q.170 (c)
the palindrome of odd length. The nullable variables in the
grammar are B and C as we have
Q.161 (c) productions B→A, C→A which
Let ℒ0, ℒcsl, ℒefl and ℒ rl denote the further makes A as nullable as we
family of type 0 languages, context have another production A -3 BC.
sensitive languages, context free
languages and regular languages, Q.171 (c)
then ℒ0 ⊇ ℒcsl ⊇ ℒefl ⊇ ℒrl For each unit production A B add
Q.162 (d) production A→y1|y2|....|yn to the
The grammar is S→BC, B→AB|ε, new grammar, where
A→011|1, C→DC|ε, D → 01. B→y1|y2|….|yn are the all
productions with B on the left.
Q.163 (d)
The grammar will have the Q.172 (c)
productions S→AB|bcC|CaD, A→a, The productions are in CNF if they
B→bc, C→a, D→b. are of the form A→BC or A →a.
© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission