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

Toc_Notes_

The Theory of Computation (TOC) is a fundamental area of computer science that explores what can be computed, the efficiency of computations, and the limitations of computational models. It encompasses various topics including automata theory, formal languages, computability, and complexity theory, which are essential for computer science students and relevant in competitive exams. The document also discusses the mathematical definitions of languages, operations on strings, and the structure of finite automata, particularly deterministic finite automata (DFA).

Uploaded by

theshield2801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Toc_Notes_

The Theory of Computation (TOC) is a fundamental area of computer science that explores what can be computed, the efficiency of computations, and the limitations of computational models. It encompasses various topics including automata theory, formal languages, computability, and complexity theory, which are essential for computer science students and relevant in competitive exams. The document also discusses the mathematical definitions of languages, operations on strings, and the structure of finite automata, particularly deterministic finite automata (DFA).

Uploaded by

theshield2801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

INTRODUCTION TO THEORY OF COMPUTATIONS

Theory of Computation • Theory of Computation (TOC) is a branch of theoretical computer science that addresses:
• Core subjects for CS/IT Students in university and Competitive Exams. • What can be computed, How efficiently can it be computed, What limitations exist in computation?
• In GATE 8-10 Marks out of 100 Marks, and 6-7 questions on an average • It involves the study of abstract machines, also known as automata, and mathematical models that define what
problems can be solved using these machines.
• In NET 18-20 Marks out of 200 marks and 7-8 questions
• TOC focuses on different computational models, their capabilities, and the complexity of solving problems. The
• Both parts are important Theory and Numerical main areas it deals with include:
• Needs less time, good scoring • Automata Theory: Studies different types of automata (e.g., finite automata, pushdown automata) and their
• Not Applied in Industry abilities to solve problems.
• Syllabus: Regular expressions and finite automata. Context-free grammars and push-down • Formal Languages: Explores the classification of languages and grammars that machines can recognize.
• Computability Theory: Investigates which problems can or cannot be solved by any computational model.
automata. Regular and context - free languages. Pumping lemma. Turing machines and
• Complexity Theory: Considers the resources (time, space) needed to solve problems and categorizes them
undecidability. based on difficulty (e.g., P, NP).

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

PROBLEM METHODS TO DEFINE LANGUAGE


• Machine Communication: • In natural language, we can list a finite and predefined set of words in a dictionary, but the
• Machines play a crucial role in human development, and we need a language to communicate with them.
However, this language need not be as complex as natural languages.
sentences formed using these words are infinite. To determine which sentences are valid or
• Formal vs. Informal Languages: invalid, we use grammar or rules as a mechanism.
• Machines use formal languages, which are structured and concise, unlike informal languages used in daily
human interaction.
• Language Definition:
• A language is "a system suitable for expressing ideas, facts, or concepts" using a set of symbols.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

MATHEMATICL DEFINATION OF LANGUAGE • Similarly, in our system we have finite number of symbols/letters but using those letters we can
generate infinite strings/words.
• SYMBOL- Symbols are the basic building blocks, which can be any character/token. (cow, • So, we may have languages that have infinite number of words, so it is not possible for us to list them,
sheep, , white flag, , , etc.) (in English we called them as letters). we have to use some framework, which can somehow represent the same language. There are mainly
two methods to represent a language
• ALPHABET- An alphabet is a finite non empty set of symbols, (every language has its own alphabet). here in toc,
we use symbol Σ for depicting alphabet. e.g. Σ = {0,1}. for English Σ = {a, b, c, …., z} (in English also alphabet is a • by a grammar that generates a language [RG generate RL]
set of letters, thought in general we called them as alphabet). • by a machine that accepts a language [FA accept RL language]

• STRING - It is a finite sequence of symbols (which are the member of set alphabet). E.g. Σ = {a, b} String- aabb,
aa, b, so on. (in English we called them as words).
Machine Grammar
• LANGUAGE - A language is defined as a set of strings. In the next level we consider programs as a string and
programming constructs/tokens like int, floats as letters/symbols.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

SOME BASIC OPERATIONS ON STRINGS Concatenation of string- Let x and y be two strings, then concatenation is defined
• So, before we proceed further let’s do a little home work on string, which will help us as the string formed by making a copy of string x followed by a copy of string y.
throughout the subject. (NOTE- It’s not commutative)
• Length of a string - It is defined as number symbol in the string. Denoted like |W|, e.g. length
E.g. w = ab, x= ba
of string |00110| = 5.
wx =
• |aaba| =
xw =

• |010| = w = w1 w2 w3… … wm x = x1 x2 x3… … xn

wx =
www.knowledgegate.in

www.knowledgegate.in
|wx| = |w| + |x|
www.knowledgegate.in

www.knowledgegate.in

Reverse of a string – If there is a string w then reverse of a string a denoted by Empty/Null String- The string with zero occurrence of symbols. It is denoted by ∈,
wr it is just the same string but written in reverse order. |∈|=0. If there is a string w, then wn stands for the strings obtained by repeating w,
n times.
W = w 1 w2 w3 … … wn w3 = www

w2 = ww

wr = w1 = w

w0 =

|w| |wr| w∈ = ∈w =

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Substring- Any string of consecutive symbols in some string ‘w’ can be collectively Q Consider a sting ‘GATE’ find the total number of substring possible?
said as a substring. E.g. w= abab its substrings can be ab, a, ba…etc. Substring of length 0
Substring of length Substring of length Substring of length Substring of
1 2 3 length 4
Number of sting
1 4 3 2 1
possible
S u b s t r i n g SUBSTRINGS ∈ G, A, T, E GA, AT, TE GAT, ATE GATE

1. utg Q Consider a sting ‘GGGE’ find the total number of substring possible?
Substring of Substring Substring Substring Substring
2. sbr length 0 of length 1 of length 2 of length 3 of length
3. rts 4
Number of
sting possible
4. str
SUBSTRINGS
5. sub
If a string has ‘n’ distinct symbols then total number of different sub string will be [n(n+1)/2] +1. If w is any string than empty
6. ∈ string ∈ and the string w itself is called a trivial substring and the remaining of the other are the non-trivial sub string[[n(n+1)/2]-
www.knowledgegate.in
1]
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider a sting ‘GATE’ find the total number of prefix and suffix possible? Q if ∑ = {a, b} then, find the following?

Prefix(GATE) = ∑0 =

∑1 =
Suffix(GATE) =
∑2 =

∑3 =

• ∑K is the set of all the strings from the alphabet ∑ of length exactly K.
www.knowledgegate.in

If there is a string of length n then no of prefix or suffix will be n+1 • ∑k = {W | |W| = K} (using the symbols from the alphabet ∑)
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Kleene closure- If ∑ is a set of symbols, then we use ∑* to denote the set of strings obtained by LANGUAGES
concatenating zero or more symbols from ∑ of any length, in general any string of any length • Since languages are sets, the union, intersection and difference of two languages are immediately defined.
which can have only symbols specified in ∑. • The complement of a language is defined with respect of ∑*
• ∑* = ‫∞=𝑖ڂ‬
𝑖=0 𝑤 𝑤 = 𝑖} (using the symbols from the alphabet ∑) • Lc =
• The reverse of a language is the set of all the strings after reversal

Positive closure – If ∑ is a set of symbols, then we use ∑ + to denote the set of strings obtained by Lr =
concatenating one or more symbols from ∑ of any length, in general any string of any length
which can have only symbols specified in ∑ (except ∈). • The concatenation of two languages L1 and L2 is the set of all the strings obtained by concatenating any elements
of L1 and L2.
• ∑+ = ‫∞=𝑖ڂ‬𝑖=1 𝑤 𝑤 = 𝑖} (using the symbols from the alphabet ∑)
• L1L2 =

• Let Ln is defined as L is concatenated with itself n times.


• Ln =

• L* =

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Given the language L = {ab, aa, baa}, which of the following strings are in L*? (GATE-2012) (1 Q In a string of length n, how many proper prefixes can be generated
Marks)
a) 2𝑛 b) n c) n (n + 1)/2 d) n – 1
1) abaabaaabaa

2) aaaabaaaa

3) baaaaabaaaab

4) baaaaabaa
(A) 1, 2 and 3
(B) 2, 3 and 4
(C) 1, 2 and 4
(D) 1, 3 and 4
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The number of substrings (of all lengths inclusive) that can be formed from a Q Suppose 𝐿1 = {10, 1} and 𝐿2 = {011, 11}. How many elements are there
character string of length n is in L = 𝐿1 𝐿2
𝑛(𝑛−1) 𝑛(𝑛+1)
a) n! b) 𝑛2 c) -1 d) +1 a) 4 b) 3 c) 2 d) None of these
2 2

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let 𝑥𝑛 denote the number of binary strings of length n that contain no Automaton
• An automaton is a self-operating system that transforms, transmits, and utilizes energy,
consecutive 0s, which of the following recurrences does 𝑥𝑛 satisfy?
materials, and information to perform functions without human involvement. The term often
refers to a machine that follows predefined rules to execute complex tasks autonomously.
a) 𝑥𝑛 = 2𝑥𝑛−1 b) 𝑥𝑛 = 𝑥 𝑛 + 1 Examples include automatic machine tools, packing machines, and photo printing devices.
2

c) 𝑥𝑛 = 𝑥 𝑛 + n d) 𝑥𝑛 = 𝑥𝑛−1 + 𝑥𝑛−2
2

Q The value of 𝑥5 is?


a) 5
b) 7
c) 13
d) 16
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts a language ‘L’, where L={a} FINITE AUTOMATA
over the alphabet ∑={a}. • A finite automaton is a computational model with a limited set of states, where control shifts
between states based on external inputs. It is commonly used as an abstract machine in
computer science for recognizing patterns in symbol strings. Finite automata have applications
in pattern matching, lexical analysis, parsing, and more. Finite automata can be broadly
classified into two types-
1. Finite automata without output
1. Deterministic finite automata.
2. Non deterministic finite automata.
3. Non deterministic finite automata with ∈

2. Finite automata with output


1. Moore machine
2. Mealy machine

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• A finite automaton is limited in its ability to store information during computation because it DETERMINISTIC FINITE AUTOMATA
lacks temporary storage. The machine can only store a finite amount of information by A deterministic finite automaton (DFA) is defined by 5-tuple (Q,,,S,F) where:
switching between a limited number of states. As a result, it can only handle scenarios where • Q is a finite and non-empty set of states
the amount of information to be stored is strictly bounded. •  is a finite non-empty set of finite input alphabet
•  is a transition function, ( : Q ×  → Q)
• S is initial state (always one) (S Q)
• F is a set of final states (F  Q) (0<=|F|<=N, where n is the number of states)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
A deterministic finite automaton (DFA) operates through Representation
various components: TRANSITION STATE DIAGRAM- A graphical representation where each circle 
• Input Tape: Divided into squares, each containing a represents a state, and directed edges show transitions between states. The initial 
symbol from the input alphabet. It has end markers state has an arrow pointing to it, and the final state is represented by two a b
(¢ at the left and $ at the right) or can be infinite. The concentric circles. q0
input string lies between these markers. Q
q1
• Reading Head: This head reads one square at a time TRANSITION TABLE- A two-dimensional table where rows represent states, and
and moves to the right. columns represent input symbols. The table shows how the machine transitions
• Finite Control: Acts as the inference engine and between states based on inputs.
manages transitions between states.
• A DFA ensures a unique computation for each input TRANSITION ID- δ {qi, a) = qj, This notation indicates that when the machine is in
string, making it deterministic. DFAs are commonly state qi and reads input symbol a, it transitions to state qj.
used in tasks like lexical analysis (spell checking) in
compiler design.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

ACCEPTANCE BY DFA Q Consider the following table of an FA


IF the final state is 𝑞4 , the which of the following strings will be accepted?
• Let ‘w’ be any string designed from the alphabet , corresponding to w, if there
exist a transition for which it starts at the initial state and ends in any One of the 1. aaaaa
final states, then the string ‘w’ is said to be accepted by the finite automata. δ *
(q0, w) = qf for some qf ∈ F.

• Mathematically, it can be represented as: - L(M) = {w  * | *(S, w) F}


2. aabbaabbbbb

3. bbabababbb
a) 1 and 2
b) 2 and 3
c) 3 and 1
d) all of the above
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q In the automaton below, s is the start state and t are the only final state. (GATE-2006) (2 Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
Marks)
b}, where every accepted string ‘w’ starts with substring s
Consider the strings u = ababab, v = bab, and w = aabb. i) s = b
Which of the following statements is true?

(A) The automaton accepts u and v but not w

(B) The automaton accepts each of u, v, and w ii) s = ab


(C) The automaton rejects each of u, v, and w

(D) The automaton accepts u but rejects v and w


iii) s = abb
• A language is considered a regular language if it can be accepted by a Deterministic Finite
Automaton (DFA). The best way to understand DFAs and regular languages is by designing
multiple DFAs, which helps in grasping both the DFA design process and the concept of regular
www.knowledgegate.in www.knowledgegate.in

languages. www.knowledgegate.in www.knowledgegate.in

Conclusion Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ ends with substring ‘s’.
• if w = sx, |s| = m, then no of states in the DFA is m+2 i) s = ab

• Dead state is required


ii) s = aa
• Loop on final state

iii) s = bab

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Conclusion Q Consider the following language:


L = { w∈{0,1}∗ ∣ w ends with the substring 011 }
Which one of the following deterministic finite automata accepts L? (GATE 2021) (2 MARKS)
(A)
• if w = xs, |s| = m, then no of states in the DFA is m+1

• No need of dead state (B)

• Can not stay of final state for ever


(C)

(D)
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Conclusion
b}. where every accepted string ‘w’ contains sub string s.
i) abb • if w = xsx, |s| = m, then no of states in the DFA is m+1

• No need of dead state

• Can loop on final state


ii) aba

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q No of states in a minimal dfa that accepts all the strings of a, b such Q Consider the following Deterministic Finite Automata (GATE-2015) (2 Marks)
that every string must have ‘aabab’ as sub string Which of the following is true?
a) 5 b) 6 c) 7 d) none

(A) It accepts all strings with prefix as “aababb”

(B) It accepts all strings with substring as “aababb”

(C) It accepts all strings with suffix as “aababb”


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in (D) None of the above www.knowledgegate.in


Q The following DFA accepts the set of all strings over {0, 1} that (GATE- Q Consider the following machine M
2009) (1 Marks) What is the language L(M) accepted by this machine?

a) Begin either with 0 or 1

b) End with 0

c) End with 00

d) Contain the substring 00 a) L(M) = {Set of all words starting with aabb}
b) L(M) = {Set of all words having aabb as a sub word}
c) L(M) = {Set of all words ending with aabb}
d) L(M) = {Set of all words with exactly one occurrence of aabb}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b} such
b} such that every accepted string start and end with a. that every accepted string start and end with same symbol.

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with different symbol.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX. b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb i) s= aa/bb ii) s=aaa/bbb

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Consider the machine M shown below L(M)?
b} such that every accepted string w, is like w=XSX.
i) s= aa/bb ii) s=aaa/bbb

a) L(M) = {words starting with aa or bb}


b) L(M) = {words ending with aa or bb}
c) L(M) = {words containing aa or bb as a sub word}
d) None of these
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let L be the set of all binary strings who’s last two symbols are the same. The Consider the transition diagram of an DFA as given below:
Q Which should be the final state(s) of the DFA if it should accept strings starting with ‘a’ and ending with ‘b’?
number of states in the minimum state deterministic finite state automation a) 𝑞0 b) 𝑞1 c) 𝑞0 , 𝑞1 d) 𝑞3
accepting L is (GATE-1998) (1 Marks)
Q Which of the following strings will be accepted if 𝑞0 and 𝑞1 are accepting states?
a) 2 b) 5 c) 8 d) 3 1. ababab 2. Babaaa 3. aaaba
a) 1,2 b) 2,3 c) 1,3 d) None of these

Q Which of the following represents the set of accepting states if the language to be accepted contains strings
having the same starting and ending symbols?
a) {𝑞0 } b) {𝑞0 , 𝑞3 } c) {𝑞3 } d) {𝑞3 , 𝑞1 }

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such that every string
accepted must contain exactly two a’s, |w|a=2.
that every string ‘w’ accepted must be like
i) |w| = 3

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such that every string
accepted must contain at least two a’s,
|w|a >= 2
ii) |w|<=3

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such that every string
accepted must contain at most two a’s,
|w|a <= 2
iii) |w|>=3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The minimum possible number of states of a deterministic finite automaton that Q Consider the machine M (GATE-2005) (2 Marks)
accepts a regular language L is_______(GATE-2017) (2 Marks) The language recognized by M is :
L = {w1aw2 | w1, w2 ∈ {a, b}*, |w1| = 2, |w2|>=3}

(A) {w ∈ {a, b}* / every a in w is followed by exactly two b’s}


(B) {w ∈ {a, b}* every a in w is followed by at least two b’}
(C) {w ∈ {a, b}* w contains the substring ‘abb’}
(D) {w ∈ {a, b}* w does not contain ‘aa’ as a substring}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Conclusion
b}, such that every string ‘w’ accepted must be like
i) |w| = 0(mod 3) ii) |w|=1(mod 4) No of states will be n, if the equation is on format r (mod n)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such Q How many minimum states are required in a DFA to find whether a given binary string
that every string accepted must contain has odd number of 0’s, there can be any number of 1’s. (GATE-2015) (1 Marks)
i) number of a is, |w|a = 0(mod 2) ii) number of b is, |w|b = 1(mod 2) (A) 1 (B) 2 (C) 3 (D) 4

iii) number of a is |w|a = 2(mod 3) iv) number of a is |w|a = 1(mod 4)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The smallest finite automation which accepts the language {x | length of x is Q Let ∑ = {0, 1}, then an automaton A accepting only those words from ∑ having an
divisible by 3} has (GATE-2002) (2 Marks) odd number of 1’s requires _________ states including the start state
(A) 2 states (B) 3 states (C) 4 states (D) 5 states a) 2 b) 3 c) 4 d) 5

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q The smallest finite automaton which accepts the language {x length of x is Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
divisible by 500} has that every string accepted must contain odd occurrence of the substring ‘ab’.
a) 200 states b) 300 states c) 400 states d) 500 states

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such Q how many DFA can be designed, with a fixed initial state, over an
that every string accepted must contain even occurrence of the substring ‘baa’. alphabet ∑ = {a, b}, and the number of states be two.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q how many DFA can be constructed over the alphabet, such that no of states |Q|
= 2 and size of input alphabet is |∑| = 2, that accepts empty language(Φ)?

• If no of states is |Q| = n, and no of input alphabet |∑| = m


• Then no of states will bewww.knowledgegate.in
www.knowledgegate.in www.knowledgegate.in

nn*m * 2n www.knowledgegate.in

Q how many DFA can be constructed over the alphabet, such that no of states |Q| Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
= 2 and size of input alphabet is |∑| = 2, that accepts universal language (∑ *)? b} such that for every accepted string 2nd from left end is always b.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 4th from left end is always a. b} such that for every accepted string 2nd from right end is always b.

• No of states will be
www.knowledgegate.in

n+2, if position is n
www.knowledgegate.in
www.knowledgegate.in

www.knowledgegate.in
Q The no of final states in a minimal DFA, that accept all string over a, b Q Design a minimal DFA that accepts all strings over the alphabet ∑= {a, b}, such
such that 4nd symbol from right end is always b. that every string ‘w’ which is accepted starts with ‘a’ & length is divisible by 3, i.e.
a) 2 b) 4 c) 8 d) none 0(mod 3)?

• No of states will be 2www.knowledgegate.in


n, if position is n
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such Q No of states in a minimal DFA that accept all string over a, b such that every
that every string ‘w’ which is accepted starts with ‘ab’ & length is divisible by string starts with ‘abb’ and length is concurrent to 4 (mod 7) is _______________
2(mod 4)?

• No of states will be n, nwww.knowledgegate.in


www.knowledgegate.in www.knowledgegate.in

= first condition + second condition -1 www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such that Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
every string ‘w’ which is accepted starts with ‘abbb’ & length is divisible by 3(mod 15)? b}, such that every string accepted must contain be like,
no of a = 0(mod 2) || no of b = 0(mod 2) ?

cross product method(one more approach , where concentrate on even and odd logic)
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b, c}, such
b}, such that every string accepted must contain be like, no of a = 0(mod that every string accepted must contain be like, a = 0(mod 2) && no of b = 0(mod
2) && no of b = 0(mod 2)? 3) && no of c = 0(mod 5)?

www.knowledgegate.in
• if, n(mod m) && p(mod r), then the no of states will be m*r, if m & r are
www.knowledgegate.in

www.knowledgegate.in relatively prime to each other and working on different symbol


www.knowledgegate.in

Q A minimum state deterministic finite automaton accepting the language L={w | Q Consider a DFA over ∑ = {a, b} accepting all strings which have number of a’s
w ε {0,1} *, number of 0s and 1s in w are divisible by 3 and 5, respectively} has divisible by 6 and number of b’s divisible by 8. What is the minimum number of
(GATE-2007) (2 Marks) states that the DFA will have? (GATE-2001) (2 Marks)
(A) 15 states (B) 11 states (C) 10 states (D) 9 states (A) 8 (B) 14 (C) 15 (D) 48

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q The following finite state machine accepts all those binary strings in which the Q Consider the following DFA in which 𝑠0 is the start and 𝑠1 , 𝑠3 are the final sates. What language
number of l’s and 0’s is respectively. (GATE-2004) (2 Marks) does this DFA recognize? (GATE-2007) (2 Marks)
(A) divisible by 3 and 2 a) All strings of x and y

b) All strings of x and y and even number of x


and even number of y or odd number or x and
(B) odd and even odd number of y

c) All strings of x and y which have equal number of x and y


(C) even and odd d) All strings of x and y with either even number
of x and odd number of y or odd number of x
and even number of y.
(D) divisible by 2 and 3
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Given below are two finite state automata (→ indicates the start state and F Q Design a minimal DFA that accepts all strings over the alphabet ∑ =
indicates a final state) Which of the following represents the product automaton {0,1}, such that every string ‘w’ which is accepted has a decimal
Z×Y? (GATE-2008) (2 Marks) equivalent
i) 0(mod 3)
ii) 2(mod 4)
iii) 0(mod 5)
iv) 2(mod 6)
v) 3(mod 8)

on a format of m (mod n)
1) if n is odd, number of states will be n
www.knowledgegate.in 2) if n is even and n=2m, then number of states will be m+1
www.knowledgegate.in

www.knowledgegate.in 3) if n is even and n! =2m, then for number of states no direct formula
www.knowledgegate.in

Q Consider the following deterministic finite automaton (DFA) The number of strings Q Let L⊆{0,1}∗ be an arbitrary regular language accepted by a minimal DFA with k
of length 8 accepted by the above automaton is _________. (GATE 2021) (1 MARKS) states. Which one of the following languages must necessarily be accepted by a
minimal DFA with k states? (GATE 2021) (1 MARKS)

(A) L − {01}

(B) L ∪ {01}

(C) {0,1}* – L

(D) L⋅L
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
COMPLIMENT OF DFA Note
• The finite automata which is obtained by interchanging final & non-final states is known as
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, complement of the finite automata.
b}, such that every string accepted must not contain a substring aaa?
• L(FA) U L(FAC) = ∑* L(FA) ∩ L(FAC) = Φ

• L(FA) subset of ∑* and L(FA)C subset of ∑*

• No of states in FA = no of states in complement of FA

• No of final states in a FA and it’s Complement FA may have different final states

• Complement always exist for DFA (as it is a complete system)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Deterministic automata of a language over alphabets {0, 1}, which does not Q construct the DFA for the following languages:
contain 3 consecutive 0’s. Minimum how many states ‘S’ DFA will have and how i) L= {am bn | m, n >= 0} ii) L = {am bn cp | m, n, p >= 0}
many of them will final states, F?
a) ISI = 5 and IFI = 1 b) ISI = 5 and IFI = 4
c) ISI = 4 and IFI = 1 d) ISI = 4 and IFI = 3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in • If type is L = {am bn | m>= 0,www.knowledgegate.in


n>=0}, then no of states is no of alphabet +1
Q construct the DFA for the following languages: Q construct the DFA for the following languages:
i) L= {am bn | m>= 0, n>=1} ii)L= {am bn | m>= 0, n>=2} i) L = {am bn | m>= 1, n>=0} ii) L = {am bn | m>= 2, n>=0}

• If type is L = {am bn | m>= • If type is L = {am bn | m>=


www.knowledgegate.in www.knowledgegate.in

0, n>=j}, then no of states is j+2


www.knowledgegate.in i, n>=0}, then no of states is i+3
www.knowledgegate.in

Q construct the DFA for the following languages: Q Consider the DFAs M and N given above. The number of states in a minimal
L= {am bn | m >= 1, n>= 2} DFA that accepts the language L(M) ∩ L(N) is __________. (GATE-2015) (2
Marks)
(A) 0

(B) 1

(C) 2

(D) 3
• If type is L = {am bn | m>=
www.knowledgegate.in www.knowledgegate.in

i, n>=j}, then no of states is i+j+2


www.knowledgegate.in www.knowledgegate.in

Q The FSM over an alphabet {a, b} shown in the figure accepts Q Definition of a language L with alphabet {a} is given as following.
L = {ank| k>0, and n is a positive integer constant}
What is the minimum number of states needed in DFA to recognize L? (NET-DEC-
2018) (2 Marks) (GATE-2011)
(A) k+1 (B) n+1 (C) 2(n+1) (D) 2(k+1)
a) all stings b) no stings
c) ϵ - alone d) None of these

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following set can be recognized by a deterministic Finite state Q Consider the set of strings on {0,1} in which, every substring of 3 symbols has at most two
Automation? (GATE–1998) (2 Marks) zeros. For example, 001110 and 011001 are in the language, but 100010 is not. All strings of
length less than 3 are also in the language. A partially completed DFA that accepts this language
a) The numbers 1,2,4, 2𝑛 , written in unary
is shown below. (GATE-2012) (2 Marks)

The missing arcs in the DFA are


b) The set of binary string in which the number of zeroes is the same as the
number of ones.

c) The numbers 1,2,4,8, 2𝑛 , written in binary

d) The set { 1, 101, 11011, 1110111,-------}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following deterministic finite state automaton M. Let S denote the set of seven- MINIMIZATION OF FINITE AUTOMATA
bit binary strings in which the first, the fourth, and the last bits are 1. The number of strings in S
• The process of removing states that do not affect the language-accepting capability of a deterministic finite
that are accepted by M is (GATE-2003) (2 Marks)
automaton (DFA). The result is a minimal deterministic finite automaton (MFA), which is unique for a given
(A) 1 (B) 5 (C) 7 (D) 8 language.
• Designing a minimal DFA directly can be difficult, so the recommended approach is to first design a DFA and then
minimize it.
• States in DFA can be classified as:
• Productive States: These states contribute to the machine’s ability to accept a language. Their presence
affects the language-accepting power.
• Non-Productive States: These states do not add any value to the language-accepting capability of the
machine and can be removed during minimization.
• NOTE- MFA is always unique for a language.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• NON- PRODUCTIVE STATES- These states don’t add anything to the language accepting power to the machine. • Equal State-These are those states that behave in same manner on each and every input
They can further be divided into three types, Dead State, Unreachable State, Equal State string. That is for any string w where w  * either both of the states will go to final state or
• Dead State- It is basically created to make the system complete, can be defined as a state from which there is no
both will go to non-final state. (remember the example of an equal state DFA).
transition possible to the final state. In a DFA there can be more than one dead state but logically always one
dead state is sufficient to complete the functionality. • More formally, two states ql and q2 are equivalent (denoted by q1≅ q2) if both δ (q1, x) and δ
(q2, x) are final states or both of them are non-final states for all x ∈ ∑*. If q1 and q2 are k-
• Unreachable Sate- It is that state which cannot be reached starting from initial state by parsing any input string. equivalent for all k ≥ 0, then they are k-equivalent.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Procedure of Minimization
• For this first of all, group all the non-final states in one set and all final states in another set.
• Now, on both the sets, individually check, whether any of the underlying elements (states) of
that particular set are behaving in the same way, that is are they having same transition(to
same set) on each input alphabet.
• if the answer is yes, then these two states are equal, otherwise not.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q IF a DFA is represented by the following transition table, then how


many states does the corresponding minimal DFA contains?
a) 2

b) 3

c) 4

d) 5

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Find weather the Conversion of the DFA below to MDFA is correct or not? Q A deterministic finite automation (DFA)D with alphabet {a, b} is given below (GATE-2011) (2
Marks)

Which of the following finite state machines is a valid minimal DFA which accepts the same
language as D?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

NON DETEMINISTIC FINITE AUTOMATA FORMAL DESCRIPTION OF NDFA


• Non-determinism in finite automata means that an automaton has multiple possible moves in • A Non-Deterministic finite automaton (NDFA) is a 5-tuple (Q,,,S,F) where:
a given state for a particular input. Unlike deterministic automata, where the next move is • Q is a finite and non-empty set of states
uniquely defined, non-deterministic automata allow for a set of possible transitions.
• Key points: •  is a finite non-empty set of finite input alphabet
• Choice of Moves: At any given step, the automaton can choose from multiple transitions •  is a transition function : Q ×  → 2Q
for the same input.
• Theoretical Concept: Non-deterministic machines are theoretical models, not meant to be • q0 is initial state (always one) (q0 Q)
physically implemented. They help simplify the design process but are not directly used in • F is a set of final states (F  Q) (0<=|F|<=N), where n is the number of states
practice.
• Purpose: NFAs are easier to design compared to deterministic automata (DFA), and every
NFA can be converted into an equivalent DFA for practical applications.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Some points to remember ACCEPTANCE BY NDFA
• Every DFA is also an NFA. Every NFA can be translated to an equivalent DFA, so their language • Let ‘w’ be any string defined over the alphabet , corresponding to w, there can be multiple
accepting capability is same Both only recognize regular languages. Accepting power of NDFA=
transitions for NFA starting from initial state, if there exist at least one transition for which we
Accepting power of DFA.
start at the initial state and ends in any One of the final state, then the string ‘w’ is said to be
• NFA need not to be a complete system. There can be a state that doesn’t have any transition on some accepted by the non-deterministic finite automata, otherwise not.
input symbol. A null transition is also possible for NFA, such special NFA are called Null-NFA. We will
discuss it later. • Mathematically, it can be represented as, L(M) = {w  * | *(q0, w) F}

• NDFA is a theoretical engine and is not implementable, but it is very easy to design compare
to DFA. No concept of dead state, therefore complementation of NFA is also not possible.
NDFA will respond for only valid strings and no need to respond for invalid strings. (it is a
Incomplete system)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q design a NDFA that accepts all strings over the alphabet ∑ = {a, b}, Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}.
where every accepted string ‘w’ starts with substring s, Where s = aba where every accepted string ‘w’ ends with substring ‘s’, Where s = bab

www.knowledgegate.in www.knowledgegate.in

conclusion→ if w = sx, |s| = m,www.knowledgegate.in


then no of states in the NDFA is m+1 conclusion→ if w = sx, |s| = m,www.knowledgegate.in
then no of states in the NDFA is m+1

Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, Q Let w be any string of length n is {0,1}*. Let L be the set of all substrings of w.
b}. where every accepted string ‘w’ contains sub string s, Where s = aba What is the minimum number of states in a non-deterministic finite automaton
that accepts L? (GATE-2010) (1 Marks)
(A) n-1 (B) n (C) n+1 (D) 2n-1

www.knowledgegate.in www.knowledgegate.in

conclusion→ if w = xsx, |s| = m, then no of states in the DFA is m+1


www.knowledgegate.in www.knowledgegate.in

Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b} such Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with same symbol. that every accepted string start and end with different symbol.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a minimal NDFA that accepts all strings over the alphabet ∑ = Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=SX , Where s = aaa/bbb {a, b} such that every accepted string w, is like w=XS , Where s = aaa/bbb

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ = Q Design a NFA that accepts all strings over the alphabet ∑ = {a, b}, such
{a, b} such that every accepted string w, is like w=XSX , Where s = that every string ‘w’ accepted must be like
aaa/bbb i) |w| = 3

ii) |w|<=3

iii) |w|>=3
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a NFA that accepts all strings over the alphabet ∑ = {a, Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain exactly two a’s. b}, such that every string accepted must contain at least two a’s.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a NFA that accepts all strings over the alphabet ∑ = {a, Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
b}, such that every string accepted must contain at most two a’s. such that for every accepted string 3rd from right end is always a.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The FSM shown in the figure accepts Q (GATE-2014) (2 Marks)

(A) {q0, q1, q2}

(B) {q0, q1}

a) all strings (C) {q0, q1, q2, q3}

b) no strings (D) {q3}

c) ϵ - alone

d) None of these
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following two finite automata. 𝑀1 accepts 𝐿1 and 𝑀2 Q Consider the non-deterministic finite automaton (NFA) shown in the figure.
accepts 𝐿2 Which one of the following is TRUE? (GATE-2008) (2 Marks) (GATE-2005) (2 Marks)
a) 𝐿1 = 𝐿2 State X is the starting state of the automaton. Let the language accepted by the
NFA with Y as the only accepting state be L1. Similarly, let the language accepted by
the NFA with Z as the only accepting state be L2. Which of the following statements
about L1 and L2 is TRUE?
b) 𝐿1 ⊂ 𝐿2 (A) L1 = L2 (B) L1 ⊂ L2 (C) L2 ⊂ L1 (D) None of the above

c) 𝐿1 ∩ 𝐿2 = ф

d) 𝐿1 ∪ 𝐿2 ≠ 𝐿1
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the NFAM shown below. (GATE–2003) (2 Marks) NFA and DFA Equivalence
Let the language accepted by M be L. Let 𝐿1 be the language accepted by the NFA • In this topic we will be learning about the equivalence of NFA and DFA and how an NFA can be
converted to equivalent DFA. Let us take an example and understand the conversion. Since
𝑀1 , obtained by changing the accepting state and by changing the non – accepting
every NFA and DFA has equal power that means, for every language if a NFA is possible, then
state of M to accepting states. Which of the following statements is True? DFA is also possible. So, every NFA can be converted to DFA. The process of conversion of an
a) 𝐿1 = {0, 1} * - L b) 𝐿1 = {0, 1} * c) 𝐿1 ⊂ L d) 𝐿1 = L NFA into a DFA is called Subset Construction.

• If NFA have ‘n’ states which is converted into DFA which ‘m’ states than the relationship
between n and m will be 1<= m <= 2n

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language. Procedure for Conversion
Which of the following in NECESSARILY true? (GATE-2008) (2 Marks)
• There lies a fixed algorithm for the NFA and DFA conversion. Following things must be
(A) m ≤ 2n (B) n ≤ m
considered
(C) M has one accept state (D) m = 2n
• Initial state will always remain same.
Q Given an arbitrary non-deterministic finite automaton (NFA) with N states, the maximum number of states in an
equivalent minimized DFA is at least (GATE-2001) (2 Marks) • Start the construction of ’ with the initial state & continue for every new state that comes
(A) N2 (B) 2N (C) 2N (D) N! under the input column and terminate the process whenever no new state appears under
the input column.
Q Let N be an NFA with n states. Let k be the number of states of a minimal DFA which is • Every subset of states that contain the final state of the NFA is a final state in the resulting
equivalent to N. Which one of the following is necessarily true? (GATE-2018) (1 Marks) DFA.
a) k ≥ 2n b) k ≥ n c) k ≤ n2 d) k ≤ 2n
• ’(q0 , q1, q2 , q3--------, qn-1,a) = ‫𝑛=𝑖ڂ‬−1
𝑖=0 ( qi , a)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
NFA WITH EPSILON MOVES (€-NFA) NULL-CLOSURE
• An automaton that consist of null transitions is called a Null- NFA i.e. we allow a transition on • Null closure of a set Q is defined as a set of all the states, which are at zero distance from the
null means empty string. state Q. A set of all the states, that can be reached from the state and along a null- transition.
• €-NFA is a 5-tuple (Q,,,S,F) where:
• Q is a finite and non-empty set of states • €-Closure(qi)- The set of all the states which are at zero distance from the state q i is called €-
closure(qi). Or the set of all the states that can be reached from the state qi along € labelled
•  is a finite non-empty set of finite input alphabet transition path, is known as €-closure(qi).

•  is a transition function : (Q × { U ε}) → 2Q

• S is initial state (always one) (S Q)

• F is a set of final states (F  Q) (0<=|F|<=N, where n is the number of states

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• Every state is at zero distance to itself. EQUIVALENCE BETWEEN NULL NFA TO NFA
• There will be no change in the initial state.
• In NFA or DFA, distance between two states is always 1, because there could be no null
transitions. • No change in the total no. of states

• The Null closure Q is always a non-empty and finite state, because every state’s null closure is • May be change in the number of final states.
that state only. • All the states will get the status of the final state in the resulting NFA, whose €-closure
contains at least one final state in the initial €-NFA.
• €-closure(Φ) = Φ

• €-closure (q0 , q1, q2 , q3--------, qn) =‫𝑛=𝑖ڂ‬


𝑖=0 ( €-closure(qi))

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q if the given NFA is converted to NFA without ϵ - moves, which of the following denotes
the set of final states?
a) {𝑞2 } b) {𝑞1 , 𝑞2 } c) {𝑞0, 𝑞1, 𝑞2} d) can’t be determined

Q Which of the following strings will not be accepted by the given NFA?
a) 00 11 22 b) 11 22 c) 21 d) 22

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let δ denote the transition function and δ’ denoted the extended transition Q Consider the following languages and find which of them are regular?
function of the ε-NFA whose transition table is given below: (GATE-2017) (2 Marks) 1. L = {am bn | m, n >=0}
Then, δ’ (q2, aba) is
a) Ø b) {q1, q2, q3} c) {q0, q1, q2} d) {q0, q2, q3}
2. L = {am bn cp | m, n, p >= 0}

3. L = {ax1bx2----zx26 | xi >= 0, 1 <= i <= 26}

4. L = {am bn | 1 <= m <= 100, 1 <= n <= 1200}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

1. L = {am bn | m*n = finite} 1. L = {am bn | m = n | m, n> = 0}

2. L = {am bn | m < n | m, n >= 0}


2. L = {an bn| 1 <= n <= 2|GATE|}
3. L = {am bn | m != n | m, n > 0}

3. L = {an bn| 1 <= n <= 237th prime} 4. L = {am bn | m is divisible by n}

5. L = {am bn | m = np, p>=1}


4. L = {am bn | m = n, 1 <= n <= 22^10}
6. L = {am bn | HCF(m, n)=1 | m, n >= 1}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

1. L = {am bn | m + n = even} 1. L = {w c wr | w  Σ*}

2. L = {w c w | w  Σ *}
2. L = {am bn cp | m = n = p}
3. L = {w c wr | w  Σ +}

4. L= {w c w | w  Σ +}
3. L = {am bn cp | m + p = n}
5. L = {w w | w  Σ *}

4. L = {am bn | m + n = odd} 6. L= {w wr | w  Σ +}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
1. L = {w c wr | c, w  Σ *} 1. L = {w c w | c, w  Σ *}

2. L = {c w wr | c, w  Σ *} 2. L = {c w w | c, w  Σ *}

3. L= {w w c | c, w  Σ *}
3. L= {w wr c | c, w  Σ *}

4. L = {w c w | c, w  Σ +}
4. L = {w c wr | c, w  Σ +

5. L = {c w wr | c, w  Σ +}
5. L = {c w w | c, w  Σ +}

6. L= {w wr c | c, w  Σ +} 6. L= {w w c | c, w  Σ +}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q If L is a regular language over ∑ = {a, b}, which one of the following languages is NOT regular? Q Which of the following languages is/are regular? (GATE-2015) (2 Marks)
(GATE-2019) (2 Marks) L1: {w x wR ⎪ w, x ∈ {a, b}* and ⎪w⎪, ⎪x⎪ >0} wR is the reverse of string w}
a) L⋅ LR = {xy | x ∈ L, yR ∈ L}
L2: {an bm ⎪m ≠ n and m, n≥0

b) Suffix (L) = {y ∈ ∑* | ∃x ∈ ∑* such that xy ∈ L}


L3: {ap bq cr ⎪ p, q, r ≥ 0}

c) Prefix (L) = {x ∈ ∑* | ∃y ∈ ∑* such that xy ∈ L}


(A) L1 and L3 only
(B) L2 only
(C) L2 and L3 only
d) {w wR | w ∈ L} (D) L3 only

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
GATECS2014Q15

Q Let L1 = {w ∈ {0, 1}∗ | w has at least as many occurrences of (110) ’s as (011)’s}.

Let L2 = {w ∈ {0, 1}∗ | w has at least as many occurrences of (000) ’s as (111)’s}. Which one of the following is CORRECT? (GATE-2014) (2 Marks)
(A) Only (I) (B) Only (II)
(C) Both (I) and (II) (D) Neither (I) nor (II)

Which one of the following is TRUE? (GATE-2014) (2 Marks)


(A) L1 is regular but not L2
(B) L2 is regular but not L1
(C) Both L2 and L1 are regular
(D) Neither L1 nor L2 are regular

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which one of the following is TRUE? (GATE-2014) (1 Marks) Q Let P be a regular language and Q be context-free language such that Q  P. (For
example, let P be the language represented by the regular expression p*q* and Q
be {pnqn |n  N}). Then which of the following is ALWAYS regular? (GATE-2011) (1
Marks)
(A) P ⋂ Q (B) P - Q (C)  *- P (D) * - Q

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following are regular sets? (GATE-2008) (2 Marks) Q Which of the following languages is (are) non-regular? (GATE-2008) (2 Marks)
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}

(A) I and IV only (B) I and III only


(A) L2 and L3 only
(C) I only (D) IV only (B) L1 and L2 only
(C) L3 only
(D) L2 only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following languages is regular? (GATE-2007) (2 Marks) Q Consider the following two statements (GATE-2001) (2 Marks)
GATECS2000Q4

a) {w wR |w ∈ {0, 1}+} b) {w wR x| x, w ∈ {0,1}+}

(A) Only S1 is correct (B) Only S2 is correct


(C) Both S1 and S2 are correct (D) None of S1 and S2 is correct
c) {w x wR |x, w ∈ {0,1}+} d) {x w wR| x, w ∈ {0,1}+}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following languages (GATE-2001) (2 Marks) Regular Expressions


• One way of describing regular language is via the notation of regular expression. An expression of
strings which represents regular language is called regular expression.
• The regular expressions are useful for representing certain sets of strings(Language) in an
algebraic fashion.

• We give a formal recursive definition of regular expressions over ∑ as follows:


• Any terminal symbol (i.e. an element of ∑), ∈ and Φ are regular expressions (Primitive regular
expressions).
Which of the languages are regular?
(A) Only L1 and L2 • A regular expression is valid iff it can be derived from a primitive regular expression by a finite
number of applications of operators.
(B) Only L2, L3 and L4
(C) Only L3 and L4
(D) Only L3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Regular Language:- Any set(language) represented by a regular expression is called a Regular Operators
language. If for example, a, b ∈ ∑, then When we view a in ∑ as a regular expression, we denote it by a.
• R = a denotes the L = {a}
• If R is a regular expression, then (R) is also a regular expression.
• R = a.b denotes L = {ab} concatenation
• The iteration (or closure) of a regular expression R written as R*, is also a regular expression.

• R = a + b denotes L = {a, b} Union • The iteration (or closure) of a regular expression R written as R+, is also a regular expression.

• The concatenation of two regular expressions R1 and R2, written as R1 R2, is also a regular
• R = a* denotes the set {∈, a, aa, aaa, ...} known as Kleene closure.
expression.
• R = a+ Positive closure {a, aa, aaa…} • The union of two regular expressions R1 and R2, written as R1 + R2, is also a regular expression.

• R =(a + b)* denotes {a, b}* • The precedence order to solve is ()Bracket, * (Kleene Closure), + Positive Closure,
Concatenation, Union.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
IDENTITIES FOR Regular Expression
हमारी language बताओ
• Two regular expressions P and Q are equivalent (we write P = Q) • R={a}
• if P and Q represent the same set of strings.
• Every regular expression can generate only one regular
language but, a regular language can be generated by more
• R={a + b}
than one regular expression I.e. means two different regular
expression can generate same language.
• R={a + b + c}
• Two regular expression are said to be equal if they generate same language.

• r1 = a* • R={a.b}
• r2 = a* + (aa)*
• R={a.b + a}b
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let S and T be language over Σ = {a, b} represented by the regular expressions FINITE AUTOMATA AND regular expression
(a + b*)* and (a + b)*, respectively. Which of the following is true? (GATE-2000) (1
Marks) Q Design a regular expression that represent a language ‘L’, where L={a}
(A) S ⊂ T over the alphabet ∑={a}.

(B) T ⊂ S

(C) S = T

(D) S ∩ T = φ

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q design a regular expression that represent all strings over the alphabet Q design a regular expression that represent all strings over the alphabet
∑ = {a, b}, where every accepted string ‘w’ starts with substring s ∑ = {a, b}. where every accepted string ‘w’ ends with substring ‘s’.
i) s = b ii) s = ab iii) s = abb i) s = ab ii) s = aa iii) s = bab

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}. where every accepted string ‘w’ contains sub string alphabet ∑ = {a, b} such that every accepted string start and end with a.
s.
i) abb ii) aba

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with alphabet ∑ = {a, b} such that every accepted string start and end with
same symbol. different symbol.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=SX. alphabet ∑ = {a, b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb i) s= aa/bb ii) s=aaa/bbb

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the alphabet ∑ = {a, b},
alphabet ∑ = {a, b} such that every accepted string w, is like w=XSX. such that every string ‘w’ accepted must be like
i) s= aa/bb ii) s=aaa/bbb i) |w| = 3 ii) |w|<=3 iii) |w|>=3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string accepted must contain exactly alphabet ∑ = {a, b}, such that every string accepted must contain at least
two a’s. two a’s.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string accepted must contain at most alphabet ∑ = {a, b} such that for every accepted string 2nd from left end is
two a’s. always b.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the alphabet ∑ = {a, b} Q Design a regular expression that represent all strings over the
such that for every accepted string 4th from right end is always a. alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 0(mod 3)?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 3(mod 4)? alphabet ∑= {a, b}, such that every string ‘w’ where |W|a = 0(mod 3)?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a regular expression that represent all strings over the Q L = {am bn | m, n >= 0}
alphabet ∑= {a, b}, such that every string ‘w’ where |W|a = 2(mod 3)?

Q L = {am bn | m>=1, n >= 1}

Q L = {am bn | m>=2, n >= 3}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q L = {am bn cp | m, n, p >= 1} Q Write a regular expression for the language, L = {w c wr |w, c ∈ {a, b}+}

Q L = {an bn | n >= 1}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q L = {am bn | m + n = even} Algebraic Properties of regular expression


Closure Property - regular expressions satisfy closure property with respect to Union,
Concatenation and kleene closure. If R1 and R2 are regular expression then the following will also
be regular expression.
r1 + r2

r1.r2

r1*

r1+
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Associative Property- regular expression satisfy associative property with respect Identity Property- The identity property is satisfied as follows-
to union and intersection

(r1 + r2) + r3 r1 + (r2 + r3) r. = r

r+ = r
(r1. r2). r3 r1. (r2. r3)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Inverse Property- The inverse property is not satisfied with respect to Commutative Property-regular expressions are commutative with
concatenation and union. respect to union but not with respect to concatenation.

r . =ε r1+ r2 r2+ r1

r + =ϕ r1. r2 r2. r1

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Distributive Property-regular expression satisfy this property as follows- Idempotent Property-regular expressions satisfies idempotent property
with respect to union but not with respect to concatenation.
r1(r2+r3) r1r2+r1r3

r1+r1 r1
(r1+r2) r3 r1r3+r2r3

r1+(r2. r3) (r1+r2)(r1+r3) r1. r1 r1


(r1.r2) + r3
www.knowledgegate.in
(r1 +r3). (r2 + r3) www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Identities for regular expressions 1. r*r* =
1. φ + r =
2. r. r* =
2. φ. r = r. φ =

3. ∈. r = r. ∈ = 3. r+. r* =
4. ∈ * =
4. r+ r+ =
5. ф * =
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

1. r+ U r* = 1. (r*)* =

2. (r+)*=
2. r+ ⋂ r* =

3. ((r+)*)* =

4. ((r*)*)r+ =
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

1. (r1+r2)* (r1* . r2*)*


1) (r1+r2)* (r1* + r2*)*
2. (r1+r2)* (r1 . r2*)*
2) (r1+r2)* (r1 + r2*)*
3. (r1+r2)* (r1* . r2)*
3) (r1+r2)* (r1* + r2) *
4. (r1+r2)* (r1 . r2)*

4) (r1+r2)* (r1* + r2*)


5. (r1+r2)* (r1* . r2*)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

r1(r2.r1)* (r1.r2)*r1 1. L(r*) = [L(r)]*

2. L(r+) = [L(r)]+

3. L(r1+r2) = L(r1) U L(r2)

4. L(r1.r2) = L(r1).L(r2)

5. L((r1)) = L(r1)
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following are equal Q Which of the following regular expressions represent(s) the set of all binary
a) a* b) (aa)* c) a(aa)* d) (a + ε) a* numbers that are divisible by three? Assume that the string ϵ is divisible by three.
(GATE 2021) (2 MARKS)

a) (0+1(01*0)*1)*

b) (0+11+10(1+00)*01)*

c) (0*(1(01*0)*1)*)*

d) (0+11+11(1+00)*00)*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which one of the following regular expressions represents the language: the set of all Q Consider the languages L1 = Φ and L2 = {a}. Which one of the
binary strings having two consecutive 0s and two consecutive 1s? (GATE-2016) (2 Marks)
following represents L1 L2*U L1* (GATE-2013) (1 Marks)?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which one of the following languages over the alphabet {0,1} is described by the regular Q Which of the following regular expressions describes the language over {0, 1}
expression: (0+1)*0(0+1)*0(0+1)*? (GATE-2009) (2 Marks) consisting of strings that contain exactly two 1’s? (GATE-2008) (1 Marks)
(A) The set of all strings containing the substring 00. (A) (0 + 1) * 11(0 + 1) * (B) 0 * 110 *

(B) The set of all strings containing at most two 0’s.

(C) 0 * 10 * 10 * (D) (0 + 1) * 1(0 + 1) * 1 (0 + 1) *


(C) The set of all strings containing at least two 0’s.

(D) The set of all strings that begin and end with either 0 or 1.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which one of the following regular expressions is NOT equivalent to Q The regular expression 0*(10*)* denotes the same set as (GATE-2003)
the regular expression (a + b + c) *? (GATE-2004) (2 Marks) (1 Marks)
(A) (a* + b* + c*)* (B) (a*b*c*)* (A) (1*0)*1* (B) 0 + (0 + 10)*

(C) ((ab)* + c*)* (D) (a*b* + c*)* (C) (0 + 1)* 10(0 + 1)* (D) none of these

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following is correct Q find the no of strings of length <= 3 generated by the (a + ab)+
a) (xx)*y = x(xy)* b) (xy)*x = x(yx)*

c) x(xy)* = (xx)*y d) (xy)* = (yx)*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q which of the following statements are correct EQUIVALENCE BETWEEN Regular Expression AND FINITE AUTOMATA
a) r*, r+ always represent finite language. • ARDEN’S THEOREM is the mechanism for the construction of a regular expression from a
finite automaton.

Q Consider a DFA and convert it into regular expression using Arden’s theorem?
b) r*, r+ always represent infinite language. (A, a) = A
(A, b) = B
(B, a) = B
(B, b) = B
c) r* = r+ if and only if r = ε A is the initial state and B Is the final state

d) r* = r+ = r if r = Ф

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider a DFA and convert it into regular expression using Arden’s theorem? • Steps used-
(A, b) = A • For, every individual state of the DFA, write an expression for every incoming and outgoing
input alphabet.
(A, b) = B
• Apply Arden’s theorem as follows-
(B, a) = C • If P is free from NULL, then equation R=Q+RP has unique solution, R=QP*
(C, b) = C • If P contains NULL, then equation R=Q+RP has infinitely many solutions.
A is the initial state and B,C Is the final state

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Conversion from Finite Automata to regular expression

Q Write regular expressions for the following machines

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the regular expressions given below represent the following Q Let L = {w ∈ (0 + 1)* | w has even number of 1s}, i.e. L is the set of all bit strings with even
number of 1s. Which one of the regular expression below represents L? (GATE-2010)(2 Marks)
DFA? (GATE-2014) (2 Marks)
I) 0*1(1+00*1)* II) 0*1*1+11*0*1 III) (0+1)*1 a) (0 * 10 * 1)* b) 0 * (10 * 10*)*

c) 0*(10 * 1*)*0* d) 0 * 1(10 * 1)*10*

(A) I and II only


(B) I and III only
(C) II and III only
(D) I, II, and III
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q If the final states and non-final states in the DFA below are interchanged, then which of the Q Consider the following Finite State Automaton. The language accepted by this
following languages over the alphabet {a, b} will be accepted by the new DFA? (GATE-2008) (1 Marks)
automaton is given by the regular expression (GATE-2007) (2 Marks)
(A) Set of all strings that do not end with ab

(B) Set of all strings that begin with either an a or a b

(C) Set of all strings that do not contain the substring ab

(D) The set described by the regular expression b*aa*(ba)*b*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the automata given in previous question. The minimum state automaton Q Which regular expression best describes the language accepted by the non-
equivalent to the above FSA has the following number of states (GATE-2007) (1 Marks) deterministic automaton below? (GATE-2006) (1 Marks)
(A) 1 (B) 2 (C) 3 (D) 4 (A) (a + b)* a(a + b)b

(B) (abb)*

(C) (a + b)* a(a + b)* b(a + b)*

(D) (a + b)*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Conversion from regular expression in Finite Automata iv) (R1*R2.R3*)


i) R*

v) R = a*b(ab)*
ii) (R1.R2)*

vi) R = (a + ba)*ab*
iii) (R1+R2)*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
vii) R = (aa + aaa)* 1. 0 * 10 * 10 *

2. ((ab)* + c*)*

viii) R = (a + aaaaa)*
3. (∈ + a + aa + aaa)b* + (a + b)* ba(a + b)*

4. 0*(10 * 1*)*0*
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

1. a*b(b * + aa*b)* Q Which one of the following regular expressions correctly represents the language of the finite
automaton given below? (GATE 2022) (1 MARKS)

(A) ab*bab* + ba*aba*

(B) (ab*b)*ab* + (ba*a)*ba*


2. ((11*0+0)(0 + 1)*0*1*) (C) (ab*b + ba*a)* (a* +b*)

(D) (ba*a + ab*b)*(ab* +ba*)

3. (ab+ bc+ acc).(a+ bc)*.( ∈+ bc*a)*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the language L given by the regular expression (a + b) *b(a +b) over the Q The number of states in the minimum sized DFA that accepts the language defined by
alphabet {a, b}. The smallest number of states needed in a deterministic finite- the regular expression (0+1)*(0+1)(0+1)* is __________________ (GATE-2016) (2 Marks)
state automaton (DFA) accepting L is ______. (GATE-2017) (1 Marks)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let T be the language represented by the regular expression Σ ∗0011Σ∗ where Σ = Q The number of states in the minimal deterministic finite automaton corresponding to
{0, 1}. What is the minimum number of states in a DFA that recognizes L’ the regular expression (0 + 1)*(10) is ____________ (GATE-2015) (1 Marks)
(complement of L)? (GATE-2015) (2 Marks) (A) 2 (B) 3 (C) 4 (D) 5
(A) 4 (B) 5 (C) 6 (D) 8

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The length of the shortest string NOT in the language (over Σ = {a, b}) of the Q Consider the DFA given. (GATE-2013) (2 Marks)
following regular expression is ______________. (GATE-2014) (2 Marks) Which of the following are FALSE?
1. Complement of L(A) is context-free.
a*b*(ba)*a*
(A) 2 (B) 3 (C) 4 (D) 5
2. L(A) = L((11*0+0)(0 + 1)*0*1*)

3. For the language accepted by A, A is the minimal DFA.

4. A accepts all strings over {0, 1} of length at least 2.

a) 1 and 3 only
b) 2 and 4 only
c) 2 and 3 only
d) 3 and 4 only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Match the following NFAs with the regular expressions they Q Consider the regular language L = (111 + 11111)*. The minimum
correspond to (GATE-2008) (2 Marks) number of states in any DFA accepting this language is: (GATE-2006) (1
Marks)
(A) 3 (B) 5 (C) 8 (D) 9

(A) P – 2, Q – 1, R – 3, S – 4
(B) P – 1, Q – 3, R – 2, S – 4
(C) P – 1, Q – 2, R – 3, S – 4
(D) P – 3, Q – 2, R – 1, S – 4
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following statements is TRUE about the regular expression 01*0? Q the string 1101 does not belong to the set
(GATE-2005) (1 Marks) a) 110*(0+1) b) 1(0+1)*101
(A) It represents a finite set of finite strings.

(B) It represents an infinite set of finite strings.

(C) It represents a finite set of infinite strings. c) (10)*(10)*(00+11)* d) (00 + (11)*01)*

(D) It represents an infinite set of infinite strings

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q which of the following re, over the Σ = {0, 1} denotes the set of all strings that Formal Grammar
not contain 100 as sub-string Language usually contains infinite number of strings. We cannot tabulate each and every string to
a) 0*(0+1)* b) 0*1010* c) 0*1*01 d) 0*(10+1)* represent the language, therefore like automata, grammar is also a mathematical model of representing a
language, using which we can generate the entire language. Therefore, a grammar is usually thought of as
a language generator. A phrase-structure grammar (or simply a grammar) is a 4-tuple (VN, ∑, P, S), where
• VN is a finite nonempty set whose elements are called variables,
• ∑ is a finite nonempty set whose elements are called terminals, V N ⋂ ∑= Ф.
• S is a special variable (i.e., an element of V N (S  Vn)) called the start symbol. Like every automaton has
exactly one initial state, similarly every grammar has exactly one start symbol.
• P is a finite set whose elements are α → β. where α and β are strings on V N ‫∑ ڂ‬. α has at least one
symbol from VN, the element of P are called productions or production rules or rewriting rules. {Σ U
Vn}* some writer refers it as total alphabet.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

For a formal valid production Some points to note about productions


• Reverse substitution is not permitted. For example, if S → AB is a production, then we can replace S by
α→β AB but we cannot replace AB by S.
• No inversion operation is permitted. For example, if S → AB is a production, it is not necessary that AB
→S is a production.
α  {Σ U Vn}* Vn {Σ U Vn}*
• To generate a string in the language, one begins with a string consisting of only a single start symbol.
β  {Σ U Vn}* The production rules are then applied in any order, until a string that contains neither the start symbol
nor designated nonterminal symbols is produced. A sequence of rule applications is called a derivation.
• A production rule is applied to a string by replacing one occurrence of the production rule’s left-hand
side in the string by that production rule’s right-hand side.
• L (G) is the set of all terminal strings derived from the start symbol S. G 1 and G2 are equivalent if L (G1)
= L (G2).

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Defining a language by grammar Chomsky Classification of Languages
• The concept of defining a language using grammar is, starting from a start symbol using the • Chomsky classified the grammars into four types in terms of productions (types 0-3). This hierarchy of
production rules of the grammar any time, deriving the string. Here every time during grammars was described by Noam Chomsky in 1956. From type 0 to type 3, we will be putting more
derivation a production is used as its LHS is replaced by its RHS, all the intermediate and more restrictions. The more restrictive the grammar, the easier the language will be to process;
stages(strings) are called sentential forms. The language formed by the grammar consists of all the more liberal the grammar, the more complex the language will become.
distinct strings that can be generated in this manner.
L (G) = {w | w  ∑* , S →* W}
• →*(reflexive, transitive closure) means from s we can derive w in zero or more steps

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
LANGUAGES AND AUTOMATA Type 0 Grammar
• Following are the machines that accepts the following grammars. • Also known as Unrestricted Grammar, phase structured grammar, recursively enumerable
grammar used to generate recursive enumerable language which is accepted by a Turing
machine.
• A type 0 grammar is without any restrictions.
• No restriction on the production rule, that is if there is a production from

α→β
α  {Σ U Vn}* Vn {Σ U Vn}*
β  {Σ U Vn}*

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Type 1 Grammar • As from the rule we can understand that we cannot have null production, in order to solve that
• Also known as case sensitive Grammar, length increasing grammar, non-contracting grammar, problem, Production S→, is allowed if S do not appear on the right-hand side of the
used to generate context sensitive language which is accepted by a linear bounded production.
automaton. • A grammar is called type 1 or context-sensitive or context dependent if all its productions are
type 1 productions.
αAβ→αδβ
α , β  {Σ U Vn}* A  Vn δ  {Σ U Vn}+
• Very difficult to have a parse tree
or
• FORTRAN, PL1 with CGF we use STD
α→β
α  {Σ U Vn}* Vn {Σ U Vn}*
β  {Σ U Vn}+
|α| <= |β|

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Type 2 Grammar Type 3 Grammar


• Also known as Context Free Grammar, which will generate context free language that will be
accepted by push down automata. (NPDA default case) • Used to generate Regular Grammar which will generate regular language which will be
• if there is a production, from accepted by finite machine.
• Regular grammar can be of two types either left linear or right linear.
α→β • Left regular grammar, support two types of production
α  Vn |α| = 1 A → a / Ba
β  {Σ U Vn} * A, B  Vn |A| = |B| = 1
a  ∑*
• In other words, the L.H.S. has no left context or right context.
• Right regular grammar
A → a / aB
• A grammar is called a type 2 grammar if it contains only type 2 productions. A, B  Vn |A| = |B| = 1
a  ∑*
• Eg ALGOL 60, PASCAL
• however, if left-linear rules and right-linear rules are combined,
the language need no longer be regular.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the grammar Q The basic limitation of FSM is that


S → aaaS | a | aa a) It cannot remember arbitrary large amount of information
L(G) =?
b) It sometimes fails to recognize grammars that are not regular

c) It sometimes fails to recognize grammars that are regular

d) All of these
a) L(G) = {w: |w| mod 3 = 0}

b) L(G) = {w: |w| mod 3 = 1 or 2}

c) L(G)= L(a*)

d) L(G) = L(a*)- (λ)


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following grammar and identify it’s language? Q Consider the following grammar and identify it’s language?
S → aAb S → AB / Bb

A → aB / b A→b/c

B→c B→d

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following grammar and identify it’s language? Q Consider the following grammar and identify it’s language?
S → aSb /  S → aA / abS

A → bS / b

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following grammar and identify it’s language? Q Consider the following grammar and identify it’s language?
S → aAB S → AB

A → aA /  A → aA / 

B→b B → bB / b

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following grammar and identify it’s language? Q If G is a grammar with productions
S → SaS | aSb | bSa | SS | ϵ
S → aSa / bSb /  where S is the start variable, then which one of the following strings is not
generated by G? (GATE-2017) (1 Marks)

(A) abab

(B) aaab

(C) abba

(D) babba

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following grammar (GATE – 2004) (2 Marks) Q Consider the regular grammar: (GATE-2005) (1 Marks)
S → bS | aA | b S → X a | Ya
A → bA | aB| X → Za
B → bB | aS| a Z → Sa | ϵ
Y → Wa
Let 𝑁𝑎 (w) and 𝑁𝑏 (w) denote the number of a’s and b’s in a string w respectively. The language
W → Sa
L(G)I {a, b}* generated by G is
a) {w | 𝑁𝑎 (w) > 3 𝑁𝑏 (w)} Where S is the starting symbol, the set of terminals is {a} and the set of non – terminals is {S, W,
X, Y, Z). We wish to construct a deterministic is (DFA) to recognize the same language. What is the
b) {w | 𝑁𝑏 (w) > 3 𝑁𝑎 (w)} minimum number of states required for the DFA?
a) 2
c) {w | 𝑁𝑏 (w) = 3k, k 𝐼መ {0, 1, 2,…….}} b) 3
c) 4
d) {w | 𝑁𝑎 (w) = 3k, k 𝐼መ {0, 1, 2,…….}} d) 5

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q What is the regular expression for the language generated by Q Write the grammar for the regular expression a*b*
S → aS | bA
A → d | ccA a) S → AB, A → aA | bB | ϵ, B → bB |aA | ϵ

b) S→ AB, A → aA | ϵ, B → bB | ϵ
a) a*bd
c) S → ab | ϵ, A → aA | ϵ, B → bB | ϵ
b) a* (bd)(bcc)* d
d) None of these
c) a* b(cc)* d

d) None of these
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q α → β and |α| ≤ |β| is a production rule for _________ grammar. Q Language L1 is defined by the grammar: S1 → aS1b | ε
Language L2 is defined by the grammar: S2 → abS2 | ε
Consider the following statements (GATE-2016) (2 Marks)
P: L1 is regular Q: L2 is regular
Which one of the following is TRUE?
(A) Both P and Q are true

(B) P is true and Q is false

(C) P is false and Q is true

(D) Both P and Q are false

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider alphabet ∑ = {0, 1}, the null/empty string ∈ and the sets of strings X0, X1 and Designing Grammar
X2 generated by the corresponding non-terminals of a regular grammar. X0, X1 and X2 are related
as follows (GATE-2015) (2 Marks) Q Design a grammar that generates a language ‘L’, where L={a} over the
X0 = 1 X1 X 1 = 0 X 1 + 1 X2 X2 = 0 X1 + {∈} alphabet ∑={a}.
Which one of the following choices precisely represents the strings in X0?

(A) 10 (0* + (10)*)1

(B) 10 (0* + (10)*)*1

(C) 1(0* + 10)*1

(D) 10 (0 + 10)*1 + 110 (0 + 10)*1


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}.
b}, where every accepted string ‘w’ starts with substring s where every accepted string ‘w’ ends with substring ‘s’.
i) s = b ii) s = ab iii) s = abb i) s = ab ii) s = aa iii) s = bab

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s. b} such that every accepted string start and end with a.
i) abb ii) aba

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with same symbol. b} such that every accepted string start and end with different symbol.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX. b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb i) s= aa/bb ii) s=aaa/bbb

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}, such
b} such that every accepted string w, is like w=XSX. that every string ‘w’ accepted must be like
i) s= aa/bb ii) s=aaa/bbb i) |w| = 3 ii) |w|<=3 iii) |w|>=3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain exactly two a’s. b}, such that every string accepted must contain at least two a’s.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at most two a’s. b} such that for every accepted string 2nd from left end is always b.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑ = {a, b} such that Q Design a grammar that generates all strings over the alphabet ∑= {a,
for every accepted string 4th from right end is always a. b}, such that every string ‘w’ where |W| = 0(mod 3)?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑= {a, Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 3(mod 4)? b}, such that every string ‘w’ where |W|a = 0(mod 3)?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a grammar that generates all strings over the alphabet ∑= {a, Q Consider the following Left recursive grammar and convert them into
b}, such that every string ‘w’ where |W|a = 2(mod 3)? Regular Expression?

A → Aα / β
A → Aα / β1 / β2
A → Aα / β1 / β2 -------/ βn

• We actually did Regular Expression to Grammar


www.knowledgegate.in www.knowledgegate.in

• Regular Grammar to Regular Expression


www.knowledgegate.in www.knowledgegate.in

A → Aα1 / Aα2 / β A → Aα1 / Aα2 /----------Aαn / β1 / β2 -------/ βm


A → Aα1 / Aα2 /----------Aαn / β

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

S → 01S / 01 S → 0011S / 01 / 10

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

S → 01A / B11 S → 011A / 101B


A →011A / 01 A →110A / 00
B → 101B / 11 B → 11B / S

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in Regular Grammar to (Finite Automata)


www.knowledgegate.in
S → 01S / 1 S → 011S / 01

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

S → 001S / 10A • Reverse the right hand side of every production.


• Construct the NFA.
A → 101A / 0 / 1 • Interchange initial and final state.
• Change the direction if edges.

S → S10 / 01

• We actually did Right Regular Grammar to (Finite Automata)


www.knowledgegate.in www.knowledgegate.in

• Left Regular Grammar to (Finite Automata)


www.knowledgegate.in www.knowledgegate.in
• Finite Automata to Regular Grammar • Obtain the regular Expression
• Reverse the regular Expression
• Construct the finite automata
• Construct the right regular grammar
• Reverse right hand side of every production

• We actually did (Finite Automata) To Right Regular Grammar


www.knowledgegate.in www.knowledgegate.in

• Finite Automata to Left Regularwww.knowledgegate.in


Grammar www.knowledgegate.in
• Every Left regular grammar can be converted into right regular and every right regular What computer science deals with?
grammar can be converted into left regular grammar.
• Procedure to convert Right linear grammar to Left linear grammar • Don’t
• Obtain the RE from the grammar • So we do not study how to design a computer
• Reverse the RE • We do not study how to run a computer
• Construct the finite automata for the regular expression • Do
• Now construct the right linear grammar • We deal with problem solving, according to computer science a problem can be divided
• Reverse the left hand side of every production to get a left linear grammar. as follows
PROBLEM

SOLVABLE UNSOLVABLE

DECIDABLE UNDECIDABLE

www.knowledgegate.in www.knowledgegate.in P TYPE NP TYPE

www.knowledgegate.in www.knowledgegate.in

Konigsberg Bridge Problem • SOLVABLE - A problem is said to be solvable if either we can solve it or if we can prove that the
problem cannot be solved.

• UNSOLVABLE - A problem is said to be unsolvable if neither we can solve it, nor we can proof
that the problem can not be solved.

• P- if there exist a polynomial time algorithm to solve a problem then problem is said to be
decidable.

• NP- if there exist a non- polynomial time algo to solve a problem.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Decision properties Emptiness & Non-emptiness
• Approximately all the properties are decidable in case a finite automaton. Here • Step 1: - select the state that cannot be reached from the initial states & delete them (remove
we will use machine model to proof decision properties. unreachable states)

i) Emptiness • Step 2: - if the resulting machine contains at least one final states, so then the finite automata
accepts the non-empty language.
ii) Non-emptiness
• Step 3: - if the resulting machine is free from final state, then finite automata accepts empty
iii) Finiteness language.

iv) Infiniteness

v) Membership

vi) Equality

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Finiteness & Infiniteness Membership


• Step 1: - Select the state that cannot be reached from the initial state & delete them (remove • Membership is a property to verify an arbitrary string is accepted by a finite automaton or not
unreachable states) i.e. it is a member of the language or not.
• Step 2: - Select the state from which we cannot reach the final state & delete them (remove • Let M is a finite automata that accepts some strings over an alphabet, and let ‘w’ be any string
dead states) defined over the alphabet, if there exist a transition path in M, which starts at initial state &
ends in anyone of the final state, then string ‘w’ is a member of M, otherwise ‘w’ is not a
• Step 3: - If the resulting machine contains loops or cycles then the finite automata accepts
infinite language member of M.

• Step 4: - If the resulting machine do not contain loops or cycles then the finite automata
accepts finite language.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Equality RL DCFL CFL CSL RS RES


• Two finite state automata M1 & M2 is said to be equal if and only if, they accept Emptiness Y Y Y X N N
the same language.
• Minimise the finite state automata and and the minimal DFA will be unique.
Non-Emptiness Y Y Y X N N
Finiteness Y Y Y X N N
Infiniteness Y Y Y X N N
Membership Y Y Y X Y N
Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in Halting Y Ywww.knowledgegate.in


Y X Y N
Closure Properties of Regular Languages Q Consider the following two statements about regular languages:
• Regular languages are closed under following operations
● S1: Every infinite regular language contains an undecidable language as a subset.
● S2: Every finite language is regular.
• Kleen Closure
Which one of the following choices is correct? (GATE 2021) (2 MARKS)
• Positive closure
• Complement (a) Only S1 is true
• Reverse Operator
(b) Only S2 is true
• Prefix Operator
• Suffix operator (c) Both S1 and S2 are true
• Concatenation
• Union (d) Neither S1 nor S2 is true
• Intersection
• Set Difference operator
• Symmetric Difference

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q If L is a regular language over ∑ = {a, b}, which one of the following languages Q Consider the following two statements (GATE-2016) (1 Marks)
is NOT regular? (GATE – 2019) (1 Marks) I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ ∗.

a) L⋅ LR {xy | x ∈ L, yR∈ L} II. There exists a regular language A such that for all languages B, A ∩ B is regular.
Which one of the following is CORRECT?

b) Suffix (L) = {y ∈ ∑* | ∃x ∈ ∑* such that xy ∈ L}

(A) Only I is true


c) Prefix (L) = {x ∈ ∑* | ∃y ∈ ∑* such that xy ∈ L} (B) Only II is true
(C) Both I and II are true
d) {w
www.knowledgegate.in
wR | w ∈ L} (D) Both I and II are false
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following is TRUE? (GATE-2007) (2 Marks) Q Which of the following is true? (GATE – 2007) (1 Marks)
a) Every subset of a regular set is regular. a) Infinite union of regular set is regular
b) The union of two non-regular sets is not regular. b) The union of two non-regular net is not regular
c) Every finite subset of a non-regular set is regular. c) finite union of infinite set is regular
d) Infinite union of finite sets is regular d) every R.L is also C.F.L

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following statements about regular languages is NOT true? (GATE- Q Which of the following statement is false? (GATE – 1998) (1 Marks)
2006) (1-Marks) a) Every finite subset of a non – regular set is regular
a) Every language has a regular superset b) Every subset of a regular set is regular
b) Every language has a regular subset c) Every finite subset of a regular set is regular
c) Every subset of a regular language is regular d) The intersection of two regular sets in regular
d) Every subset of a finite language is regular

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let 𝐿1 and 𝐿2 are regular sets defined over alphabet ∑*. Mark the Q Which of the following statements are true?
false statement
i) The complement of a language is always regular

a) 𝐿1 ∪ 𝐿2 is regular b) 𝐿1 ∩ 𝐿2 is not regular ii) The intersection of regular languages is regular


iii) The complement of a regular language is regular

c) ∑* -𝐿1 is regular d) 𝐿1 ∗ is regular


a) i) and ii) only
b) ii) and iii) only
c) i) and iii) only

www.knowledgegate.in
d) All of the above
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

RL DCFL CFL CSL RS RES RL DCFL CFL CSL RS RES


Union Y N Y Y Y Y Homomorphism Y N Y N N Y
Intersection Y N N Y Y Y
∈ Free Homomorphism
Complement Y Y N Y Y N Y N Y Y Y Y
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y Inverse Homomorphism Y Y Y Y Y Y
Positive Closure Y N Y Y Y Y Substitution
Y N Y N N Y
Concatenation Y N Y Y Y Y
Intersection
with regular set Y Y Y Y Y Y ∈ Free Substitution Y N Y Y Y Y
Reverse Y Y Y Y Y Y
www.knowledgegate.in

Subset N Nwww.knowledgegate.in
N N N N
Quotient with regular set
www.knowledgegate.in
Y Y
www.knowledgegate.in
Y N Y Y
Moore and Mealy Machine Moore Machine
• Both moore and mealy machine are special case of DFA
• Both acts like o/p producers rather than language acceptors A Moore machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where
• In moore and mealy machine no need to define the final states
• No concepts of dead states and no concepts of final states • Q is a finite set of states:
• Mealy and Moore Machines are equivalent in power.
• ∑ is the input alphabet:
• Δ is the output alphabet.
• δ is the transition function Q x ∑ into Q
• λ is the output function mapping Q into Δ and
• q0 is the initial state.

George H Mealy Edward F Moore


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Examples: The below table shows the transition table of a Moore Machine. Q construct a Moore machine take all the string of a’s and b’s as i/p and
counts the no of a’s in the i/p string in terms of 1, ∑ = {a, b}, Δ = {0, 1}?

• In moore machine for every state output is associated. If the length of i/p string is n, then
www.knowledgegate.in www.knowledgegate.in

length of o/p string will be n+1. Moore machine response for empty string .
www.knowledgegate.in www.knowledgegate.in

Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the
no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}? no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q construct a Moore machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give Mealy Machine
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise? • Mealy machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where all the symbols except λ have the same

meaning as in the Moore machine. λ is the output function mapping Q x ∑ into Δ.

• In case of mealy machine, the output symbol depends on the transition.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Example: The below table shows the transition table of a Mealy Machine. Q construct a Mealy machine take all the string of a’s and b’s as i/p and
counts the no of a’s in the i/p string in terms of 1, ∑ = {a, b}, Δ = {0, 1}?

www.knowledgegate.in www.knowledgegate.in

• If the length of i/p string is n, then length ofwww.knowledgegate.in


o/p string will be n.Mealy machine do not response for empty string . www.knowledgegate.in

Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts the
the no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}? no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q construct a Mealy machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give CONVERSION OF MOORE TO MEALY MACHINE
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise? • Let us take an example to understand the conversion:
• Convert the following Moore machine into its equivalent Mealy machine.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• To convert a mealy machine to moore machine all you need to do is just push out the outputs PROCEDURE FOR TRANSFORMING A MEALY MACHINE INTO A MOORE MACHINE
of states onto to the incoming transitions. Consider the Mealy Machine:
• While conversion from moore to mealy machine, the number of states will we same and there
will be no extra states.
• The equivalent Moore Machine will be:

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Given the following state table of an FSM with two states A and B, one input and one output: Q The following diagram represents a finite state machine which takes as input a binary number
If the initial state is A=0, B=0, what is the minimum length of an input string which will take the from the least significant bit. (GATE-2005) (1 Marks)
machine to the state A=0, B=1 with Output = 1? (GATE-2009) (2 Marks) Which one of the following is TRUE?
(A) 3 (B) 4 (C) 5 (D) 6
(A) It computes 1’s complement of the input number
Present Present Next Next
I/p O/p
State A State B State A State B (B) It computes 2’s complement of the input number
0 0 0 0 0 1
(C) It increments the input number
0 1 0 1 0 0
1 0 0 0 1 0 (D) It decrements the input number
1 1 0 1 0 0
0 0 1 0 1 0
0 1 1 0 0 1
1 0 1 0 1 1
1 1 1 0 0 1

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q The Finite state machine described by the following state diagram with A as starting state, Q Suppose we want to design a synchronous circuit that processes a string of 0’s and 1’s. Given a string, it produces another
string by replacing the first 1 in any subsequence of consecutive 1’s by a 0. Consider the following example.
where an arc label is x / y and x stand for 1-bit input and y stands for 2- bit output (GATE-2002) (2 Input sequence : 00100011000011100
Marks) Output sequence : 00000001000001100
A Mealy Machine is a state machine where both the next state and the output are functions of the present state and the current
(A) Outputs the sum of the present and the previous bits of the input. input. The above mentioned circuit can be designed as a two-state Mealy machine. The states in the Mealy machine can be
represented using Boolean values 0 and 1. We denote the current state, the next state, the next incoming bit, and the output bit
of the Mealy machine by the variables s,t,b and y respectively. Assume the initial state of the Mealy machine is 0. What are the
(B) Outputs 01 whenever the input sequence contains 11. Boolean expressions corresponding to t and y in terms of s and b? (GATE 2021) (2 MARKS)

(C) Outputs 00 whenever the input sequence contains 10. (a) t = s+b y = sb

(D) None of these (b) t = b y = sb

(c) t = b y = sb’

(d) t = s+b y = sb'

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Pumping Lemma For Regular Languages Pumping Lemma For Regular Languages
• Pumping Lemma is used as a proof for irregularity of a language. Thus, if a language is regular, it always satisfies • For any regular language L, there exists an integer n, such that for all z ∈ L with |z| ≥ n, there
pumping lemma. If there exists at least one string made from pumping which is not in L, then L is surely not exists u, v, w ∈ Σ∗, such that z = uvw, and
regular. o |uv| ≤ n
• The opposite of this may not always be true. That is, if Pumping Lemma holds, it does not mean that the
o |v| ≥ 1
o for all i ≥ 0: uviw ∈ L
language is regular.
• Pumping Lemma is used to prove that some of the language is non-regular.
• For the pumping lemma, i/p is NRL & o/p is also NRL. • In simple terms, this means that if a string v is ‘pumped’, i.e., if v is inserted any number of
times, the resultant string still remains in L.

Pumping Lemma
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Process of pumping Lemma Q Proof that language L = {ambn | m=n} is non-regular?
• Suppose that we need to prove that language L is a non-regular.
• Assume that L is a regular language, then L must satisfy pumping lemma property. L = {ab, aabb, aaabbb, aaaabbbb, ---}
• Choose z ∈ L such that |z| <= n, split z into 3 parts.
o |uv| ≤ n
z∈L
o |v| ≥ 1 Z = akbk

o If there exist at least one variable for i such that uviw ∉ L, then L does not satisfy pumping
lemma property so it is a contradiction, therefore language L is non-regular. For i=1 → uviw → akbk
For i=2 → uviw → ak+1bk ∉ L

There for L is not regular

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Proof that language L = {ambn | m<n} is non-regular? Q Proof that language L = {anbn | n is a prime number} ?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Proof that language L = {an^2 | n>= 0} ? Q For Σ = {a, b}, let us consider the regular language
L = {x ∣ x = a2 + 3k or x = b10 + 12k, k ≥ 0}
Which one of the following can be a pumping length (the constant guaranteed by the pumping
lemma) for L? (GATE- 2019)

(A) 3 (B) 5 (C) 9 (D) 24

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

CONTEXT-FREE LANGUAGES AND PUSH DOWN AUTOMATA BLOCK DIAGRAM OF PDA


• Finite control unit is also called as memory unit it is static and limited. So to process the i/p string if the static
• We Already understand the limitation of finite automata, that it cannot do the infinite comparison memory is not sufficient then we can use the stack.
between the symbols.
• i/p tape is divided into cells where is cell is capable of holding one symbol at a time. At stack of infinite size, which
• Let us consider L = {an bn | n >= 1}. This is not regular, as it has to remember the number of a's in a support three operations push, pop and skip.
string and so it will require an infinite number of states, which is logically not possible.
• The accepting power of a pda is more than that of finite automata and less than that of linear bounder automata
• This difficulty can be avoided by adding an auxiliary memory in the form of a 'stack'. The reason we
choose stack because it is the simplest memory possible. • The power of non-deterministic pda is more than the power of deterministic pda.

• This type of arrangement where a finite automaton has a stack leads to the generation of a
pushdown automaton.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Formal Definition of DPDA Representation of States


A DPDA is a 7-tuple, namely (Q, ∑, Γ, δ, q0, Z0, F), where
(1) PUSH – one symbol can be inserted into the stack at one time.
(i) Q – is a finite nonempty set of states, δ(qi, a, z0) = (qj, az0)
(ii) ∑ – is a finite nonempty set of input symbols,
(iii) Γ – is a finite nonempty set of pushdown symbols,
(iv) q0 – is a special state called the initial state,
(v) Z0 – is a special pushdown symbol called the initial symbol on the pushdown store.
(vi) F – is a set of final states, a subset of Q and
(vii) δ – is a transition function from Q x (∑ U {∈}) x Γ to the set of finite subsets of Q x Γ*.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Representation of States Representation of States
(2) POP – one symbol can be deleted from the stack at one time. (3) SKIP – IT means no stack operation, status of the stack will remain same, before
δ(qi, a, z0) = (qj, ε) a after the operation
δ(qi, a, z0) = (qj, z0)

note- if pda perform a push or a pop operation at least one’s during processing of
string than we say that pda is using the stack.
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Instantaneous Description (ID) Q Design a Deterministic Push Down Automata for L = {a, ab}?
• An instantaneous description (ID) is (q, x, α), where q ∈ Q, x ∈ ∑* and α ∈ Γ*.

• An initial ID is (q0, x, Z0), this means that initially the pda is in the initial state q0, the input
string to be processed is x and the PDS has only one symbol, namely Z0.

• ACCEPTANCE BY PDA There is no change in the language acceptance


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in
capability of the pda either we accept by final state of empty stack. www.knowledgegate.in

Q Design a Deterministic Push Down Automata for L = {a bn | n >= 0}? Q Design a Deterministic Push Down Automata for {an bn | n >= 1} ?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a Deterministic Push Down Automata for {an b2n | n >= 1} ? Q Design a PDA for {w c wr | w ∈(a, b)*} ?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Construct PDA that accepts L = {|w|a = b | w € (a, b)*} ? Q consider the following mapping and find the correct language?
δ (q0, 1, z0) = (q0, xz0)
δ (q0, 1, x) = (q0, xx)
δ (q0, 0, x) = (q1, €)
δ (q1, 0, x) = (q1, €)
δ (q1, €, x) = (q1, €)
δ (q1, €, z0) = (qF, z0)

a) L = {am bn | m = n}
b) L = {am bn | m != n}
c) L = {am bn | m >= n}
d) L = {am bn | m <= n}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q consider the following mapping and find the correct language? Non- Deterministic PDA
δ (q0, a, z0) = (q1, z0)
δ (q0, b, z0) = (q2, z0) • Non- Deterministic PDA can also be defined using 7 tuples.
δ (q1, a, z0) = (q1, z0) • δ: Q x {∑ U ∈} x Γ → 2(Q x Γ* )

δ (q1, b, z0) = (q2, z0) • i.e. on a given input symbol and stack symbol a NPDA can move to more than one state.
δ (q2, a, z0) = (q2, z0)
• Rest all other tuples are same as DPDA.
δ (q2, b, z0) = (q0, z0)
δ (q1, €, z0) = (qf, z0)

a) ending with a
b) ending with a, contain even number of a
c) ending with a, contain odd number of a
d) ending with a, contain even number of b
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Construct pda that accepts a language L = {w wr | w € (a, b)*}?


(GATE-2021)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q In a pushdown automaton P=(Q,Σ,Γ,δ,q0,F), a transition of the form, Q Which one of the following languages over ∑ = {a, b} is NOT context-free?
(GATE-2019) (2 Marks)
where p,q∈Q, a∈σ∪{ϵ}, X,Y,∈Γ∪{ϵ}, represents
(q,Y) ∈ δ(p,a,X) a) {an bi | i ∈ {n, 3n, 5n}, n≥ 0} b) {w an wR bn | w ∈ {a, b}*, n≥ 0}
Consider the following pushdown automaton over the input alphabet Σ={a,b} and stack alphabet Γ={#,A}.

c) {w wR | w ∈ {a, b}*} d) {wan bn wR | w ∈ {a, b}*, n≥ 0}

The number of strings of length 100 accepted by the above pushdown automaton is ___________ .(GATE
2021) (2 MARKS)

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following languages: Linear Grammar in Computer Science

I. m + p = n + q, where m, n, p, q ≥ 0}
{am bn cp dq ∣ • A linear grammar is a type of context-free grammar where each production's right-hand side contains at most
one nonterminal symbol.
II. {am bn cp dq ∣ m = n and p = q, where m, n, p, q ≥ 0} • Example of a simple linear grammar:
• Let G be a grammar with nonterminal set N={S}, terminal set Σ={a,b}, and the start symbol S.
III. {am bn cp dq ∣ m = n = p and p ≠ q, where m, n, p, q ≥ 0} • Production rules:
• S→aSb
IV. {am bn cp dq ∣ mn = p + q, where m, n, p, q ≥ 0} • S→ε
• This grammar generates the language L={anbn∣n≥0}, which is a linear language.
• Types of Linear Grammars:
• Left-Linear Grammars: Nonterminal symbols appear only at the left ends of the right-hand sides.
• Right-Linear Grammars: Nonterminal symbols appear only at the right ends of the right-hand sides.
• Both left-linear and right-linear grammars generate regular languages.
Which of the above languages are context-free?
(GATE-2018) (2 Marks)
a) I and IV only b) I and II only
c) II and III only d) II and IV only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• General Linear Grammars:
• Relation to Other Languages:
• Nonterminal symbols can appear at either end of the production, but not necessarily always at the same • All regular languages are linear, but not all linear languages are regular. For example,
end. {anbn∣n≥0} is linear but non-regular.
• Any linear grammar can be transformed into this form without changing the language generated. • All linear languages are context-free, but not all context-free languages are linear. For
• For example, the grammar: example, the well-balanced bracket language is context-free but not linear.
• S→aAS
• A→SbA
• Determinism and Complexity:
• S→ε • Regular linear languages are deterministic, but some linear languages are
• generates the same language as the example above. nondeterministic.
• For example, the language of even-length palindromes (generated by the grammar
S→0S0∣1S1∣ε) is nondeterministic.
• Nondeterministic linear languages cannot always be recognized in linear time.
• Moreover, it is undecidable whether a given context-free language is linear.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the transition diagram of a PDA given below with input alphabet &Sum; = {a, b}and Q Consider the following languages (GATE-2016) (1 Marks)
stack alphabet &Gamma; = {X, Z}. Z is the initial stack symbol. Let L denote the language L1 = {an bm cn: m, n >= 1}
accepted by the PDA. (GATE-2016) (2 Marks)

L2 = {an bn c2n: n >= 1}

Which one of the following is TRUE?


(A) Both L1 and L2 are context-free
(B) L1 is context-free while L2 is not context-free.
(C) L2 is context-free while L1 is not context-free
(D) Neither L1 nor L2 is context-free.
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following languages are context-free? (GATE-2015) (2 Marks)


L1 = {am bn an bm ⎪ m, n ≥ 1}

L2 = {am bn am bn ⎪ m, n ≥ 1}

L3 = {am bn ⎪ m = 2n + 1}

Here, wr is the reverse of the string w. Which of these languages are deterministic Context-free
(A) L1 and L2 only (B) L1 and L3 only languages? (GATE-2014) (2 Marks)
(A) None of the languages (B) Only L1
(C) L2 and L3 only (D) L3 only
(C) Only L1 and L2 (D) All the three languages
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the language L1, L2, L3 as given below. (GATE-2011) (2 Marks) Q Consider the languages (GATE-2010) (2 Marks)
L1 = {ap bq | p, q N} L1 = {0i 1j | i != j} L2 = {0i 1j | i = j}

L2 = {ap bq | p, q N and p=q}

L3 = {0i 1j | i = 2j+1} L4 = {0i 1j | i != 2j}


L3 = {ap bq cr | p, q, r N and p = q = r}

Which of the following statements is NOT TRUE?


(A) Only L2 is context free
(A) Push Down Automata (PDA) can be used to recognize L1 and L2
(B) L1 is a regular language (B) Only L2 and L3 are context free
(C) All the three languages are context free (C) Only L1 and L2 are context free
(D) Turing machine can be used to recognize all the three languages (D) All are context free
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which one of the following is FALSE? (GATE-2009) (2 Marks) Q Consider the following languages. (GATE-2008) (2 Marks)
(A) There is unique minimal DFA for every regular language L1 = {ai bj ck | i = j, k ≥ 1} L2 = {ai bj | j = 2i, i ≥ 0}
(B) Every NFA can be converted to an equivalent PDA.
(C) Complement of every context-free language is recursive. Which of the following is true?
(D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA.
(A) L1 is not a CFL but L2 is

(B) L1 ∩ L2 = ∅ and L1 is non-regular

(C) L1 ∩ L2 is not a CFL but L2 is

(D) There is a 4-state PDA that accepts L1,

www.knowledgegate.in
but there is no DPDA that accepts L2
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The language L = {0i21i | i≥0} over the alphabet {0,1, 2} is: (GATE-2007) (2 Marks) Q (GATE-2006) (1 Marks)
a) not recursive.
b) is recursive and is a deterministic CFL.
c) is a regular language.
d) is not a deterministic CFL but a CFL

(A) L1 only (B) L3 Only


(C) L1 and L2 (D) L2 and L3
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the languages: (GATE-2005) (2 Marks) Q Let Nf and Np denote the classes of languages accepted by non-deterministic finite automata
L1 = {w wR |w ∈ {0, 1}*} and non-deterministic push-down automata, respectively. Let Df and Dp denote the classes of
languages accepted by deterministic finite automata and deterministic push-down automata,
respectively. Which one of the following is TRUE? (GATE-2005) (1 Marks)

L2 = {w # wR | w ∈ {0, 1}*}, where # is a special symbol


(A) Df ⊂ Nf and Dp ⊂ Np (B) Df ⊂ Nf and Dp = Np

L3 = {w w | w ∈ (0, 1}*)
(C) Df = Nf and Dp = Np (D) Df = Nf and Dp ⊂ Np

Which one of the following is TRUE?


(A) L1 is a deterministic CFL
(B) L2 is a deterministic CFL
(C) L3 is a CFL, but not a deterministic CFL
(D) L3 is a deterministic CFL
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The language {0𝑛 12𝑛 | 1 ≤ n ≤ 106 } is: (GATE – 2005) (1 Marks) Q The language {am bn Cm+n | m, n ≥ 1} is (GATE-2004) (1 Marks)

(A) regular
a) Regular
(B) context-free but not regular
b) Context free but not regular
c) Context free but its complement is not context free (C) context sensitive but not context free
d) Not context free
www.knowledgegate.in
(D) type-0 but not context sensitive
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The language accepted by a Pushdown Automation in which the stack is Q Which of the following language over {a, b, c} is accepted by a deterministic
limited to 10 items is best described as (GATE-2003) (1 Marks) pushdown automaton? (GATE – 1997) (1 Marks)
a) {w ⊂ 𝑤 𝑅 | w ϵ {a, b) *} b) {𝑤𝑤 𝑅 | w ϵ {a, b, c) *}
(A) Context Free (B) Regular

(C) Deterministic Context Free (D) Recursive

c) { 𝑎𝑛 𝑏𝑛 𝑐 𝑛 | n ≥ 0} d) {w| w is a palindrome over {a, b, c}}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following set of languages Q The languages


𝑳𝟏 = 𝑎 𝑚 𝑏 𝑛 | n = 𝑚 2 𝑳𝟐 = 𝑎 𝑚 𝑏 𝑚 𝑐 𝑚 𝑑 𝑛 | m, n > 0 𝑳𝟑 = 𝑎 𝑚 𝑏 𝑚 𝑐 𝑛 𝑑 𝑛 | m, n > 0 1. {0n 1n | n>=1} and 2. { 0n 12n | n >= 1} U {0n 1n | n >= 1} are

a) both accepted by deterministic push down automata

b) 1can be accepted by a DPDA but 2 requires a NDPDA


Which of the above language is not context free?
a) 𝐿1 and 𝐿3 b) 𝐿2 and 𝐿3 c) 2 can be accepted by a DPDA but 1 requires a NDPDA

c) 𝐿1 and 𝐿2 d) All 𝐿1 , 𝐿2 and 𝐿3 d) None of the above


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let M = ({q0, q1}, {0, 1}, (Z0, X), , q0, Z0, ) be a pushdown automata where  is Q A PDM behaves like a TM when the number of auxiliary memories it
given by has, is
(q0, 1, Z0) = {(q0, XZ0)} a) 0
(q1, , Z0) = {(q0, )}
(q0, 1, X) = {(q0, XX)} b) 1 or more
(q1, 1, X) = {(q1, )}
(q0, 0, X) = {(q1, X)} c) 2 or more
The language defined by above PDA is
d) none of these
a) {1n 01n | n  1}
b) {1n 01n 0 | n  1}
c) {1m 01m + 1 | m  1}
d) None
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following languages can’t be accepted by a deterministic PDA? Q Which of the following languages is accepted by a non – deterministic pushdown
automaton (PDA) but NOT by a deterministic PDA?
a) The set of palindromes over alphabet {a, b} a) {an bn c n |n ≥ 0} b) {a1 bm c n |l ≠ m or m ≠ n}

b) The set of all strings of balanced parenthesis

c) L = {W c 𝑊 𝑅 |𝑊 𝑖𝑛 0 + 1 ∗} c) {an bn |n ≥ 0} d) {an bn |m, n ≥ 0}

d) L = {0𝑛 1𝑛 | n ≥ 0}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following set of languages over one symbol alphabet Q Which of the following is a CFL?
L1: set of left linear languages L2: set of right linear languages
a) L = {𝑎𝑚 𝑏 𝑚 𝑐 𝑚 | 𝑚 ≥ 1} b) L = {𝑎𝑚 𝑏 𝑛 𝑐 𝑚 𝑑 𝑛 | 𝑚 ≥ 1 and n≥ 1}

L3: set of DCFLs L4: set of CFLs

c) L = {𝑎𝑚 𝑏 𝑛 𝑐 𝑝 | 𝑚 < 𝑛 ≥ 𝑝} d) {W 𝑊 𝑅 | 𝑊 𝑖𝑛 (a + b)*}


Choose the correct statement from the following
a) L1  L2  L3  L4
b) L1  L2  L3 = L4
c) L1 = L2  L3  L4
d) L1 = L2 = L3 = L4
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following is not true? Q Which of the following statement must always be true for A and B? Suppose A
a) The set of languages accepted by deterministic and non-deterministic PDAs are not and B are two sets of strings from ∑*, such that B ⊆ A
equal i) If A is finite then, B is finite

b) L = {w c w R|𝑤 in (0 + 1)* & c ∉ {0,1}} can be accepted by deterministic PDA


ii) If A is regular then, B is regular
c) L = {w c w R|𝑤, 𝑐 in (0 + 1)*} can not be accepted by a deterministic PDA
iii) If A is context free then, B is context free
d) L= { 0𝑛 01|𝑛 ≥ 0} can be accepted by a deterministic PDA

a) i) only b) ii) only


c) iii) only d) All three

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
𝑃
Q Which of the following language is true about the language L = (𝑎 |P is a prime) Q Identity the language generated by following grammar where S is the
start variable. (GATE-2017) (2 Marks)
a) It is not accepted by a T.M
S → XY
b) It is regular but not C.F.L
X → aX | a
c) It is CFL but not regular
Y → aYb | ∈
d) It is neither regular non CFL
a) {am bn| m >= n, n > 0}
b) {am bn| m >= n, n >= 0}
c) {am bn| m > n, n >= 0}
www.knowledgegate.in
d) {am bn| m > n, n > 0}
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the context-free grammars over the alphabet {a, b, c} given below. S Q Consider the following context-free grammar over the alphabet ∑ = {a, b, c} with S as the start
and T are non-terminals. (GATE-2017) (2 Marks) symbol: (GATE-2017) (2 Marks)
G1: S → aSb | T, T → cT | ϵ
S → abScT | abcT

T → bT | b
G2: S → bSa | T, T → cT | ϵ
Which of the following represents the language generated by the above grammar?
a) {(ab)n(cb)n | n >= 1 }
The language L(G1) ∩ L(G2) is
(A) Finite b) {((ab)n c bm1 c bm2...c bmn | n, m1, m2, ....., mn >= 1 }
(B) Not finite but regular
c) {(ab)n (cbm)n | m,n >= 1 }
(c) Context-Free but not regular
(D) Recursive but not context-free d) {(ab)n (cbn)m | m, n >= 1 }
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following languages is generated by the given grammar? (GATE- Q Consider the following context-free grammars:

2016) (2 Marks)
S → aS | bS | ε

Which one of the following pairs of languages is generated by G1 and G2, respectively (GATE-2016) (2 Marks)

(A) {an bm |n, m ≥ 0}

(B) {w ∈ {a, b}* | w has equal number of a’s and b’s}

(C) {an |n ≥ 0} ∪ {bn |n ≥ 0} ∪ {an bn |n ≥ 0}

(D) {a, b}*


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider a CFG with the following productions. (GATE-2008) (2 Marks)
Q S -> aSa | bSb | a | b (GATE-2009) (2 Marks) S → AA | B
The language generated by the above grammar over the alphabet {a, b} is the set of

A → 0A | A0 | 1

B → 0B00 | 1

S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this
(A) All palindromes grammar is
(A) {0n 102n | n ≥ 1}
(B) All odd length palindromes.
(B) {0i 10j 10k | i, j, k ≥ 0} ∪ {0n 102n | n ≥ 0}
(C) Strings that begin and end with the same symbol
(C) {0i 10j | i, j ≥ 0} ∪ {0n 102n | n ≥ 0}
(D) All even length palindromes (D) The set of all strings over {0, 1} containing at least two 0’s
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Language L1 is defined by the grammar: S1 -> aS1b | ε Q The two-grammar given below generate a language over alphabet {x, y, z) (GATE – 2007) (2 Marks)

G1: S → x | z | xS | zS | yB G2: S → y | z | yS | zS | xB
Language L2 is defined by the grammar: S2 -> abS2 | ε B → y | z | yB | zB B → y | yS

Consider the following statements:


P: L1 is regular
Q: L2 is regular

Which one of the following is TRUE? (GATE-2007) (2 Marks) Which one of the following choices describes the properties satisfied by the strings in these languages?
a) Both P and Q are true a) G1: No y appears before any x, G2: Every x is followed by at least one y

b) P is true and Q is false b) G1: No y appears before any x, G2: No x appears before any y

c) P is false and Q is true c) G1: No y appears after any x, G2: Every x is followed by at least one y

d) Both P and Q are false d) G1: No y appears after any x, G2: Every y is followed by at least one x
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the grammar given below (GATE – 2007) (2 Marks) Q Which one of the following grammars generates the language L = {a i bj | i ≠ j} (GATE-2006) (1 Marks)
S → xB | yA
A → x | x S| y AA
B → y | y S| x BB

Consider the following strings.


i) xxyyx ii) xxyyxy iii) xyxy
iv) yxxy v) yxx vi) xyx

Which of the above strings are generated by the grammar?


a) i), ii) and iii) b) ii), v) and vi)
c) ii), iii) and iv) d) i), iii) and iv)
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q In the context-free grammar below, S is the start symbol, a and b are terminals, Q Let L denotes the language generated by the grammar S → 0S0/00. (GATE-2000)
and ϵ denotes the empty string (GATE-2006) (1 Marks) (1 Marks)
S → aSa | bSb | a | b | ϵ Which of the following is true?
a) L = 0+ b) L is regular but not 0+

Which of the following strings is NOT generated by the grammar? c) L is context free but not regular d) L is not context free
(A) aaaa (B) baba
(C) abba (D) babaaabab

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following definitions below generates the same language as L, Q A CFG G is given with the following productions where S is the start symbol, A is
where (GATE -1995) (2 Marks) a non-terminal and a and b are terminals.
L = { 𝑥 𝑛 𝑦 𝑛 such that n > = 1}? S → aS ∣ A
I. E → xEy | xy II. xy | (𝑥 + sy𝑦 + ) III. 𝑥 + 𝑦 +

A → aAb ∣ bAa ∣ ϵ

Which of the following strings is generated by the grammar above?


(A) aabbaba (B) aabaaba
a) I only b) I and II
c) II and III d) II only (C) abababb (D) aabbaab
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q What is the equivalent CFL for the following CFG?


Q The grammar S → aaSbb | ab can generate the set
S → aS / aSbS / ϵ

a) {𝑎𝑛 𝑏𝑛 |𝑛 = 1,2,3, … }
a) {x|x is a palindrome}
b) {𝑎2𝑛+1 𝑏2𝑛+1 |= n = 0, 1, 2,..}
b) {x|x = 𝑎 𝑛 𝑏 𝑛 𝑓𝑜𝑟 𝑛 ≥ 0}
c) {𝑎2𝑛+1 𝑏2𝑛+1 |= n = 1, 2, 3,..}
c) {x| each prefix of x has atleast as many a’S as b’S

d) none of these
d) {x|x has equal number of a’S and b’S}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following grammar generates the language L = {𝒂𝒊 𝒃𝒋 | i≠ j} Q The following CFG
S → aS | bS | a | b is equivalent to the regular expression
a) S → AC / CB b) S → as / sb / a / b
C → aCb / a / b
A → aA / ε 1. (a* + b)* 2. (a + b)+
B → Bb / ε

3. (a + b)(a + b)* 4. (a + b)* (a + b)


c) S → Ac / CB d) S → AC / CB
C → aCb / ε C → aCb / ε
A → aA / ε A → aAa a) 2 and 3 only b) 2,3 and 4
B → Bb / ε B → bB / b
c) All of the above d) 3 and 4 only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The set {𝑎𝑛 𝑏𝑛 |𝑛 = 1,2,3 … } can be generated by the CFG Q In the context – free grammar below, S is the start symbol, a and b are terminals, and ε
denotes the empty string.

a) S → ab |aSb|ϵ b) S → aaSbb | ab S → aSAb | ε

A → bA | ε
c) S → ab | aSb d) None of these
The grammar generates the language
a) ((a + b)*b)
b) {am bn |m ≤ n}
c) {am bn |m = n}
d) a*b*
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q The following CFG Q 𝐿1 has the following grammar 𝐿2 has the following grammar
S → aB | bA S → aB / BA S → Sba / a
A → ba | aS | bAA A → bAA / aS / a

B → b | bS | aBB B → b / bS / aBB
Which of the following statement is true about?
generates strings of terminals that have
𝐿3 = 𝐿1 ∩ 𝐿2 𝑎𝑛𝑑 𝐿4 = 𝐿.1 . 𝐿1 ∗?
a) equal number of a’s and b’s
b) odd number of a’s and even number of b’s a) Both 𝐿3 and 𝐿4 𝑎𝑟𝑒 𝑛𝑜𝑡 𝑐𝑜𝑛𝑡𝑒𝑥𝑡 𝑓𝑟𝑒𝑒
b) 𝐿3 is context free but 𝐿4 is not
c) even number of a’s and even number of b’s c) Both 𝐿3 and 𝐿4 are context free
d) odd number of a’s and even number of a’s d) 𝐿4 is context free, but not 𝐿3
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q What is the equivalent CFL for the following CFG S → OS 1/ϵ? Q If G, = ({S}, {a}, {S → SS}, S), find language generated by G.

a) L(G) = ϕ
a) {X/X is a palindrome}

b) {X/X = 0𝑛 1𝑛 𝑓𝑜𝑟 𝑛 ≥ 0} b) L(G) = 𝑎 𝑛

c) {X/X = 0𝑛 1𝑛 𝑓𝑜𝑟 𝑛 > 0 } c) L(G)= a*

d) {X/X = 0𝑛 1𝑛 𝑓𝑜𝑟 𝑛 > 1} d) L(G)= 𝑎 𝑛 b𝑎 𝑛

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider a grammar G as follows Decision properties


S → aA Following properties are decidable in case a CFL. Here we will use Grammar model
to proof decision properties.
A → bbA
A→c i) Emptiness
L(G) =?
ii) Non-emptiness

iii) Finiteness
a) L(G) = {abbc}
b) L(G) = {a 𝑏 𝑛 𝑐; n ≥ 0} iv) Infiniteness
2𝑛
c) L(G) = {a 𝑏 𝑐; n > 0} v) Membership
d) L(G) = {a 𝑏 2𝑛 𝑐; n ≥ 0}
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q consider the following CFG and identify which of the following CFG generate Empty language? Q consider the following CFG and identify which of the following CFG generate Finite
language?
S → aAB / Aa
A→a S → SS / AB
A → BC / a
B → CC / b
S → aAB
A→a/b S → AB
A→B/a

S → aAB / aB
A → aBb S → AB
B → aA A → BC / a
B → CC / b
C → AB
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q consider the following CFG and check out the membership properties? CYK algorithm
• In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is
S → AB / BB a parsing algorithm for context-free grammars, named after its inventors, John Cocke, Daniel Younger and Tadao
Kasami. It employs bottom-up parsing and dynamic programming.
A → BA / AS / b • The standard version of CYK operates only on context-free grammars given in Chomsky normal form (CNF).

B → AA / SB / a However any context-free grammar may be transformed to a CNF grammar expressing the same language (Sipser
1997).

• The importance of the CYK algorithm stems from its high efficiency in certain situations. Using Big O notation,
the worst case running time of CYK is O (n3 .|G|), Where n is the length of the parsed string and |G| is the size of
w1 = aba the CNF grammar G.

w2 = abaab • This makes it one of the most efficient parsing algorithms in terms
of worst-case asymptotic complexity, although other algorithms exist

w3 = abababba with better average running time in many practical scenarios.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Following properties are Undecidable in case a CFL Q Which of the following problems is undecidable? (GATE-2014) (1 Marks)
i) Equality
(A) Deciding if a given context-free grammar is ambiguous.
ii) Ambiguity
(B) Deciding if a given string is generated by a given context-free grammar.

(C) Deciding if the language generated by a given context-free grammar is empty.

(D) Deciding if the language generated by a given context-free grammar is finite.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following are decidable? (GATE-2008) (2 Marks) Q Which of the following problems is undecidable? (GATE-2007) (1 Marks)
I. Whether the intersection of two regular languages is infinite (A) Membership problem for CFGs (B) Ambiguity problem for CFGs.
II. Whether a given context-free language is regular

III. Whether two push-down automata accept the same language

IV. Whether a given grammar is context-free


(C) Finiteness problem for FSAs. (D) Equivalence problem for FSAs.
a). I and II b). I and IV c). II and III d). II and IV

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which one of the following statements is FALSE? (GATE-2004) (1 Marks) Q Consider the following decision problems? (GATE-2000) (2 Marks)
(P1) Does a given finite state machine accept a given string
a) There exist context free languages such that all the context free grammars generating them
age ambiguous.

b) An unambiguous context free grammar always has a unique parse tree for each string of the
language generated by it. (P2) Does a given context free grammar generate an infinite number of stings

c) Both deterministic and non – deterministic pushdown automata always accept the same set of
languages

d) A finite set of string from one alphabet is always a regular language. Which of the following statements is true?
(A) Both (P1) and (P2) are decidable
(B) Neither (P1) nor (P2) are decidable
(C) Only (P1) is decidable
(D) Only (P2) is decidable
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following is undecidable RL DCFL CFL CSL RS RES


a) Equivalence of regular languages Emptiness Y Y Y X N N

b) Equivalence of context free languages


Non-Emptiness Y Y Y X N N
Finiteness Y Y Y X N N
c) Finiteness check on context free languages Infiniteness Y Y Y X N N
Membership Y Y Y X Y N
d) Emptiness of regular languages Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in Halting Y Ywww.knowledgegate.in


Y X Y N
Closure Properties of Deterministic Context Free Languages Closure Properties of Context Free Languages
• Deterministic Context Free Languages are closed under following operations • Context Free Languages are closed under following operations
• Complement • Union
• Intersection with regular set • Concatenation
• Kleen Closure
• Inverse Homeomorphism
• Substitution
• Homomorphism
• Deterministic Context Free Languages are not closed under following operations
• Inverse Homomorphism
• Union • Reverse Operator
• Concatenation • Intersection with regular set
• Kleen closure
• Context Free Languages are not closed under following operations
• homomorphism • Intersection
• Substitution • Complement
• Reverse operator • Symmetric Difference
• Intersection

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
RL DCFL CFL CSL RS RES RL DCFL CFL CSL RS RES
Union Y N Y Y Y Y Homomorphism Y N Y N N Y
Intersection Y N N Y Y Y
∈ Free Homomorphism
Complement Y Y N Y Y N Y N Y Y Y Y
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y
Inverse Homomorphism Y Y Y Y Y Y
Y N Y Y Y Y Substitution
Positive Closure
Y N Y N N Y
Concatenation Y N Y Y Y Y
Intersection with
regular set Y Y Y Y Y Y
∈ Free Substitution Y N Y Y Y Y
Reverse Y Y Y Y Y Y Quotient with regular set Y Y Y N Y Y
Subset N N N N N N
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q For a string w, we define wR to be the reverse of w. For example, if w = 01101 then wR = Q Consider the following languages:
10110. Which of the following languages is/are context-free?(GATE 2021) (2 MARKS) L1 = {ww| w ∈ {a,b}*}
L2 = {anbncm |m,n >= 0}
(A){wxwRxR ∣ w,x∈{0,1}*} L3 = {ambncn |m,n >= 0}
Which of the following statements is/are FALSE?(GATE 2022) (2 MARKS)
(A){wwRxxR ∣ w,x∈{0,1}*}
(A)L1 is not context-free but L2 and L3 are deterministic context-free.
(A){wxwR ∣ w,x∈{0,1}*}
(B) Neither L1 nor L2 is context-free.
(A){wxxRwR ∣ w,x∈{0,1}*}
(C) L2 , L3 and L2 ∩ L3 all are context-free.

(D) Neither L1 nor its complement is context-free.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following languages: Q Suppose that L1 is a regular language and L2 is a context-free language.
L1 = {anwan | w ∈{a,b}* }
L2 ={wxwR | w, x ∈ {a,b}*,|w|,|x|> 0}
Which one of the following languages is NOT necessarily context-free?
Note that wR is the reversal of the string w. Which of the following is/are TRUE? (GATE 2022) (2 (GATE 2021)
MARKS)

(A) L1 and L2 are regular.


(a) L1 ∩ L2

(B) L1 and L2 are context-free. (b) L1 ⋅ L2


(C) L1 is regular and L2 is context-free.
(c) L1 − L2
(D) L1 and L2 are context-free but not regular.
(d) L1 ∪ L2

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let L1 be a regular language and L2 be a context-free language. Which of the following Q Let L1 and L2 be any context-free language and R be any regular language. Then,
languages is/are context-free? (GATE 2021) (1 MARKS) which of the following is correct? (GATE-2017) (2 Marks)
(A) L1∩L2'
I. L1 ∪ L2 is context-free. II. L1' is context-free.
(B) (L1'∪L2')'

(C) L1∪(L2∪L2')
III. L1 - R is context-free. IV. L1 ∩ L2 is context-free
(D)(L1∩L2)∪(L1∩L2)

a) I, II and IV only b) I and III only


c) II and IV only d) I only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Consider the following languages over the alphabet ∑= {a, b, c}. Q Which one of the following statements is FALSE? (GATE-2013) (1
Let L1 = {an bn cm | m, n >= 0} and L2 = {am bn cn | m, n >= 0}. Marks)
L1 = {0p 1q 0r ∣ p, q, r ≥ 0} L2 = {0p 1q 0r ∣p, q, r ≥ 0, p ≠ r}

Which of the following are context-free languages? (GATE-2017) (2 Marks)


I. L1 ∪ L2 (A) L2 is context-free.

II. L1 ∩ L2 (B) L1 intersection L2 is context-free.

(C) Complement of L2 is recursive.


a) I only b) II only
c) I and II d) Neither I nor II
www.knowledgegate.in
(D) Complement of L1 is context-free but not regular.
www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let L = 𝐿1 ∩ 𝐿2 , where 𝐿1 and 𝐿2 are languages as defined below: (GATE – 2009) (2 Marks) Q Let L be a context - free language and M a regular language. Then the language L ∩ M is (GATE-
𝐿1 = {𝑎𝑚 𝑏𝑚 c 𝑎𝑛 𝑏𝑛 | m, n ≥ 0} 𝐿2 = {𝑎𝑖 𝑏 𝑗 𝑐 𝑘 | I, j, k ≥ 0} 2006) (1 Marks)

a) Always regular b) Never regular

a) Not recursive
c) Always a deterministic context free language d) Always a context – free language

b) Regular

c) Context – free but not regular

d) Recursively enumerable but not context – free


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the languages: (GATE-2005) (2 Marks) Q Let L be a regular language and M be a context-free language, both over the alphabet Σ. Let Lc
L1 = {an bn cm | n, m > 0} L2 = {an bm cm | n, m > 0} and Mc denote the complements of L and M respectively. Which of the following statements
about the language Lc ∪ Mc is TRUE? (GATE-2005) (2 Marks)

Which one of the following statements is FALSE?


(A) L1 ∩ L2 is a context-free language (A) It is necessarily regular but not necessarily context-free

(B) L1 U L2 is a context-free language (B) It is necessarily context-free.

(C) L1 and L2 are context-free language (C) It is necessarily non-regular.

(D) L1 ∩ L2 is a context sensitive language (D) None of the above


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following statements is true? (GATE-2001) (1 Marks) Q Consider the following decision problems (GATE-2000) (2 Marks)
(A) If a language is context free it can always be accepted by a deterministic push-down (P1) Does a given finite state machine accept a given string
automaton

(B) The union of two context free languages is context free (P2) Does a given context free grammar generate an infinite number of stings

(C) The intersection of two context free languages is context free Which of the following statements is true?
(A) Both (P1) and (P2) are decidable
(B) Neither (P1) nor (P2) are decidable
(C) Only (P1) is decidable
(D) The complement of a context free language is context free
(D) Only (P2) is decidable
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let L1 is context free language and L2 is a regular language which of the following Q Context – free language is closed under: (GATE – 1999) (1 Marks)
is/are false (GATE – 1999) (1 Marks) a) Union, intersection b) Union, Kleene closure

a) L 1 – L2 is not context free


c) Intersection, complement d) Complement, Kleene closure
b) L1 ∩ L2 is context free

c) ~ L1 is context free

d) ~ L2 is regular
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q If 𝐿1 and 𝐿2 are context free language and R a regular set, one of the languages Q Context – free languages are (GATE – 1992) (1 Marks)
below is not necessarily a context free language. Which one? (GATE – 1996) (1 a) Closed under union b) Closed under complementation
Marks)
a) 𝐿1 , 𝐿2 b) 𝐿1 ∩ 𝐿2 c) 𝐿1 ∩ R d) 𝐿1 ∪ 𝐿2

c) Closed under intersection d) Closed under Kleene closure

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Turing Machine Q Which one of the following is false


• The Church-Turing thesis posits that any computational task performable by a human or machine can be a) There is unique minimal DFA for every regular language
executed by a Turing machine. It is widely regarded as a fundamental theoretical model of computation in
computer science.
• Turing machines serve several key purposes:
• General Automaton: Turing machines are the most general form of automaton, capable of simulating any
algorithmic process. b) Every NFA can be converted into equivalent PDA
• Type-0 Language Acceptance: They can recognize type-0 languages, which are the most complex in the
Chomsky hierarchy.
• Function Computation: Turing machines can compute any computable function.
• Undecidability & Complexity: They help determine the undecidability of certain languages and are used to
measure both time and space complexity for computational problems. c) Every PDA can be converted into FM

d) TM is the most powerful machine

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
• Components of a Turing Machine: FORMAL DEFINITION
• Infinite Tape: The tape acts as both input storage and memory. It is infinitely long and divided into cells, each
capable of holding a single symbol. The tape can be accessed randomly in either direction, referred to as a A Turing machine M is a 7-tuple, namely (Q, ∑, Γ, δ, q0, b, F), where
two-way infinite tape. • Q is a finite nonempty set of states.
• Read-Write Head: The head reads symbols from the tape and can also write over them. After reading or
writing, it moves one cell either to the left or right. • Γ is a finite nonempty set of tape symbols,
• Finite Control Unit: The control unit governs transitions based on the current state and symbol under the
read-write head. It determines the next action, ultimately leading to the machine’s output. • b ∈ Γ is the blank.

• ∑ is a nonempty set of input symbols and is a subset of Γ and b ∉∑.

• δ is the transition function mapping : Q ×ℾ -> Q× ℾ × (L/R). It says that, on providing a tape symbol, from a
particular state there will be a transition to another state, with a different or same tape symbol with defining
whether next the machine needs to move in left/ right.

• q0 ∈ Q is the initial state, and

• F ⊆ Q is the set of final states.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a Turing machine for L = {ab}? Q Design a Turing machine for L = {a, ab}?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
REPRESENTATION OF TURING MACHINES

Three representations:
• Instantaneous descriptions using move-relations.
• Transition table, and
• Transition diagram (transition graph).

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
LANGUAGE ACCEPTABILITY BY TURING MACHINES Q Design a Turing machine for L = {an bn | n >= 1}?
• A string w in ∑* is said to be accepted by a TM(M) if after parsing the string w Turing machine
must halts on final state.
• q0w ⊢* α1pα2 for some p ∊ F and α1, α2 ∊ Γ *.
• M does not accept w if the machine M either halts in a non-accepting state or does not halt
and goes into a loop.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Design a Turing machine for L = {an bn cn| n >= 0}? Q Design a Turing machine for L = {w c w | w ∊ {0, 1}* }?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Design a Turing machine for addition of two number in unary? Q Design a Turing machine for converting unary number into binary
number?

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The Q Consider the transition table of a TM given below. Here “b” represents the blank symbol.
tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}. The symbol B is the blank symbol Which of the following strings will not accepted?
used to indicate end of an input string. The transition function of M is described in the following a) 010101 b) 101010 c) 110011 d) Both a and b
table. Which of the following statements is true about M ?
(A) M does not halt on any string in (0 + 1)+ 0 1 B
q0 q1, 1, R q1, 1, R Halt
(B) M does not halt on any string in (00 + 1)*
q1 q1, 1, R q0, 1, L q0, B, L
(C) M halts on all string ending in a 0

(D) M halts on all string ending in a 1

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q The given Turing machine accepts Q Consider the following languages.
a) set of all even palindromes over {0, 1} L1 = {ap | p is a prime number}

L2 = {an bm c2m | n >= 0, m >= 0}


b) strings over {0, 1} containing even number of 1’s

L3 = {an bn c2n | n >= 0}


c) strings over {0, 1} containing even number of 1’s
and odd no. of 0’s L4 = {an bn | n >= 1}

Which of the following are CORRECT? (GATE-2017) (2 Marks)


d) string over {0, 1} starting with zero I. L1 is context free but not regular. II. L2 is not context free.
III. L3 is not context free but recursive IV. L4 is deterministic context free

a) I, II and IV only b) II and III only


c) I and IV only d) III and IV only

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following is true for the language (GATE-2008) (2 Marks) Q For S ∈ (0 + 1) * let d(s) denote the decimal value of s (e.g. d (101) = 5).
(A) It is not accepted by a Turing Machine Let L = {s ∈ (0 + 1) * d(s)mod5 = 2 and d(s)mod7 != 4}. (GATE-2006) (2 Marks)
Which one of the following statements is true?
(A) L is recursively enumerable, but not recursive

(B) It is regular but not context-free

(B) L is recursive, but not context-free


(C) It is context-free but not regular

(D) It is neither regular nor context-free, but accepted by a Turing machine (C) L is context-free, but not regular

(D) L is regular

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q L1 is a recursively enumerable language over Σ. An algorithm A effectively enumerates its words as w1, w2, w3, … • Deterministic and Non-Deterministic Turing Machines:
Define another language L2 over Σ Union {#} as {wi # wj : wi, wj ∈ L1, i < j}. Here # is a new symbol. Consider the • Deterministic: Each state and symbol pair leads to a single possible move.
following assertions. (GATE-2004) (2 Marks) • Non-Deterministic: Multiple moves may be possible for a given state and symbol.
S1 : L1 is recursive implies L2 is recursive However, non-deterministic Turing machines do not add computational power and can
always be converted into a deterministic Turing machine.

S2 : L2 is recursive implies L1 is recursive

Which of the following statements is true ?


(A) Both S1 and S2 are true
(B) S1 is true but S2 is not necessarily true
(C) S2 is true but S1 is not necessarily true
(D) Neither is necessarily true

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Versions of Turing Machines: Q Which of the following pairs have DIFFERENT expressive power? (GATE-2011) (1 Marks)
• Multi-Tape Turing Machine: Uses multiple tapes with corresponding read/write heads. However, every multi-tape machine
a) Deterministic finite automata (DFA) and non – deterministic finite automata (NFA)
can be simulated by a single-tape machine.
• Multi-Head Turing Machine: A machine with multiple read/write heads.
• Multi-Dimensional Turing Machine: Operates on tapes of multiple dimensions (e.g., 2D grid).
• Turing Machine with Stay Option: The head can remain in place instead of moving left or right. b) Deterministic push down automata (DPDA) and Non – deterministic push down automata (NPDA)
• One-Way Infinite Tape (Semi-Infinite Tape): The tape is infinite in only one direction.
• Offline Turing Machine: The input tape is read-only and cannot be modified.
• Jumping Turing Machine: Can make multiple moves in one transition.
• Non-Erasing Turing Machine: Cannot erase or overwrite the input symbols with blanks.
• Always Writing Turing Machine: Must replace every symbol it reads with another symbol. c) Deterministic single – tape Turing machine and Non – deterministic single tape Turing machine
• Finite Automaton with Queue: Combines a finite automaton with an unbounded queue.
• Turing Machine with 3 States: A simplified Turing machine with only 3 states.
• Multi-Tape TM with Stay Option and 2 States: A variation with multiple tapes and stay options but limited to two states.
• Non-Deterministic TM: Similar to the non-deterministic Turing machine but with a stay option.
• NPDA with Two Stacks: A non-deterministic pushdown automaton with two independent stacks. d) Single – tape Turing machine and multi – tape Turing machine

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following is true? Q Consider the Turing machine M defined below 0 1 B
a) PDA with 2 stacks is equivalent to TM Choose the false statement →Q0 (Q0, 0, R) (Q2, 1, L) (Qf, -, -)
a) The machine loops on 01 Q1 (Q2, 1, L) (Q1, 1, R) (Qf, -, -)
Q2 (Q2, 1, L) (Q2, 0, L) (Qf, -, -)
b) Regular expression can represent only some of the languages
*Qf --- --- ---
b) The machine does not accept 0000

c) Both a and b
c) The machine accepts strings ending with a 1

d) None of a and b
d) The machine accepts strings ending with 10

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Halt in a Turing Machine Recursively Enumerable Languages


• Recursive Set:
• When a Turing machine reaches a state where no further transitions are defined or needed, it • A language L is a recursive set if it is accepted by a Turing machine in such a way that:
is said to halt. There are two types of halts: • For all w∈L , the machine halts in a final state (accepts).
• For all w∉L, the machine halts in a non-final state (rejects).
• Final Halt: The machine halts in a final (accepting) state, indicating that the input string is
• The membership property is clearly defined here—every string is either accepted or rejected.
accepted. • Recursively Enumerable Set (REL):
• Non-Final Halt: The machine halts in a non-final state, meaning the input string is rejected. • A language L is recursively enumerable if it is accepted by a Turing machine, where:
• For all w∈L, the machine halts in a final state (accepts).
• After processing an input string, a Turing machine can experience one of three outcomes: • For all w∉L, the machine may either halt in a non-final state (reject) or enter an infinite loop.
• Final Halt: The machine accepts the string. • The membership property is not defined because the machine might never halt for certain strings.
• Non-Final Halt: The machine rejects the string. • Decidability:
• Infinite Loop: The machine enters an infinite loop, in which case it is undecidable whether • A set is decidable if both the set and its complement are recognizable by a Turing machine.
the string is accepted or rejected. • Some sets are not recognizable, meaning that even the members of the set cannot be identified, as there are
more languages than programs available to recognize them.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let L be a language and L’ be its complement. Which one of the Q Which of the following statements is false? (GATE-2008) (1 Marks)
following is NOT a viable possibility? (GATE-2014) (1 Marks) (A) Every NFA can be converted to an equivalent DFA
(A) Neither L nor L’ is recursively enumerable (r.e.).
(B) Every non-deterministic Turing machine can be converted to an equivalent
deterministic Turing machine
(B) One of L and L’ is r.e. but not recursive; the other is not r.e.

(C) Every regular language is also a context-free language


(C) Both L and L’ are r.e. but not recursive.
(D) Every subset of a recursively enumerable set is recursive

(D) Both L and L’ are recursive


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q If L and L’ are recursively enumerable, then L is (GATE-2008) (1 Marks) Q Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive
language. Which one of the following is TRUE? (GATE-2005) (1 Marks)
(A) regular L1’ → Complement of L1

(B) context-free L2’ → Complement of L2

(C) context-sensitive (A) L1′ is recursive and L2′ is recursively enumerable

(B) L1′ is recursive and L2′ is not recursively enumerable


(D) recursive (C) L1′ and L2′ are recursively enumerable

(D) L1′ is recursively enumerable and L 2′ is recursive


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Universal Turing Machine (UTM)

• In computer science, a Universal Turing Machine (UTM) is a Turing machine capable of simulating any
other Turing machine on any input. It does this by reading both the description of the machine to be
simulated and the input for that machine from its own tape.
• Every Turing machine computes a fixed partial computable function from input strings over its
alphabet, behaving like a computer with a specific program.
• The action table of any Turing machine can be encoded into a string. A UTM can then read this
string, which describes the action table, followed by a string that describes the input tape, and
simulate the encoded Turing machine's behavior.

• In his 1936 paper, Turing described this concept in detail, stating:


• "It is possible to invent a single machine which can be used to compute any computable sequence.
If this machine UUU is supplied with a tape containing the 'standard description' (S.D.) of some
machine MMM, UUU will compute the same sequence as MMM."

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q For a Turing machine M, ⟨M⟩ denotes an encoding of M. Consider the following two languages. Q Let ⟨M⟩ denote an encoding of an automaton M. Suppose that Σ={0,1}. Which of
●L1 = { ⟨M⟩ ∣ M takes more than 2021 steps on all inputs } the following languages is/are NOT recursive? (GATE 2021)
●L2 = { ⟨M⟩ ∣ M takes more than 2021 steps on some input } (a) L = {⟨M⟩ ∣ M is a DFA such that L(M)=∅}
Which one of the following options is correct? (GATE 2021) (2 MARKS)

(a) Both L1 and L2 are decidable (b) L = {⟨M⟩ ∣ M is a DFA such that L(M)=Σ*}
(b) L1 is decidable and L2 is undecidable
(c) L1 is undecidable and L2 is decidable (c) L = {⟨M⟩ ∣ M is a PDA such that L(M)=∅}
(d) Both L1 and L2 are undecidable
(d) L = {⟨M⟩ ∣ M is a PDA such that L(M)=Σ*}

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q L1 = { <M> | M takes at least 2016 steps on some input}, Q Let < M > be the encoding of a Turing machine as a string over {0, 1}.
Let L = {< M > |M is a Turing machine that accepts a string of length 2014}.
Then, L is (GATE-2014) (2 Marks)
L2 = { <M> | M takes at least 2016 steps on all inputs} and (A) decidable and recursively enumerable

L3 = { <M> | M accepts ε},


where for each Turing machine M, <M> denotes a specific encoding of M.
(B) undecidable but recursively enumerable

Which one of the following is TRUE? (GATE-2016) (2 Marks)

(C) undecidable and not recursively enumerable


(A) L1 is recursive and L2, L3 are not recursive
(B) L2 is recursive and L1, L3 are not recursive
(C) L1, L2 are recursive and L3 is not recursive
(D) decidable but not recursively enumerable
(D) L1, L2, L3 are recursive
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Linear Bounded Automaton (LBA) Decision properties


• An LBA is a variant of a Turing machine with the following property: The tape
length is finite and bounded, unlike a traditional Turing machine that has an • Following properties are decidable in case a RS.
infinite tape. • Membership

• All properties are undecidable in case of a REL.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

RL DCFL CFL CSL RS RES Q Which of the following is/are undecidable? (GATE 2022) (2 MARKS)
Emptiness Y Y Y X N N
(A) Given two Turing machines M1 and M2,decide if L(M1) = L(M2).
Non-
Y Y Y X N N
Emptiness
(B) Given a Turing machine M, decide if L(M) is regular.
Finiteness Y Y Y X N N

Infiniteness Y Y Y X N N
(C) Given a Turing machine M, decide if M accepts all strings.
Membershi
Y Y Y X Y N
p
(D) Given a Turing machine M, decide if M takes more than 1073 steps on every string.
Equality Y N N X N N

Ambiguity Y N N X N N

∑* Y N N X N N

Halting Y Y Y X Y N

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes Q Let L(R) be the language represented by regular expression R. Let L(G) be the language
the language accepted by a machine M. generated by a context free grammar G. Let L(M) be the language accepted by a Turing machine
(I) For an unrestricted grammar G and a string w, whether w ϵ L(G) M. Which of the following decision problems are undecidable? (GATE-2017) (2 Marks)
I. Given a regular expression R and a string w, is w ∈ L(R)?
(II) Given a Turing machine M, whether L(M) is regular
II. Given a context-free grammar G, is L(G)=∅
(III) Given two grammar G1 and G2, whether L(G1) = L(G2)

(IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language III. Given a context-free grammar G, is L(G)=Σ∗ for some alphabet Σ?

Which one of the following statement is correct? (GATE-2018) (2 Marks) IV. Given a Turing machine M and a string w, is w ∈ L(M)?
a) Only I and II are undecidable
a) I and IV only b) II and III only
b) Only II is undecidable
c) II, III and IV only d) III and IV only
c) Only II and IV are undecidable

d) Only I, II and III are undecidable


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following decision problems are undecidable (GATE-2016) (2 Q Which of the following is/are undecidable? (GATE-2013) (1 Marks)
Marks)
1) G is a CFG. Is L(G)=ϕ?

2) G is a CFG. Is L(G)=Σ∗?

3) M is a Turing machine. Is L(M) regular?

4) A is a DFA and N is an NFA. Is L(A)=L(N)?


(A) I and IV only

(B) II and III only (A) 3 only (B) 3 and 4 only

(C) III and IV only


(C) 1, 2 and 3 only (D) 2 and 3 only

(D) II and IV only


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following problems are decidable? (GATE-2012) (2 Marks) Q Which of the following is not decidable? (GATE – 1997) (1 Marks)
a) Does a given program ever produce an output? a) Given a Turing machine M, a strings s and an integer k, M accepts s within k steps

b) If L is a context-free language, then, is L’ also context-free?

c) If L is a regular language, then, is L’ also regular? b) Equivalence of two given Turing machines

d) If L is a recursive language, then, is L’ also recursive?

c) Language accepted by a given finite state machine is not empty


a) 1, 2, 3, 4 b) 1, 2

d) Languages generated by a context free grammar is non empty


c) 2, 3, 4 d) 3, 4

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Closure Properties of Recursive Set Closure Properties of Recursive Enumerable Set
• Recursive languages are closed under following operations • Recursive Enumerable are closed under following operations
• Union • Union
• Concatenation • Concatenation
• Intersection • Kleen Closure
• Reverse • Intersection
• Complement • Substitution
• Inverse homomorphism • Homomorphism
• Intersection with regular set • Inverse Homomorphism
• Set Difference
• Intersection with regular set
• Reverse operation
• Recursive languages are not closed under following operations
• Kleen closure
• Homomorphism • Recursive Enumerable are not closed under following operations
• Substitution • Compliment
• Set Difference

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

RL DCFL CFL CSL RS RES RL DCFL CFL CSL RS RES


Union Y N Y Y Y Y
Homomorphism Y N Y N N Y
Intersection Y N N Y Y Y
∈ Free
Complement Y Y N Y Y N
Homomorphism Y N Y Y Y Y
Set Difference Y N N Y Y N

Kleene Closure Y N Y Y Y Y
Inverse Y Y Y Y Y Y
Positive
Closure
Y N Y Y Y Y Homomorphism
Concatenation Y N Y Y Y Y Substitution
Y N Y N N Y
Intersection
with regular Y Y Y Y Y Y
set ∈ Free Substitution Y N Y Y Y Y
Reverse Y Y Y Y Y Y
Subset N N N N N N Quotient with Y Y Y N Y Y
regular set

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following statements is/are TRUE? (GATE 2022) (1 MARKS) Q The set of all recursively enumerable languages is (GATE-2018) (1 Marks)
a) closed under complementation.
(A) Every subset of a recursively enumerable language is recursive.

(B) If a language L and its complement L’ are both recursively enumerable, then L must be
recursive. b) closed under intersection.

(C) Complement of a context-free language must be recursive.


c) a subset of the set of all recursive languages.
(D) If L1 and L2 are regular, then L1 ∩ L2 must be deterministic context-free.

d) an uncountable set.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following types of languages (GATE-2016) (2 Marks) Q For any two languages L1 and L2 such that L1 is context free and L2 is recursively enumerable
L1 Regular, L2: Context-free L3: Recursive, L4: Recursively enumerable. but not recursive, which of the following is/are necessarily true? (GATE-2015) (2 Marks)
Which of the following is/are TRUE? 1. L1' is recursive
I. L3' U L4 is recursively enumerable

II. L2 U L3 is recursive 2. L2' is recursive

III. L1* U L2 is context-free


3. L1' is context-free
IV. L1 U L2' is context-free

4. L1' ∪ L2 is recursively enumerable


(A) I only (B) I and III only
(A) 1 only (B) 3 only

(C) I and IV only (D) I, II and III only


(C) 3 and 4 only (D) 1 and 4 only
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let L be a language and L' be its complement. Which one of the following is NOT a viable Q Which of the following statements is/are FALSE? (GATE-2013) (2 Marks)
possibility? (GATE-2014) (2 Marks) 1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing
a) Neither L nor L' is recursively enumerable (r.e.). machine.

2. Turing recognizable languages are closed under union and complementation.


b) One of L and L' is r.e. but not recursive; the other is not r.e.
3. Turing decidable languages are closed under intersection and complementation.

c) Both L and L' are r.e. but not recursive. 4. Turing recognizable languages are closed under union and intersection.

d) Both L and L' are recursive (A) 1 and 4 only (B) 1 and 3 only

(C) 2 only (D) 3 only

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let L1 be a recursive language. Let L2 and L3 be languages that are recursively enumerable but Q Which one of the following is FALSE? (GATE-2009) (1 Marks)
not recursive. Which of the following statements is not necessarily true? (GATE-2010) (1 Marks) A) There is unique minimal DFA for every regular language
(A) L2 – L1 is recursively enumerable.
B) Every NFA can be converted to an equivalent PDA

(B) L1 – L3 is recursively enumerable


C) Complement of every context-free language is recursive.

(C) L2 ∩ L1 is recursively enumerable D) Every non-deterministic PDA can be converted to an equivalent deterministic PDA

(D) L2 ∪ L1 is recursively enumerable

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q If the strings of a language L can be effectively enumerated in lexicographic (i.e., alphabetic) Q Which of the following is true? (GATE-2002) (1 Marks)
order, which of the following statements is true? (GATE-2003) (1 Marks) (A) The complement of a recursive language is recursive.
(A) L is necessarily finite

(B) The complement of a recursively enumerable language is recursively enumerable.


(B) L is regular but not necessarily finite

(C) The complement of a recursive language is either recursive or recursively enumerable.


(C) L is context free but not necessarily regular

(D) The complement of a context-free language is context-free.


(D) L is recursive but not necessarily context free

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
a) Not recursive

b) Regular

c) Context free but not regular

d) Recursively enumerable but not context free


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Cook-Levin Theorem (Cook's Theorem) Stephen Cook's Contributions:
• In computational complexity theory, the Cook-Levin theorem states that the Boolean satisfiability • During his PhD, Cook worked on function complexity, focusing on multiplication. In his 1971 landmark paper,
problem (SAT) is NP-complete. This means: "The Complexity of Theorem Proving Procedures", Cook formalized the concepts of polynomial-time reduction
(also known as Cook reduction) and NP-completeness. He also proved the existence of NP-complete problems,
• SAT is in NP, and any problem in NP can be reduced in polynomial time by a deterministic Turing
showing that SAT is NP-complete.
machine to SAT. • This theorem explores whether optimization problems, whose solutions can be efficiently verified, can also be
• An important implication of this theorem is that if a deterministic polynomial-time algorithm exists solved efficiently.
for SAT, then every NP problem can be solved in polynomial time. This leads to the famous P vs NP • Cook proposed that some optimization problems (with easily verifiable solutions) cannot be solved by efficient
problem, one of the most important open questions in theoretical computer science. algorithms, i.e., P ≠ NP. This conjecture has spurred extensive research in computational complexity, enhancing
our understanding of the difficulty of computational problems. However, the conjecture remains unresolved.
• In 1982, Cook received the Turing Award for his groundbreaking contributions to complexity theory.

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Let X be a recursive language and Y be a recursively enumerable but not recursive language. Let W and Q Consider the following statements (GATE-2015) (2 Marks)
Z be two languages such that Y reduces to W, and Z reduces to X (reduction means the standard many- 1. The complement of every Turning decidable language is Turning decidable
one reduction). Which one of the following statements is TRUE (GATE-2016) (2 Marks)
(A) W can be recursively enumerable and Z is recursive.
2. There exists some language which is in NP but is not Turing decidable
(B) W can be recursive and Z is recursively enumerable.

3. If L is a language in NP, L is Turing decidable


(C) W is not recursively enumerable and Z is recursive.

Which of the above statements is/are True?


(D) W is not recursively enumerable and Z is not recursive (A) Only 2 (B) Only 3

(C) Only 1 and 2 (D) Only 1 and 3

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Language L1 is polynomial time reducible to language L 2. Language L3 is polynomial time Q Consider two decision problems Q 1, Q2 such that Q1 reduces in polynomial time
reducible to L2, which in turn is polynomial time reducible to language L4. Which of the following to 3-SAT and 3-SAT reduces in polynomial time to Q 2. Then which one of the
is/are True? (GATE-2015) (2 Marks)
following is consistent with the above statement?(CS-2015) (2 Marks)
I. If L4 ∈ P, L2 ∈ P
(A) Q1 is in NP, Q2 is NP hard
II. If L1 ∈ P or L3 ∈ P, then L2 ∈ P

III. L1 ∈ P, if and only if L3 ∈ P (B) Q2 is in NP, Q1 is NP hard


IV. If L4 ∈ P, then L1 ∈ P and L3 ∈ P

(A) II only (B) III only (C) Both Q1 and Q2 are in NP

(C) I and IV only (D) I only (D) Both Q1 and Q2 are in NP hard

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q consider the following two problems of graph. (GATE-2015) (2 Marks) Q Let A ≤m B denotes that language A is mapping reducible (also known as many-to-one
1) Given a graph, find if the graph has a cycle that visits every vertex exactly once except the first visited vertex reducible) to language B. Which one of the following is FALSE? (GATE-2014) (2 Marks)
which must be visited again to complete the cycle.
(A) If A ≤m B and B is recursive then A is recursive.

2) Given a graph, find if the graph has a cycle that visits every edge exactly once. (B) If A ≤m B and A is undecidable then B is undecidable.

Which of the following is true about above two problems. (C) If A ≤m B and B is recursively enumerable then A is recursively enumerable.
(A) Problem 1 belongs NP Complete set and 2 belongs to P

(B) Problem 1 belongs to P set and 2 belongs to NP Complete set (D) If A ≤m B and B is not recursively enumerable then A is not recursively enumerable.
(C) Both problems belong to P set

(D) Both problems belong to NP complete set

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q (GATE-2014) (2 Marks) Q Assuming P ≠ NP, which of the following is TRUE? (GATE-2012) (1 Marks)
a) NP-complete = NP

b) NP-complete ∩ P = ∅
(A) solvable in polynomial time by reduction to directed graph reachability

(B) solvable in constant time since any input instance is satisfiable c) NP-hard = NP

(C) solvable in constant time since any input instance is satisfiable.


d) P = NP-complete
(D) NP-hard, but not NP-complete

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Suppose a polynomial time algorithm is discovered that correctly computes the largest clique Q Let πA be a problem that belongs to the class NP. Then which one of the
in a given graph. In this scenario, which one of the following represents the correct Venn diagram following is TRUE? (GATE-2009) (1 Marks)
of the complexity classes P, NP and NP Complete (NPC)? (GATE-2012) (1 Marks)
a) There is no polynomial time algorithm for πA

b) If πA can be solved deterministically in polynomial time, then P = NP

c) If πA is NP-hard, then it is NP-complete

d) πA may be undecidable

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q For problem X and Y, Y is NP – complete and X reduces to Y in polynomial time. Q The subset-sum problem is defined as follows: Given a set S of n positive integers and a
Which of the following is TRUE? (GATE – 2008) (2 Marks) positive integer W, determine whether there is a subset of S whose elements sum to W. An
algorithm Q solves this problem in O(nW) time. Which of the following statements is false?
a) IF X can be solved in polynomial, time then so can Y
(GATE-2008) (2 Marks)
a) Q solves the subset-sum problem in polynomial time when the input is encoded in unary

b) X is NP – complete
b) Q solves the subset-sum problem in polynomial time when the input is encoded in binary

c) X is NP – hard
c) The subset sum problem belongs to the class NP

d) X is in NP – but not necessarily NP – complete d) The subset sum problem is NP-hard

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q A problem in NP is NP – complete if [GATE - 2006] (2 Marks) Q Let SHAM3 be the problem of finding a Hamiltonian cycle in graph G = (V, E) with |V| divisible
a) It can be reduced to the 3 – SAT problem polynomial time by 3 and DHAM3 be the problem of determining if a Hamiltonian cycle exists in such graphs.
Which one of the following is true? (GATE – 2006) (1 Marks)
a) Both DHAM3 and SHAM3 are NP – hard

b) The 3-SAT problems can be reduced to it in polynomial time

b) SHAM3 is NP – hard, but DHAM3 is not

c) It can reduce to any other problem in NP in polynomial time

c) DHAM3 is NP – hard, but SHAM3 is not

d) Some problem in NP can be reduced to it in polynomial time

d) Neither DHAM3 nor SHAM3 is NP – hard


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Let S be an NP – complete problem Q and R be two other problems not known Q Consider three decision problems P 1, P2 and P3. It is known that P1 is decidable
to be in NP. Q is polynomial – time reducible to S and S is polynomial – time and P2 is undecidable. Which one of the following is TRUE? (GATE-2005) (2 Marks)
reducible to R. Which one of the following statements is true? (GATE-2006) (2 (A) P3 is decidable if P1 is reducible to P3
Marks)
a) R is NP – complete
(B) P3 is undecidable if P3 is reducible to P2

b) R is NP – hard
(C) P3 is undecidable if P2 is reducible to P3

c) Q is NP – complete
(D) P3 is decidable if P3 is reducible to P2’s complement

d) Q is NP- hard
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Consider the following two problems on undirected graphs: (GATE – 2005) (1 Q Ram and Shyam have been asked to show that a certain problem Π is NP-complete. Ram shows a
polynomial time reduction from the 3-SAT problem to Π, and Shyam shows a polynomial time reduction
Marks) from Π to 3-SAT. Which of the following can be inferred from these reductions? (GATE-2003) (2 Marks)
𝜶: Given G (V, E) does G have an independent set of size |V| - 4?
(A) Π is NP-hard but not NP-complete
β: Given G(V, E), does G have an independent set of size 5?

Which one of the following is true? (B) Π is in NP, but is not NP-complete
a) 𝛼 is in P and β NP – complete

b) 𝛼 is NP – complete in and β is in P (C) Π is NP-complete


c) Both 𝛼 and β are NP – complete

d) Both 𝛼 and β are in P (D) Π is neither NP-hard, nor in NP


www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q Which of the following is in P? Q The problem 3-SAT and 2-SAT are


(A) both in P (B) both NP complete
PATH, HAMPATH, SAT, 3AT
a) SAT b) 3SAT

c) PATH d) HAMPATH (C) NP-complete and in P respectively (D) undecidable and NP-complete respectively

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following is false? Q The statement P ⊆ Np is
a) PATH is a class problem b) Dijkstra’s algorithm is a problem in P
a) true b) false

c) CLQUE is a NP class problem d) RELPRIME is a NP class problem c) still open for argument d) none of these

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q If 1 p 2 (1 is polynomially reduces to 2) then consider the statements


S1: if 1  P then 2  P
S2: if 2  P then 1  P
S3: if 1 is un-decidable then 2 is Un- decidable
S4: if 2 is un-decidable then 1 is Un- decidable

a) Only S1 and S2

b) Only S2 and S3

c) Only S3 and S4

d) Only S4 and S1
www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

Q If there is an NP – complete language L whose complement is in NP, then the Q The Travelling Salesman Problem (TSP) is
complement of any language in NP is in a) NP but not NP complete b) NP – complete
a) NP b) P c) Both a and b d) None of these

c) Neither NP nor NP – complete d) none of these

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in
Q Which of the following statements are TRUE?
1. The problem of determining whether there exists a cycle in an undirected graph is in P.
Q Which of the following is true about NP-Complete and NP-Hard problems.
2. The problem of determining whether there exists a cycle in an undirected graph is in NP. (A) If we want to prove that a problem X is NP-Hard, we take a known NP-Hard
3. If a problem A is NP-Complete, there exists a non-deterministic polynomial time algorithm to
solve A. problem Y and reduce Y to X
(A) 1, 2 and 3 (B) 1 and 2 only
(B) The first problem that was proved as NP-complete was the circuit satisfiability
problem.
(C) 2 and 3 only (D) 1 and 3 only (C) NP-complete is a subset of NP Hard
(D) All of the above
(E) None of the above

www.knowledgegate.in www.knowledgegate.in

www.knowledgegate.in www.knowledgegate.in

A) 1, 2 and 3 B) 1 and 2 only


C) 3 and 2 only D) 1 and 3 only

www.knowledgegate.in

www.knowledgegate.in

You might also like