Toc Notespptxpdf Lyst1752818763003
Toc Notespptxpdf Lyst1752818763003
Theory of Computation
Core subjects for CS/IT Students in university and Competitive Exams.
at e
G
• In GATE 8-10 Marks out of 100 Marks, and 6-7 questions on an average
e
• In NET 18-20 Marks out of 200 marks and 7-8 questions
g
• Both parts are important Theory and Numerical
• Needs less time, good scoring
d
• Not Applied in Industry
e
• Syllabus: Regular expressions and finite automata. Context-free grammars and push-down
l
automata. Regular and context - free languages. Pumping lemma. Turing machines and
undecidability.
n ow
www.knowledgegate.in
INTRODUCTION TO THEORY OF COMPUTATIONS
• Theory of Computation (TOC) is a branch of theoretical computer science that addresses:
at e
• What can be computed, How efficiently can it be computed, What limitations exist in computation?
G
• It involves the study of abstract machines, also known as automata, and mathematical models that define what
e
problems can be solved using these machines.
• TOC focuses on different computational models, their capabilities, and the complexity of solving problems. The
g
main areas it deals with include:
• Automata Theory: Studies different types of automata (e.g., finite automata, pushdown automata) and their
d
abilities to solve problems.
e
• Formal Languages: Explores the classification of languages and grammars that machines can recognize.
l
• Computability Theory: Investigates which problems can or cannot be solved by any computational model.
• Complexity Theory: Considers the resources (time, space) needed to solve problems and categorizes them
w
based on difficulty (e.g., P, NP).
n o www.knowledgegate.in
• Machine Communication:
PROBLEM
at e
G
• Machines play a crucial role in human development, and we need a language to communicate with them.
e
However, this language need not be as complex as natural languages.
• Formal vs. Informal Languages:
g
• Machines use formal languages, which are structured and concise, unlike informal languages used in daily
human interaction.
d
• Language Definition:
e
• A language is "a system suitable for expressing ideas, facts, or concepts" using a set of symbols.
w l
n o www.knowledgegate.in
METHODS TO DEFINE LANGUAGE
at e
• In natural language, we can list a finite and predefined set of words in a dictionary, but the
e G
sentences formed using these words are infinite. To determine which sentences are valid or
invalid, we use grammar or rules as a mechanism.
g
l e d
n ow
www.knowledgegate.in
MATHEMATICL DEFINATION OF LANGUAGE
• SYMBOL- Symbols are the basic building blocks, which can be any character/token. (cow,
at e
G
sheep, , white flag, , , etc.) (in English we called them as letters).
e
• ALPHABET- An alphabet is a finite non empty set of symbols, (every language has its own alphabet). here in toc,
g
we use symbol Σ for depicting alphabet. e.g. Σ = {0,1}. for English Σ = {a, b, c, …., z} (in English also alphabet is a
d
set of letters, thought in general we called them as alphabet).
e
• STRING - It is a finite sequence of symbols (which are the member of set alphabet). E.g. Σ = {a, b} String- aabb,
l
aa, b, so on. (in English we called them as words).
w
• 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.
n o www.knowledgegate.in
generate infinite strings/words.
at e
• Similarly, in our system we have finite number of symbols/letters but using those letters we can
• So, we may have languages that have infinite number of words, so it is not possible for us to list them,
G
we have to use some framework, which can somehow represent the same language. There are mainly
e
two methods to represent a language
g
• by a grammar that generates a language [RG generate RL]
• by a machine that accepts a language [FA accept RL language]
Machine
l e d Grammar
n ow
www.knowledgegate.in
SOME BASIC OPERATIONS ON STRINGS
at e
• So, before we proceed further let’s do a little home work on string, which will help us
throughout the subject.
e G
• Length of a string - It is defined as number symbol in the string. Denoted like |W|, e.g. length
of string |00110| = 5.
g
• |aaba| =
l e d
• |010| =
n ow
www.knowledgegate.in
at e
Concatenation of string- Let x and y be two strings, then concatenation is defined
as the string formed by making a copy of string x followed by a copy of string y.
(NOTE- It’s not commutative)
E.g. w = ab, x= ba
wx =
ge G
xw =
l e d
wx =
n ow
w = w 1 w 2 w 3… … w m x = x1 x2 x3… … xn
a
W = w 1 w2 w3 … … wn
ge G
wr =
l e d
|w|
n ow
|wr|
www.knowledgegate.in
at e
Empty/Null String- The string with zero occurrence of symbols. It is denoted by ∈,
|∈|=0. If there is a string w, then wn stands for the strings obtained by repeating
w, n times.
w3 = www
ge G
d
w2 = ww
w1 = w
w0 =
w l e
w∈ = ∈w =
n o www.knowledgegate.in
t e
Substring- Any string of consecutive symbols in some string ‘w’ can be collectively
a
said as a substring. E.g. w= abab its substrings can be ab, a, ba…etc.
1. utg
S u b s
ge G t r i n g
2. sbr
3. rts
l e d
4. str
5. sub
6. ∈
n ow
www.knowledgegate.in
Q Consider a sting ‘GATE’ find the total number of substring possible?
Substring of length 0
Substring of length
1
Substring of length
2
Substring of length
3
at e
Substring of
length 4
G
Number of sting
1 4 3 2 1
e
possible
g
SUBSTRINGS ∈ G, A, T, E GA, AT, TE GAT, ATE GATE
length 0
l d
Substring of Substring Substring Substring Substring
e
of length 1 of length 2 of length 3 of length
4
w
Number of
sting possible
o
SUBSTRINGS
n
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
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]-1]
www.knowledgegate.in
t
Q Consider a sting ‘GATE’ find the total number of prefix and suffix possible?
Prefix(GATE) =
a e
Suffix(GATE) =
ge G
l e d
n ow
If there is a string of length n then no of prefix or
www.knowledgegate.insuffix will be n+1
Q if ∑ = {a, b} then, find the following?
∑0 =
at e
∑1 =
∑2 =
ge G
∑3 =
l e d
n ow
• ∑K is the set of all the strings from the alphabet ∑ of length exactly K.
• ∑k = {W | |W| = K} (using the symbols from the alphabet ∑)
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
•
•
LANGUAGES
at e
Since languages are sets, the union, intersection and difference of two languages are immediately defined.
The complement of a language is defined with respect of ∑*
G
c
• L =
•
r
L =
dge
The reverse of a language is the set of all the strings after reversal
e
• The concatenation of two languages L1 and L2 is the set of all the strings obtained by concatenating any elements
l
of L1 and L2.
• L1 L2 =
• Ln =
• L* =
n w
• Let Ln is defined as L is concatenated with itself n times.
o www.knowledgegate.in
Marks)
1) abaabaaabaa
at e
Q Given the language L = {ab, aa, baa}, which of the following strings are in L*? (GATE-2012) (1
2) aaaabaaaa
ge G
3) baaaaabaaaab
4) baaaaabaa
l e d
n ow
(A) 1, 2 and 3
(B) 2, 3 and 4
(C) 1, 2 and 4
(D) 1, 3 and 4
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
Automaton
at e
• An automaton is a self-operating system that transforms, transmits, and utilizes energy,
materials, and information to perform functions without human involvement. The term often
G
refers to a machine that follows predefined rules to execute complex tasks autonomously.
e
Examples include automatic machine tools, packing machines, and photo printing devices.
e dg
w l
n o www.knowledgegate.in
FINITE AUTOMATA
at e
• A finite automaton is a computational model with a limited set of states, where control shifts
G
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
1.
classified into two types-
Finite automata without output
d e
in pattern matching, lexical analysis, parsing, and more. Finite automata can be broadly
g
e
1. Deterministic finite automata.
l
2. Non deterministic finite automata.
3. Non deterministic finite automata with ∈
2.
ow
Finite automata with output
1. Moore machine
n
2. Mealy machine
www.knowledgegate.in
at e
• A finite automaton is limited in its ability to store information during computation because it
lacks temporary storage. The machine can only store a finite amount of information by
switching between a limited number of states. As a result, it can only handle scenarios where
G
the amount of information to be stored is strictly bounded.
dge
w l e
n o www.knowledgegate.in
DETERMINISTIC FINITE AUTOMATA
A deterministic finite automaton (DFA) is defined by 5-tuple (Q,Σ,δ,S,F) where:
• Q is a finite and non-empty set of states
at e
G
• Σ is a finite non-empty set of finite input alphabet
e
• δ is a transition function, ( δ: Q × Σ 🡪 Q)
• S is initial state (always one) (S∈ Q)
e dg
• F is a set of final states (F ⊆ Q) (0<=|F|<=N, where n is the number of states)
w l
n o www.knowledgegate.in
A deterministic finite automaton (DFA) operates through
various components:
• Input Tape: Divided into squares, each containing a
at e
G
symbol from the input alphabet. It has end markers
e
(¢ at the left and $ at the right) or can be infinite. The
input string lies between these markers.
e g
• Reading Head: This head reads one square at a time
d
• Finite Control: Acts as the inference engine and
l
manages transitions between states.
• A DFA ensures a unique computation for each input
w
string, making it deterministic. DFAs are commonly
o
used in tasks like lexical analysis (spell checking) in
compiler design.
n www.knowledgegate.in
Representation
TRANSITION STATE DIAGRAM- A graphical representation where each circle
represents a state, and directed edges show transitions between states. The initial δ
at e Σ
G
state has an arrow pointing to it, and the final state is represented by two a b
e
concentric circles. q0
Q
g
q1
TRANSITION TABLE- A two-dimensional table where rows represent states, and
d
columns represent input symbols. The table shows how the machine transitions
e
between states based on inputs.
w l
TRANSITION ID- δ {qi, a) = qj, This notation indicates that when the machine is in
state qi and reads input symbol a, it transitions to state qj.
n o www.knowledgegate.in
ACCEPTANCE BY DFA
at e
• Let ‘w’ be any string designed from the alphabet Σ, corresponding to w, if there
G
exist a transition for which it starts at the initial state and ends in any One of the
e
final states, then the string ‘w’ is said to be accepted by the finite automata. δ*
(q0, w) = qf for some qf ∈ F.
dg
• Mathematically, it can be represented as: - L(M) = {w ∈ Σ* | δ*(S, w) ∈F}
e
w l
n o www.knowledgegate.in
Q. Consider the following table of an FA
at e
If the final state is q4, to which of the following string is accepted?
1. aaaaa
2. aabbaabbbbb
ge G
d
3. bbabababbb
a) 1&2
w l e
o
b) 2&3
n
c) 3&1
d) all of the above
www.knowledgegate.in
Marks)
G
Consider the strings ,
e
Which of the following statements is true?
e dg
(B) The automaton accepts each of u, v, and w
l
(C) The automaton rejects each of u, v, and w
w
o
(D) The automaton accepts u but rejects v and w
n
• 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
languages. www.knowledgegate.in
t e
Q Design a minimal DFA that accepts a language ‘L’, where L={a}
over the alphabet ∑={a}.
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, where every accepted string ‘w’ starts with substring s
a
G
i) s = b
dge
e
ii) s = ab
w l
n o
iii) s = abb
www.knowledgegate.in
Conclusion
at e
• Dead state is required
ge G
• if w = sx, |s| = m, then no of states in the DFA is m+2
l e d
n ow
www.knowledgegate.in
t e
Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ ends with substring ‘s’.
a
G
i) s = ab
dge
e
ii) s = aa
w l
n o
iii) s = bab
www.knowledgegate.in
Conclusion
at e
ge G
• if w = xs, |s| = m, then no of states in the DFA is m+1
d
• No need of dead state
l e
• Can not stay of final state for ever
w
n o www.knowledgegate.in
Q Consider the following language:
L = { w∈{0,1}∗ ∣ w ends with the substring 011 }
at e
Which one of the following deterministic finite automata accepts L? (GATE 2021) (2 MARKS)
G
(A)
(B)
dge
(C)
w l e
(D)
n o www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s.
a
G
i) abb
dge
ii) aba
w l e
n o www.knowledgegate.in
Conclusion
at e
G
• if w = xsx, |s| = m, then no of states in the DFA is m+1
dge
e
• Can loop on final state
w l
n o www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with a.
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following Deterministic Finite Automata (GATE-2015) (2 Marks)
Which of the following is true?
a
ge G
l e d
w
(A) It accepts all strings with prefix as “aababb”
o
(B) It accepts all strings with substring as “aababb”
n
(C) It accepts all strings with suffix as “aababb”
a
a) Begin either with 0 or 1
ge G
d
b) End with 0
c) End with 00
w l e
o
d) Contain the substring 00
n www.knowledgegate.in
Q Consider the following machine M
What is the language L(M) accepted by this machine?
at e
ge G
l e d
w
a) L(M) = {Set of all words starting with aabb}
o
b) L(M) = {Set of all words having aabb as a sub word}
n
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
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with same symbol.
a
ge G
e d
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b} such
l
that every accepted string start and end with different symbol.
n ow
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XS.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XSX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
Q Consider the machine M shown below L(M)?
at e
ge G
l e d
ow
a) L(M) = {words starting with aa or bb}
b) L(M) = {words ending with aa or bb}
n
c) L(M) = {words containing aa or bb as a sub word}
d) None of these
www.knowledgegate.in
at e
Q Let L be the set of all binary strings who’s last two symbols are the same. The
number of states in the minimum state deterministic finite state automation
accepting L is (GATE-1998) (1 Marks)
a) 2 b) 5 c) 8
ge G d) 3
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
that every string ‘w’ accepted must be like
i) |w| = 3
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
ge G
ii) |w|<=3
l e d
n
iii) |w|>=3
ow
www.knowledgegate.in
t e
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.
a
ge G
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
l e d
ow
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
n www.knowledgegate.in
t e
Q The minimum possible number of states of a deterministic finite automaton that
accepts a regular language L is_______(GATE-2017) (2 Marks)
a
G
L = {w1aw2 | w1, w2 ∈ {a, b}*, |w1| = 2, |w2|>=3}
dge
w l e
n o www.knowledgegate.in
Q Consider the machine M (GATE-2005) (2 Marks)
The language recognized by M is :
at e
ge G
l e d
w
(A) {w ∈ {a, b}* / every a in w is followed by exactly two b’s}
o
(B) {w ∈ {a, b}* every a in w is followed by at least two b’}
n
(C) {w ∈ {a, b}* w contains the substring ‘abb’}
(D) {w ∈ {a, b}* w does not contain ‘aa’ as a substring}
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string ‘w’ accepted must be like
a
G
i) |w| = 0(mod 3) ii) |w|=1(mod 4)
dge
w l e
n o www.knowledgegate.in
Conclusion
at e
G
No of states will be n, if the equation is on format r (mod n)
dge
w l e
n o www.knowledgegate.in
that every string accepted must contain
i) number of a is, |w|a = 0(mod 2)
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
ge G
l e
iii) number of a is |w|a = 2(mod 3)
d iv) number of a is |w|a = 1(mod 4)
n ow
www.knowledgegate.in
t e
Q How many minimum states are required in a DFA to find whether a given binary string
a
has odd number of 0’s, there can be any number of 1’s. (GATE-2015) (1 Marks)
(A) 1 (B) 2 (C) 3 (D) 4
ge G
l e d
n ow
www.knowledgegate.in
divisible by 3} has (GATE-2002) (2 Marks)
(A) 2 states (B) 3 states (C) 4 states (D) 5 states
t e
Q The smallest finite automation which accepts the language {x | length of x is
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Let ∑ = {0, 1}, then an automaton A accepting only those words from ∑ having
a
an odd number of 1’s requires _________ states including the start state
a) 2 b) 3 c) 4 d) 5
ge G
l e d
n ow
www.knowledgegate.in
divisible by 500} has
a) 200 states b) 300 states c) 400 states d) 500 states
t e
Q The smallest finite automaton which accepts the language {x⎮ length of x is
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
a
that every string accepted must contain odd occurrence of the substring ‘ab’.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
a
that every string accepted must contain even occurrence of the substring ‘baa’.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q how many DFA can be designed, with a fixed initial state, over an
alphabet ∑ = {a, b}, and the number of states be two.
a
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
• If no of states is |Q| = n, and no of input alphabet |∑| = m
nn*m * 2n
• Then no of states will bewww.knowledgegate.in
t e
Q how many DFA can be constructed over the alphabet, such that no of states |Q|
a
= 2 and size of input alphabet is |∑| = 2, that accepts empty language(Φ)?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q how many DFA can be constructed over the alphabet, such that no of states |Q|
a
= 2 and size of input alphabet is |∑| = 2, that accepts universal language (∑*)?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
a
b} such that for every accepted string 2nd from left end is always b.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
a
b} such that for every accepted string 2nd from right end is always b.
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑= {a, b}, such
that every string ‘w’ which is accepted starts with ‘a’ & length is divisible by 3, i.e.
0(mod 3)?
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ which is accepted starts with ‘ab’ & length is divisible by
2(mod 4)?
ge G
l e d
n ow
• No of states will be n, n www.knowledgegate.in
= first condition + second condition -1
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain be like,
at e
G
no of a = 0(mod 2) || no of b = 0(mod 2) ?
dge
w l e
n o
cross product method(one more approach , where concentrate on even and odd logic)
www.knowledgegate.in
t e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
a
b}, such that every string accepted must contain be like, no of a = 0(mod
G
2) && no of b = 0(mod 2)?
dge
w l e
n o www.knowledgegate.in
t e
Q. Consider the following deterministic finite automaton (DFA) defined over the alphabet, Σ = {𝑎,
a
𝑏}. Identify which of the following language(s) is/are accepted by the given DFA. (Gate 2025)
ge G
l e d
A) The set of all strings containing an even number of 𝑏’s.
w
B) The set of all strings containing the pattern 𝑏𝑎𝑏.
o
C) The set of all strings ending with the pattern 𝑏𝑎𝑏.
n
D) The set of all strings not containing the pattern 𝑎𝑏𝑎.
www.knowledgegate.in
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b, c}, such
that every string accepted must contain be like, a = 0(mod 2) && no of b = 0(mod
3) && no of c = 0(mod 5)?
ge G
l e d
n ow
• if, n(mod m) && p(mod r), then the no of states will be m*r, if m & r are
relatively prime to each other and working on different symbol
www.knowledgegate.in
at e
Q A minimum state deterministic finite automaton accepting the language L={w |
w ε {0,1} *, number of 0s and 1s in w are divisible by 3 and 5, respectively} has
(GATE-2007) (2 Marks)
(A) 15 states (B) 11 states
ge G
(C) 10 states (D) 9 states
l e d
n ow
www.knowledgegate.in
at e
Q Consider a DFA over ∑ = {a, b} accepting all strings which have number of a’s
divisible by 6 and number of b’s divisible by 8. What is the minimum number of
states that the DFA will have? (GATE-2001) (2 Marks)
(A) 8 (B) 14 (C) 15
ge G (D) 48
l e d
n ow
www.knowledgegate.in
number of l’s and 0’s is respectively. (GATE-2004) (2 Marks)
(A) divisible by 3 and 2
at e
Q The following finite state machine accepts all those binary strings in which the
n o
(D) divisible by 2 and 3
www.knowledgegate.in
Q. Consider the following DFA in which So is the start and
S1,S3 are the final states. What language does this DFA
recognize?(GATE 2007, 2 Marks)
at e
a) All strings of x and y
ge G
b) All strings of x and y and even number of x and even
d
number of y or odd no of x and odd number of y
c) All strings of x and y which have equal number of x and y
l e
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
w
n o www.knowledgegate.in
at e
Q Given below are two finite state automata (→ indicates the start state and F
indicates a final state) Which of the following represents the product automaton
Z×Y? (GATE-2008) (2 Marks)
ge G
l e d
n ow
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ =
{0,1}, such that every string ‘w’ which is accepted has a decimal
at e
G
equivalent
e
i) 0(mod 3)
g
ii) 2(mod 4)
d
iii) 0(mod 5)
e
iv) 2(mod 6)
v) 3(mod 8)
w l
n o
on a format of m (mod n)
1) if n is odd, number of states will be n
2) if n is even and n=2m, then number of states will be m+1
3) if n is even and n! =2m, then for number of states no direct formula
www.knowledgegate.in
t e
Q Consider the following deterministic finite automaton (DFA) The number of strings
a
of length 8 accepted by the above automaton is _________. (GATE 2021) (1 MARKS)
ge G
l e d
n ow
www.knowledgegate.in
Consider the following language:
L = {w ∈ {0, 1}* | w ends with the substring 011}
at e
ge G
Which one of the following deterministic finite automata accepts L?
l e d
n ow
www.knowledgegate.in
COMPLIMENT OF DFA
at e
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
ge G
b}, such that every string accepted must not contain a substring aaa?
l e d
n ow
www.knowledgegate.in
•
complement of the finite automata.
Note
at e
The finite automata which is obtained by interchanging final & non-final states is known as
•
L(FA) U L(FAC) = ∑* L(FA) ∩ L(FAC) = Φ
ge
L(FA) subset of ∑* and L(FA)C subset of ∑*G
•
l e d
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
ow
Complement always exist for DFA (as it is a complete system)
n www.knowledgegate.in
Q construct the DFA for the following languages:
i) L= {am bn | m, n >= 0}
a
ii) L = {am bn cp | m, n, p >= 0}
t e
ge G
l e d
n ow
• 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:
i) L= {am bn | m>= 0, n>=1} ii)L= {am bn | m>= 0, n>=2}
at e
ge G
l e d
n ow
• If type is L = {am bn | m>= 0, n>=j}, then no of states is j+2
www.knowledgegate.in
Q construct the DFA for the following languages:
i) L = {am bn | m>= 1, n>=0} ii) L = {am bn | m>= 2, n>=0}
at e
ge G
l e d
n ow
• If type is L = {am bn | m>= i, n>=0}, then no of states is i+3
www.knowledgegate.in
Q construct the DFA for the following languages:
L = {am bn | m >= 1, n>= 2}
at e
ge G
l e d
n ow
• If type is L = {am bn | m>= i, n>=j}, then no of states is i+j+2
www.knowledgegate.in
t e
Q Consider the DFAs M and N given above. The number of states in a minimal
a
DFA that accepts the language L(M) ∩ L(N) is __________. (GATE-2015) (2
G
Marks)
e
(A) 0
(B) 1
e dg
w l
o
(C) 2
(D) 3
n www.knowledgegate.in
t e
Q The FSM over an alphabet {a, b} shown in the figure accepts
a
a) all stings
ge G
b) no stings
c) ϵ - alone
l d
d) None of these
e
n ow
www.knowledgegate.in
L = {ank| k>0, and n is a positive integer constant}
What is the minimum number of states needed in DFA to recognize L?
at
Q Definition of a language L with alphabet {a} is given as following.
e
(NET-DEC-2018) (2 Marks) (GATE-2011)
(A) k+1 (B) n+1
ge G
(C) 2(n+1) (D) 2(k+1)
l e d
n ow
www.knowledgegate.in
1998, 2 Marks)
a) The numbers 1,2,4,2n , written in unary
at e
Q. Which of the following can be recognized by a deterministic finite automation? (GATE
ones
g G
b) The set of binary string in which the number of zeroes is the same as the number of
e
c) The numbers 1,2,4,8,2n , written in binary
d
d) The set {1,101, 11011,1110111,...}
w l e
n o www.knowledgegate.in
at e
Q Consider the set of strings on {0,1} in which, every substring of 3 symbols has at most two
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
G
is shown below. (GATE-2012) (2 Marks)
dge
w l e
n o www.knowledgegate.in
at e
Q Consider the following deterministic finite state automaton M. Let S denote the set of
seven-bit binary strings in which the first, the fourth, and the last bits are 1. The number of
strings in S that are accepted by M is (GATE-2003) (2 Marks)
G
(A) 1 (B) 5 (C) 7 (D) 8
dge
w l e
n o www.knowledgegate.in
at e
Q Let L⊆{0,1}∗ be an arbitrary regular language accepted by a minimal DFA with k
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}
ge G
(B) L ∪ {01}
l e d
ow
(C) {0,1}* – L
(D) L⋅L
n www.knowledgegate.in
t e
Q.Consider the 5-state DFA M accepting the language L(M) ⊂ (0+1)’ shown below.
a
For any string w ∈(0+1)’ let n0 (w) be the number of 0’s in w and n1(w) be the
G
number of 1’s in W. (Gate 2024,CS) (2 Marks) (MSQ)
e
Which of the following statements is/are FALSE?
g
(a) States 2 and 4 are distinguishable in M
d
(b) States 3 and 4 are distinguishable in M
e
(c) States 2 and 5 are distinguishable in M
l
(d) Any string W with n0(w)=n1 (w) is in L(M)
w
n o www.knowledgegate.in
MINIMIZATION OF FINITE AUTOMATA
at e
• The process of removing states that do not affect the language-accepting capability of a deterministic finite
G
automaton (DFA). The result is a minimal deterministic finite automaton (MFA), which is unique for a given
language.
e
• Designing a minimal DFA directly can be difficult, so the recommended approach is to first design a DFA and then
g
minimize it.
• States in DFA can be classified as:
d
• Productive States: These states contribute to the machine’s ability to accept a language. Their presence
affects the language-accepting power.
l e
• 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.
n ow
www.knowledgegate.in
t e
• NON- PRODUCTIVE STATES- These states don’t add anything to the language accepting power to the machine.
They can further be divided into three types, Dead State, Unreachable State, Equal State
a
G
• Dead State- It is basically created to make the system complete, can be defined as a state from which there is no
transition possible to the final state. In a DFA there can be more than one dead state but logically always one
e
dead state is sufficient to complete the functionality.
g
• Unreachable Sate- It is that state which cannot be reached starting from initial state by parsing any input string.
l e d
n ow
www.knowledgegate.in
at e
• Equal State-These are those states that behave in same manner on each and every input
string. That is for any string w where w ∈ Σ* either both of the states will go to final state or
both will go to non-final state. (remember the example of an equal state DFA).
e G
• 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
g
k-equivalent for all k ≥ 0, then they are k-equivalent.
l e d
n ow
www.knowledgegate.in
Procedure of Minimization
at e
• For this first of all, group all the non-final states in one set and all final states in another set.
G
• 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
e
same set) on each input alphabet.
g
• if the answer is yes, then these two states are equal, otherwise not.
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
t e
Q A deterministic finite automation (DFA)D with alphabet {a, b} is given below (GATE-2011) (2
Marks)
a
ge G
d
Which of the following finite state machines is a valid minimal DFA which accepts the same
e
language as D?
w l
n o www.knowledgegate.in
t e
Q. Let Σ = {1,2,3,4}. For 𝑥 ∈ Σ∗ , let 𝑝𝑟𝑜𝑑(𝑥) be the product of symbols in 𝑥 modulo 7. We take
𝑝𝑟𝑜𝑑(𝜖) = 1, where 𝜖 is the null string.
a
G
For example, 𝑝𝑟𝑜𝑑(124) = (1 × 2 × 4) mod 7 = 1.
dge
The number of states in a minimum state DFA for 𝐿 is ___________. (Answer in integer) (Gate
2025)
w l e
n o www.knowledgegate.in
NON DETEMINISTIC FINITE AUTOMATA
at e
• Non-determinism in finite automata means that an automaton has multiple possible moves in
G
a given state for a particular input. Unlike deterministic automata, where the next move is
uniquely defined, non-deterministic automata allow for a set of possible transitions.
• Key points:
ge
• Choice of Moves: At any given step, the automaton can choose from multiple transitions
for the same input.
d
• Theoretical Concept: Non-deterministic machines are theoretical models, not meant to be
practice.
w l e
physically implemented. They help simplify the design process but are not directly used in
• Purpose: NFAs are easier to design compared to deterministic automata (DFA), and every
NFA can be converted into an equivalent DFA for practical applications.
n o www.knowledgegate.in
FORMAL DESCRIPTION OF NDFA
• A Non-Deterministic finite automaton (NDFA) is a 5-tuple (Q,Σ,δ,S,F) where:
at e
G
• Q is a finite and non-empty set of states
e
• Σ is a finite non-empty set of finite input alphabet
•
e dg
δ is a transition function δ: Q × Σ 🡪 2Q
w l
F is a set of final states (F ⊆ Q) (0<=|F|<=N), where n is the number of states
n o www.knowledgegate.in
•
Some points to remember
at e
Every DFA is also an NFA. Every NFA can be translated to an equivalent DFA, so their language
accepting capability is same Both only recognize regular languages. Accepting power of NDFA=
G
Accepting power of DFA.
ge
NFA need not to be a complete system. There can be a state that doesn’t have any transition on some
input symbol. A null transition is also possible for NFA, such special NFA are called Null-NFA. We will
discuss it later.
d
•
l e
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.
w
NDFA will respond for only valid strings and no need to respond for invalid strings. (it is a
o
Incomplete system)
n www.knowledgegate.in
•
ACCEPTANCE BY NDFA
at e
Let ‘w’ be any string defined over the alphabet Σ, corresponding to w, there can be multiple
G
transitions for NFA starting from initial state, if there exist at least one transition for which we
start at the initial state and ends in any One of the final state, then the string ‘w’ is said to be
dge
accepted by the non-deterministic finite automata, otherwise not.
* *
Mathematically, it can be represented as, L(M) = {w ∈ Σ | δ (q0, w) ∈F}
w l e
n o www.knowledgegate.in
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
at e
ge G
l e d
n ow
conclusion🡪 if w = sx, |s| = m,www.knowledgegate.in
then no of states in the NDFA is m+1
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}.
where every accepted string ‘w’ ends with substring ‘s’, Where s = bab
at e
ge G
l e d
n ow
conclusion🡪 if w = sx, |s| = m,www.knowledgegate.in
then no of states in the NDFA is m+1
t
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
a
b}. where every accepted string ‘w’ contains sub string s, Where s = aba
e
ge G
l e d
n ow
conclusion🡪 if w = xsx, |s| = m, then no of states in the DFA is m+1
www.knowledgegate.in
at
What is the minimum number of states in a non-deterministic finite automaton
that accepts L? (GATE-2010) (1 Marks) e
Q Let w be any string of length n is {0,1}*. Let L be the set of all substrings of w.
ge G (D) 2n-1
l e d
n ow
www.knowledgegate.in
t e
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
a
such that every accepted string start and end with same symbol.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
a
such that every accepted string start and end with different symbol.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
a
{a, b} such that every accepted string w, is like w=SX , Where s = aaa/bbb
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
a
{a, b} such that every accepted string w, is like w=XS , Where s = aaa/bbb
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a NFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ accepted must be like
a
G
i) |w| = 3
dge
e
ii) |w|<=3
w l
n o
iii) |w|>=3
www.knowledgegate.in
at e
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
s
b}, such that every string accepted must contain exactly two a’ .
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
s
b}, such that every string accepted must contain at least two a’ .
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
s
b}, such that every string accepted must contain at most two a’ .
ge G
l e d
n ow
www.knowledgegate.in
rd
at e
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
such that for every accepted string 3 from right end is always a.
ge G
l e d
n ow
www.knowledgegate.in
Q The FSM shown in the figure accepts
at e
ge G
a) all strings
l e d
w
b) no strings
n o
c) ϵ - alone
d) None of these
www.knowledgegate.in
Q (GATE-2014) (2 Marks)
at e
G
(A) {q0, q1, q2}
dge
e
(C) {q0, q1, q2, q3}
(D) {q3}
w l
n o www.knowledgegate.in
of the following is True? (GATE 2008, 2 Marks)
a) L1 = L2
at e
Q. Consider the following two finite automata. M1 accepts L1 and M2 accepts L2 which one
b) L1 ⊂ L2
c) L1∩ L2’= Φ
d) L1 ∪ L2 ≠ L1
ge G
l e d
n ow
www.knowledgegate.in
(GATE-2005) (2 Marks)
at e
Q Consider the non-deterministic finite automaton (NFA) shown in the figure.
State X is the starting state of the automaton. Let the language accepted by the
G
NFA with Y as the only accepting state be L1. Similarly, let the language accepted by
e
the NFA with Z as the only accepting state be L2. Which of the following statements
about L1 and L2 is TRUE?
g
d
(A) L1 = L2 (B) L1 ⊂ L2 (C) L2 ⊂ L1 (D) None of the above
w l e
n o www.knowledgegate.in
Q. Consider the NFAM shown below. (GATE 2003, 2 Marks)
at e
Let the language accepted by M be L. Let L1 be the language accepted by the NFA M1 ,
obtained by changing the non-accepting state and by changing the non-accepting state of
a) L1 = {0,1}* - L
b) L1 = {0,1}*
c) L1 ⊂ L
g G
M to accepting states. Which of the following statements are True?
e
d) L1 = L
l e d
n ow
www.knowledgegate.in
NFA and DFA Equivalence
at e
• 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
G
every NFA and DFA has equal power that means, for every language if a NFA is possible, then
e
DFA is also possible. So, every NFA can be converted to DFA. The process of conversion of an
NFA into a DFA is called Subset Construction.
dg
• 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
e
w l
n o www.knowledgegate.in
Which of the following in NECESSARILY true? (GATE-2008) (2 Marks)
(A) m ≤ 2n (B) n ≤ m
at e
Q Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language.
G
(C) M has one accept state (D) m = 2n
(A) N 2
(B) 2 N
(C) 2N
ge
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)
d
(D) N!
a) k ≥ 2 b) k ≥ n
l e
Q Let N be an NFA with n states. Let k be the number of states of a minimal DFA which is
equivalent to N. Which one of the following is necessarily true? (GATE-2018) (1 Marks)
n
w
2
c) k ≤ n n
d) k ≤ 2
n o www.knowledgegate.in
t e
Q. A regular language 𝐿 is accepted by a non-deterministic finite automaton (NFA) with 𝑛 states.
Which of the following statement(s) is/are FALSE? (Gate 2025)
a
G
A) 𝐿 may have an accepting NFA with < 𝑛 states.
e
B) 𝐿 may have an accepting DFA with < 𝑛 states.
g
C) There exists a DFA with ≤ 2𝑛 states that accepts 𝐿.
D) Every DFA that accepts 𝐿 has > 2𝑛 states.
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
NFA WITH EPSILON MOVES (€-NFA)
at e
• An automaton that consist of null transitions is called a Null- NFA i.e. we allow a transition on
null means empty string.
• €-NFA is a 5-tuple (Q,Σ,δ,S,F) where:
e
• Q is a finite and non-empty set of states
g G
• Σ is a finite non-empty set of finite input alphabet
e d
• δ is a transition function δ: (Q × {Σ U ε}) 🡪 2Q
l
w
• S is initial state (always one) (S∈ Q)
o
• F is a set of final states (F ⊆ Q) (0<=|F|<=N, where n is the number of states
n www.knowledgegate.in
NULL-CLOSURE
at e
• Null closure of a set Q is defined as a set of all the states, which are at zero distance from the
state Q. A set of all the states, that can be reached from the state and along a null- transition.
ge G
• €-Closure(qi)- The set of all the states which are at zero distance from the state qi is called
€-closure(qi). Or the set of all the states that can be reached from the state qi along € labelled
transition path, is known as €-closure(qi).
l e d
n ow
www.knowledgegate.in
•
EQUIVALENCE BETWEEN NULL NFA TO NFA
There will be no change in the initial state.
at e
G
• No change in the total no. of states
•
•
ge
May be change in the number of final states.
All the states will get the status of the final state in the resulting NFA, whose €-closure
d
contains at least one final state in the initial €-NFA.
w l e
n o www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
the set of final states?
a) {q2} b) {q1,q2} c) {q0, q1, q2} d) can’t be determined
t e
Q. If the given NFA is converted to NFA without ∈ moves , which of the following denotes
a
a) 00 11 22 b) 11 22 c) 21
e G
Q. Which of the following strings will not be accepted by the given NFA?
g
d) 22
l e d
n ow
www.knowledgegate.in
at e
G
Q. Which of the following is False?
a) The languages accepted by FAs are regular languages
b) Every DFA is an NFA
ge
c) There are some NFAs for which no DFA can be constructed
d
d) If L is accepted by an NFA with ∈ transitions then L is accepted by an
e
NFA without ∈ transitions
w l
n o www.knowledgegate.in
Q. An FSM can be used to add two given integers. This remark is
at e
G
a) true
b) false
c) may be true
d) none of the above
dge
w l e
n o www.knowledgegate.in
at e
Q Let δ denote the transition function and δ’ denoted the extended transition
function of the ε-NFA whose transition table is given below: (GATE-2017) (2 Marks)
Then, δ’ (q2, aba) is
a) Ø b) {q1, q2, q3}
G
c) {q0, q1, q2}
ge
d) {q0, q2, q3}
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following languages and find which of them are regular?
1. L = {am bn | m, n >=0}
a
2. L = {am bn cp | m, n, p >= 0}
ge G
l e d
3. L = {ax1bx2----zx26 | xi >= 0, 1 <= i <= 26}
ow
4. L = {am bn | 1 <= m <= 100, 1 <= n <= 1200}
n www.knowledgegate.in
1. L = {am bn | m*n = finite}
at e
2.
e
L = {an bn| 1 <= n <= 2|GATE|}
g G
3. n n
L = {a b | 1 <= n <= 2
l e d
37th prime
}
4.
n ow
L = {am bn | m = n, 1 <= n <= 22^10}
www.knowledgegate.in
1. L = {am bn | m = n | m, n> = 0}
at e
2.
3.
ge G
L = {am bn | m < n | m, n >= 0}
L = {am bn | m != n | m, n > 0}
4. m n
l e d
L = {a b | m is divisible by n}
5.
6.
n ow
L = {am bn | m = np, p>=1}
at e
m n p
2. L = {a b c | m = n = p}
ge G
m n p
l e d
3. L = {a b c | m + p = n}
n o
m
w n
4. L = {a b | m + n = odd}
www.knowledgegate.in
1. L = {w c wr | w ∈ Σ*}
at e
2.
3.
L = {w c w | w ∈ Σ *}
L = {w c wr | w ∈ Σ +}
ge G
4. L= {w c w | w ∈ Σ }+
l e d
5.
6.
n ow
L = {w w | w ∈ Σ *}
L= {w wr | w ∈ Σ +}
www.knowledgegate.in
1. L = {w c wr | c, w ∈ Σ *}
at e
2. L = {c w wr | c, w ∈ Σ *}
ge G
d
3. L= {w wr c | c, w ∈ Σ *}
w
4. L = {w c wr | c, w ∈ Σ +
l e
n o
5. L = {c w wr | c, w ∈ Σ +}
6. L= {w wr c | c, w ∈ Σ +}
www.knowledgegate.in
1. L = {w c w | c, w ∈ Σ *}
at e
2.
3.
L = {c w w | c, w ∈ Σ *}
L= {w w c | c, w ∈ Σ *}
ge G
4.
l
+
L = {w c w | c, w ∈ Σ }
e d
5.
6.
n ow
L = {c w w | c, w ∈ Σ +}
L= {w w c | c, w ∈ Σ +}
www.knowledgegate.in
(GATE-2019) (2 Marks)
a) L⋅ LR = {xy | x ∈ L, yR ∈ L}
at e
Q If L is a regular language over ∑ = {a, b}, which one of the following languages is NOT regular?
ge G
b) Suffix (L) = {y ∈ ∑* | ∃x ∈ ∑* such that xy ∈ L}
l e d
c) Prefix (L) = {x ∈ ∑* | ∃y ∈ ∑* such that xy ∈ L}
n ow
d) {w wR | w ∈ L}
www.knowledgegate.in
Q Which of the following languages is/are regular? (GATE-2015) (2 Marks)
L1: {w x wR ⎪ w, x ∈ {a, b}* and ⎪w⎪, ⎪x⎪ >0} wR is the reverse of string w}
at e
L2: {an bm ⎪m ≠ n and m, n≥0
ge G
d
p q r
L3: {a b c ⎪ p, q, r ≥ 0}
w l e
o
(A) L1 and L3 only
(B) L2 only
n
(C) L2 and L3 only
(D) L3 only
www.knowledgegate.in
Q Let L1 = {w ∈ {0, 1}∗ | w has at least as many occurrences of (110)’s as (011)’s}.
at e
e G
Let L2 = {w ∈ {0, 1}∗ | w has at least as many occurrences of (000)’s as (111)’s}.
g
l e d
Which one of the following is TRUE? (GATE-2014) (2 Marks)
w
(A) L1 is regular but not L2
o
(B) L2 is regular but not L1
(C) Both L2 and L1 are regular
n
(D) Neither L1 nor L2 are regular
www.knowledgegate.in
at e
(A) Only (I)
ge G
Which one of the following is CORRECT? (GATE-2014) (2 Marks)
(B) Only (II)
(C) Both (I) and (II)
n ow
www.knowledgegate.in
t e
Q Which one of the following is TRUE? (GATE-2014) (1 Marks)
a
ge G
l e d
n ow
www.knowledgegate.in
at e
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
e
(C) Σ *- P
g G (D) Σ* - Q
l e d
n ow
www.knowledgegate.in
Q Which of the following are regular sets? (GATE-2008) (2 Marks)
at e
ge G
l e d
w
(A) I and IV only (B) I and III only
(C) I only
n o(D) IV only
www.knowledgegate.in
t e
Q Which of the following languages is (are) non-regular? (GATE-2008) (2 Marks)
L1 = {0m1n | 0 ≤ m ≤ n ≤ 10000}
a
e G
L2 = {w | w reads the same forward and backward}
g
e d
L3 = {w ∊ {0, 1} * | w contains an even number of 0’s and an even number of 1’s}
l
ow
(A) L2 and L3 only
(B) L1 and L2 only
n
(C) L3 only
(D) L2 only
www.knowledgegate.in
a) {w wR |w ∈ {0, 1}+} b) {w wR x| x, w ∈ {0,1}+}
at e
Q Which of the following languages is regular? (GATE-2007) (2 Marks)
ge G
c) {w x wR |x, w ∈ {0,1}+}
l e d d) {x w wR| x, w ∈ {0,1}+}
n ow
www.knowledgegate.in
Q Consider the following two statements (GATE-2001) (2 Marks)
at e
(A) Only S1 is correct
ge G
(B) Only S2 is correct
d
(C) Both S1 and S2 are correct (D) None of S1 and S2 is correct
w l e
n o www.knowledgegate.in
Q Consider the following languages (GATE-2001) (2 Marks)
at e
ge G
l e d
Which of the languages are regular?
w
(A) Only L1 and L2
o
(B) Only L2, L3 and L4
(C) Only L3 and L4
n
(D) Only L3
www.knowledgegate.in
Regular Expressions
at e
• 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.
algebraic fashion.
g G
• The regular expressions are useful for representing certain sets of strings(Language) in an
e
• We give a formal recursive definition of regular expressions over ∑ as follows:
e d
• Any terminal symbol (i.e. an element of ∑), ∈ and Φ are regular expressions (Primitive
regular expressions).
l
w
• A regular expression is valid iff it can be derived from a primitive regular expression by a finite
number of applications of operators.
n o www.knowledgegate.in
language. If for example, a, b ∈ ∑, then
• R = a denotes the L = {a}
at e
Regular Language:- Any set(language) represented by a regular expression is called a Regular
ge G
e d
• R = a* denotes the set {∈, a, aa, aaa, ...} known as Kleene closure.
l
ow
• R =(a + b)* denotes {a, b}*
n www.knowledgegate.in
Operators
When we view a in ∑ as a regular expression, we denote it by a.
at e
G
• If R is a regular expression, then (R) is also a regular expression.
e
• The iteration (or closure) of a regular expression R written as R*, is also a regular expression.
dg
• 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
e
l
expression.
• The union of two regular expressions R1 and R2, written as R1 + R2, is also a regular expression.
ow
• The precedence order to solve is ()Bracket, * (Kleene Closure), + Positive Closure,
Concatenation, Union.
n www.knowledgegate.in
IDENTITIES FOR Regular Expression
at e
G
• if P and Q represent the same set of strings.
•
ge
Every regular expression can generate only one regular
language but, a regular language can be generated by more
d
than one regular expression I.e. means two different regular
expression can generate same language.
• r1 = a*
w l e
Two regular expression are said to be equal if they generate same language.
n o
r2 = a* + (aa)*
www.knowledgegate.in
• R={a}
हमारी language बताओ
at e
• R={a + b}
ge G
• R={a + b + c}
l e d
•
n ow
R={a.b}
R={a.b + a}b
www.knowledgegate.in
at e
Q Let S and T be language over Σ = {a, b} represented by the regular expressions
(a + b*)* and (a + b)*, respectively. Which of the following is true? (GATE-2000) (1
Marks)
(A) S ⊂ T
ge G
d
(B) T ⊂ S
(C) S = T
w l e
n
(D) S ∩ T = φ
o www.knowledgegate.in
FINITE AUTOMATA AND regular expression
at e
Q Design a regular expression that represent a language ‘L’, where L={a}
over the alphabet ∑={a}.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}, where every accepted string ‘w’ starts with substring s
G
i) s = b ii) s = ab iii) s = abb
dge
w l e
n o www.knowledgegate.in
t e
Q design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}. where every accepted string ‘w’ ends with substring ‘s’.
G
i) s = ab ii) s = aa iii) s = bab
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}. where every accepted string ‘w’ contains sub string s.
G
i) abb ii) aba
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b} such that every accepted string start and end with a.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b} such that every accepted string start and end with same
G
symbol.
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b} such that every accepted string start and end with different
G
symbol.
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑ = {a, b} such that every accepted string w, is like w=SX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑ = {a, b} such that every accepted string w, is like w=XS.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑ = {a, b} such that every accepted string w, is like w=XSX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
b}, such that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
t e
Q Design a regular expression that represent all strings over the alphabet ∑ = {a,
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}, such that every string accepted must contain exactly two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}, such that every string accepted must contain at least two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b}, such that every string accepted must contain at most two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
a
∑ = {a, b} such that for every accepted string 2nd from left end is always
G
b.
dge
w l e
n o www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet ∑ = {a, b}
such that for every accepted string 4th from right end is always a.
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑= {a, b}, such that every string ‘w’ where |W| = 0(mod 3)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑= {a, b}, such that every string ‘w’ where |W| = 3(mod 4)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑= {a, b}, such that every string ‘w’ where |W|a = 0(mod 3)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a regular expression that represent all strings over the alphabet
∑= {a, b}, such that every string ‘w’ where |W|a = 2(mod 3)?
a
ge G
l e d
n ow
www.knowledgegate.in
m n
Q L = {a b | m, n >= 0}
at e
m n
Q L = {a b | m>=1, n >= 1}
ge G
m n
l e d
Q L = {a b | m>=2, n >= 3}
n ow
www.knowledgegate.in
m n p
Q L = {a b c | m, n, p >= 1}
at e
ge G
n n
Q L = {a b | n >= 1}
l e d
n ow
www.knowledgegate.in
Q L = {am bn | m + n = even}
at e
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Write a regular expression for the language, L = {w c wr |w, c ∈ {a, b}+}
a
ge G
l e d
n ow
www.knowledgegate.in
Algebraic Properties of regular expression
at e
Closure Property - regular expressions satisfy closure property with respect to Union,
G
Concatenation and kleene closure. If R1 and R2 are regular expression then the following will also
e
be regular expression.
g
r1 + r2
r1.r2
l e d
r1*
r1 +
n ow
www.knowledgegate.in
t e
Associative Property- regular expression satisfy associative property with respect
to union and intersection
a
(r1 + r2) + r3
G
r1 + (r2 + r3)
ge
(r1. r2). r3
l e d
r1. (r2. r3)
n ow
www.knowledgegate.in
r. = r
at
Identity Property- The identity property is satisfied as follows-
e
ge G
r+ = r
l e d
n ow
www.knowledgegate.in
Inverse Property- The inverse property is not satisfied with respect to
concatenation and union.
at e
r . =ε
ge G
r + =ϕ l e d
n ow
www.knowledgegate.in
t e
Commutative Property-regular expressions are commutative with
respect to union but not with respect to concatenation.
a
r1+ r 2 r 2+ r 1
ge G
l e d
r1. r 2
n ow r 2. r 1
www.knowledgegate.in
r1(r2+r3) r1r2+r1r3
at e
Distributive Property-regular expression satisfy this property as follows-
ge G
d
(r1+r2) r3 r1r3+r2r3
w
r1+(r2. r3) l e
(r1+r2)(r1+r3)
n o
(r1.r2) + r3 (r1 +r3). (r2 + r3)
www.knowledgegate.in
t e
Idempotent Property-regular expressions satisfies idempotent property
a
with respect to union but not with respect to concatenation.
r1+r1 r1
ge G
l e d
ow
r 1. r 1
n
r1
www.knowledgegate.in
Identities for regular expressions
at e
G
1. φ+r=
2. φ. r = r. φ =
dge
3.
4.
∈. r = r. ∈ =
∈*=
w l e
5. ф*=
n o www.knowledgegate.in
1. r*r* =
at e
2. r. r* =
ge G
+
3. r . r* =
l e d
+ +
4. r r =
n ow
www.knowledgegate.in
+
1. r U r* =
at e
+
2. r ⋂ r* =
ge G
l e d
n ow
www.knowledgegate.in
1. (r*)* =
at e
+
2. (r )*=
ge G
+
3. ((r )*)* =
l e d
n ow
4. ((r*)*)r =+
www.knowledgegate.in
1) (r1+r2)* (r1* + r2*)*
at e
2) (r1+r2)* (r1 + r2*)*
ge G
3) (r1+r2)*
e d
(r1* + r2) *
l
ow
4) (r1+r2)*
n
(r1* + r2*)
www.knowledgegate.in
1. (r1+r2)* (r1* . r2*)*
at e
2. (r1+r2)* (r1 . r2*)*
ge G
d
3. (r1+r2)* (r1* . r2)*
4. (r1+r2)*
w
(r1 . r2)*
l e
n
5. (r1+r2)*
o (r1* . r2*)
www.knowledgegate.in
r1(r2.r1)* (r1.r2)*r1
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Which of the following regular expressions represent(s) the set of all binary
numbers that are divisible by three? Assume that the string ϵ is divisible by three.
(GATE 2021) (2 MARKS)
a) (0+1(01*0)*1)*
ge G
d
b) (0+11+10(1+00)*01)*
c) (0*(1(01*0)*1)*)*
w l e
o
d) (0+11+11(1+00)*00)*
n www.knowledgegate.in
t e
Q Which one of the following regular expressions represents the language: the set of all
a
binary strings having two consecutive 0s and two consecutive 1s? (GATE-2016) (2 Marks)
ge G
l e d
n ow
www.knowledgegate.in
* *
at
following represents L1 L2 U L1 (GATE-2013) (1 Marks)? e
Q Consider the languages L1 = Φ and L2 = {a}. Which one of the
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Which one of the following languages over the alphabet {0,1} is described by the regular
expression: (0+1)*0(0+1)*0(0+1)*? (GATE-2009) (2 Marks)
a
G
(A) The set of all strings containing the substring 00.
ge
(B) The set of all strings containing at most two 0’s.
d
l e
(C) The set of all strings containing at least two 0’s.
w
(D) The set of all strings that begin and end with either 0 or 1.
n o www.knowledgegate.in
(A) (0 + 1) * 11(0 + 1) * (B) 0 * 110 *
at e
Q Which of the following regular expressions describes the language over {0, 1}
consisting of strings that contain exactly two 1’s? (GATE-2008) (1 Marks)
ge G
(C) 0 * 10 * 10 *
d
(D) (0 + 1) * 1(0 + 1) * 1 (0 + 1) *
l e
n ow
www.knowledgegate.in
t e
Q The regular expression 0*(10*)* denotes the same set as (GATE-2003)
(1 Marks)
a
G
(A) (1*0)*1* (B) 0 + (0 + 10)*
dge
e
(C) (0 + 1)* 10(0 + 1)* (D) none of these
w l
n o www.knowledgegate.in
t e
Q Which one of the following regular expressions is NOT equivalent to
the regular expression (a + b + c) *? (GATE-2004) (2 Marks)
a
G
(A) (a* + b* + c*)* (B) (a*b*c*)*
dge
e
(C) ((ab)* + c*)* (D) (a*b* + c*)*
w l
n o www.knowledgegate.in
Q Which of the following is correct
a) (xx)*y = x(xy)* b) (xy)*x = x(yx)*
at e
ge G
c) x(xy)* = (xx)*y
n ow
www.knowledgegate.in
t e
Q find the no of strings of length <= 3 generated by the (a + ab)+
a
ge G
l e d
n ow
www.knowledgegate.in
Q which of the following statements are correct
a) r*, r+ always represent finite language.
at e
ge G
b) r*, r+ always represent infinite language.
c) r* = r+ if and only if r = ε
l e d
n ow
d) r* = r+ = r if r = Ф
www.knowledgegate.in
EQUIVALENCE BETWEEN Regular Expression AND FINITE AUTOMATA
at e
• ARDEN’S THEOREM is the mechanism for the construction of a regular expression from a
G
finite automaton.
δ(A, a) = A
δ(A, b) = B
d e
Q Consider a DFA and convert it into regular expression using Arden’s theorem?
g
e
δ(B, a) = B
l
δ(B, b) = B
A is the initial state and B Is the final state
n ow
www.knowledgegate.in
δ(A, b) = A
δ(A, b) = B
at e
Q Consider a DFA and convert it into regular expression using Arden’s theorem?
δ(B, a) = C
δ(C, b) = C
ge G
A is the initial state and B,C Is the final state
l e d
n ow
www.knowledgegate.in
• Steps used-
at e
• For, every individual state of the DFA, write an expression for every incoming and outgoing
input alphabet.
G
• Apply Arden’s theorem as follows-
e
• If P is free from NULL, then equation R=Q+RP has unique solution, R=QP*
• If P contains NULL, then equation R=Q+RP has infinitely many solutions.
e dg
w l
n o www.knowledgegate.in
Conversion from Finite Automata to regular expression
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Which of the regular expressions given below represent the following
DFA? (GATE-2014) (2 Marks)
a
G
I) 0*1(1+00*1)* II) 0*1*1+11*0*1 III) (0+1)*1
dge
w
(A) I and II only
l e
o
(B) I and III only
n
(C) II and III only
(D) I, II, and III
www.knowledgegate.in
t e
Q Let L = {w ∈ (0 + 1)* | w has even number of 1s}, i.e. L is the set of all bit strings with even
a
number of 1s. Which one of the regular expression below represents L? (GATE-2010)(2 Marks)
a) (0 * 10 * 1)*
ge G
b) 0 * (10 * 10*)*
c) 0*(10 * 1*)*0*
l e d d) 0 * 1(10 * 1)*10*
n ow
www.knowledgegate.in
at e
Q If the final states and non-final states in the DFA below are interchanged, then which of the
following languages over the alphabet {a, b} will be accepted by the new DFA? (GATE-2008) (1 Marks)
(A) Set of all strings that do not end with ab
ge G
(B) Set of all strings that begin with either an a or a b
l e d
(C) Set of all strings that do not contain the substring ab
ow
(D) The set described by the regular expression b*aa*(ba)*b*
n www.knowledgegate.in
t e
Q Consider the following Finite State Automaton. The language accepted by this
automaton is given by the regular expression (GATE-2007) (2 Marks)
a
ge G
l e d
n ow
www.knowledgegate.in
non-deterministic automaton below? (GATE-2006) (1 Marks)
(A) (a + b)* a(a + b)b
at e
Q Which regular expression best describes the language accepted by the
(B) (abb)*
ge G
(C) (a + b)* a(a + b)* b(a + b)*
l e d
o
(D) (a + b)*
n w
www.knowledgegate.in
t e
Q Consider the automata given in previous question. The minimum state automaton
a
equivalent to the above FSA has the following number of states (GATE-2007) (1 Marks)
(A) 1 (B) 2 (C) 3 (D) 4
ge G
l e d
n ow
www.knowledgegate.in
by the DFA given below? (Gate 2024 CS)(1 Mark)(MCQ)
(a) 0∗1(0 + 10∗1)∗
at e
Q. Which one of the following regular expressions is equivalent to the language accepted
ge G
(c) 0∗1(0101∗1)∗0∗
l e d
ow
(d) 0(1 + 0∗10∗1)∗0∗
n www.knowledgegate.in
at e
Q. Let 𝑀 be the 5-state NFA with 𝜖-transitions shown in the diagram below. Which one of
the following regular expressions represents the language accepted by 𝑀 ? (Gate 2024
CS) (2 Marks)(MCQ)
(a) (00)∗ + 1(11)∗
ge G
(c) (00)∗ + (1 + (00)∗ )(11)∗
l e d
n ow
www.knowledgegate.in
i) R*
t e
Conversion from regular expression in Finite Automata
a
ge G
ii) (R1.R2)*
l e d
ow
iii) (R1+R2)*
n www.knowledgegate.in
iv) (R1*R2.R3*)
at e
v) R = a*b(ab)*
ge G
l e d
n ow
vi) R = (a + ba)*ab*
www.knowledgegate.in
vii) R = (aa + aaa)*
at e
ge G
viii) R = (a + aaaaa)*
l e d
n ow
www.knowledgegate.in
1. 0 * 10 * 10 *
at e
2. ((ab)* + c*)*
ge G
l e d
3. (∈ + a + aa + aaa)b* + (a + b)* ba(a + b)*
n ow
4. 0*(10 * 1*)*0*
www.knowledgegate.in
1. a*b(b * + aa*b)*
at e
2. ((11*0+0)(0 + 1)*0*1*)
ge G
l e d
3.
ow
(ab+ bc+ acc).(a+ bc)*.( ∈+ bc*a)*
n www.knowledgegate.in
t e
Q Which one of the following regular expressions correctly represents the language of the finite
automaton given below? (GATE 2022) (1 MARKS)
a
G
(A) ab*bab* + ba*aba*
dge
(D) (ba*a + ab*b)*(ab* +ba*)
w l e
n o www.knowledgegate.in
at e
Q Consider the language L given by the regular expression (a + b) *b(a +b) over the
alphabet {a, b}. The smallest number of states needed in a deterministic
finite-state automaton (DFA) accepting L is ______. (GATE-2017) (1 Marks)
ge G
l e d
n ow
www.knowledgegate.in
t e
Q The number of states in the minimum sized DFA that accepts the language defined by
a
the regular expression (0+1)*(0+1)(0+1)* is __________________ (GATE-2016) (2 Marks)
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Let T be the language represented by the regular expression Σ∗0011Σ∗ where Σ =
{0, 1}. What is the minimum number of states in a DFA that recognizes L’
(complement of L)? (GATE-2015) (2 Marks)
(A) 4 (B) 5 (C) 6
ge G (D) 8
l e d
n ow
www.knowledgegate.in
the regular expression (0 + 1)*(10) is ____________ (GATE-2015) (1 Marks)
(A) 2 (B) 3 (C) 4 (D) 5
t e
Q The number of states in the minimal deterministic finite automaton corresponding to
a
ge G
l e d
n ow
www.knowledgegate.in
following regular expression is ______________. (GATE-2014) (2 Marks)
a*b*(ba)*a*
at e
Q The length of the shortest string NOT in the language (over Σ = {a, b}) of the
ge G (D) 5
l e d
n ow
www.knowledgegate.in
t e
Q Consider the regular language L = (111 + 11111)*. The minimum
a
number of states in any DFA accepting this language is: (GATE-2006) (1
G
Marks)
e
(A) 3 (B) 5 (C) 8 (D) 9
e dg
w l
n o www.knowledgegate.in
t
Q Match the following NFAs with the regular expressions they
correspond to (GATE-2008) (2 Marks)
a e
ge G
l e d
n ow
(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
Q Consider the DFA given. (GATE-2013) (2 Marks)
Which of the following are FALSE?
1. Complement of L(A) is context-free.
at e
2. L(A) = L((11*0+0)(0 + 1)*0*1*)
ge G
l e d
3. For the language accepted by A, A is the minimal DFA.
w
4. A accepts all strings over {0, 1} of length at least 2.
o
a) 1 and 3 only
n
b) 2 and 4 only
c) 2 and 3 only
d) 3 and 4 only
www.knowledgegate.in
Q the string 1101 does not belong to the set
a) 110*(0+1) b) 1(0+1)*101
at e
ge G
d
c) (10)*(10)*(00+11)* d) (00 + (11)*01)*
w l e
n o www.knowledgegate.in
(GATE-2005) (1 Marks)
(A) It represents a finite set of finite strings.
at e
Q Which of the following statements is TRUE about the regular expression 01*0?
e G
(B) It represents an infinite set of finite strings.
g
d
(C) It represents a finite set of infinite strings.
l e
(D) It represents an infinite set of infinite strings
w
n o www.knowledgegate.in
not contain 100 as sub-string
a) 0*(0+1)* b) 0*1010* c) 0*1*01 d) 0*(10+1)*
t e
Q which of the following re, over the Σ = {0, 1} denotes the set of all strings that
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q. Consider the following two regular expressions over the alphabet {0,1}: (Gate
2024,CS) (2 Marks) (NAT)
a
r = 0*+1*
s = 01* +10*
ge G
s, is ____________
l e d
The total number of strings of length less than or equal to 5,which are neither in r nor in
n ow
www.knowledgegate.in
Q. Let 𝐿1 be the language represented by the regular expression
at e
𝑏 ∗𝑎𝑏 ∗ (𝑎𝑏 ∗𝑎𝑏 ∗ ) ∗ and 𝐿2 = { 𝑤 ∈ (𝑎 + 𝑏) ∗ | |𝑤| ≤ 4}, where |𝑤| denotes the length of
string 𝑤. The number of strings in 𝐿2 which are also in 𝐿1 is ___________ (Gate 2024 CS)
(2 Marks) (NAT)
ge G
l e d
n ow
www.knowledgegate.in
t e
Q. Let Σ = {𝑎, 𝑏, 𝑐}. For 𝑥 ∈ Σ∗ , and 𝛼 ∈ Σ, let #𝛼(𝑥) denote the number of occurrences of 𝛼 in 𝑥.
a
Which one or more of the following option(s) define(s) regular language(s)? (Gate 2025)
A) {𝑎𝑚𝑏𝑛 | 𝑚, 𝑛 ≥ 0}
B) {𝑎, 𝑏}∗ ∩ {𝑎𝑚𝑏𝑛𝑐𝑚−𝑛 | 𝑚 ≥ 𝑛 ≥ 0}
ge G
C) {𝑤 | 𝑤 ∈ {𝑎, 𝑏}∗ , #𝑎 (𝑤) ≡ 2 (mod 7), and #𝑏 (𝑤) ≡ 3 (mod 9)}
d
D) {𝑤 | 𝑤 ∈ {𝑎, 𝑏}∗ , #𝑎 (𝑤) ≡ 2 (mod 7), and #𝑎 (𝑤) = #𝑏(𝑤)}
w l e
n o www.knowledgegate.in
Formal Grammar
at e
Language usually contains infinite number of strings. We cannot tabulate each and every string to
G
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
e
a language generator. A phrase-structure grammar (or simply a grammar) is a 4-tuple (VN, ∑, P, S), where
g
• VN is a finite nonempty set whose elements are called variables,
d
• ∑ is a finite nonempty set whose elements are called terminals, VN ⋂ ∑= Ф.
e
• S is a special variable (i.e., an element of VN (S ∈ Vn)) called the start symbol. Like every automaton has
l
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 VN ⋃ ∑. α has at least one
w
symbol from VN, the element of P are called productions or production rules or rewriting rules. {Σ U
o
Vn}* some writer refers it as total alphabet.
n www.knowledgegate.in
α🡪β
For a formal valid production
at e
α ∈ {Σ U Vn}* Vn {Σ U Vn}*
ge G
β ∈ {Σ U Vn}*
l e d
n ow
www.knowledgegate.in
Some points to note about productions
at e
• 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.
→S is a production.
g G
• No inversion operation is permitted. For example, if S → AB is a production, it is not necessary that AB
e
• To generate a string in the language, one begins with a string consisting of only a single start symbol.
d
The production rules are then applied in any order, until a string that contains neither the start symbol
e
nor designated nonterminal symbols is produced. A sequence of rule applications is called a derivation.
l
• 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.
w
• L (G) is the set of all terminal strings derived from the start symbol S. G1 and G2 are equivalent if L (G1)
o
= L (G2).
n www.knowledgegate.in
Defining a language by grammar
at e
• The concept of defining a language using grammar is, starting from a start symbol using the
G
production rules of the grammar any time, deriving the string. Here every time during
derivation a production is used as its LHS is replaced by its RHS, all the intermediate
e
stages(strings) are called sentential forms. The language formed by the grammar consists of all
g
distinct strings that can be generated in this manner.
d
L (G) = {w | w ∈ ∑* , S 🡪* W}
l e
• 🡪*(reflexive, transitive closure) means from s we can derive w in zero or more steps
w
n o www.knowledgegate.in
Chomsky Classification of Languages
at e
• Chomsky classified the grammars into four types in terms of productions (types 0-3). This hierarchy of
grammars was described by Noam Chomsky in 1956. From type 0 to type 3, we will be putting more
G
and more restrictions. The more restrictive the grammar, the easier the language will be to process;
e
the more liberal the grammar, the more complex the language will become.
e dg
w l
n o www.knowledgegate.in
LANGUAGES AND AUTOMATA
at e
ge G
l e d
n ow
www.knowledgegate.in
•
Type 0 Grammar
at e
Also known as Unrestricted Grammar, phase structured grammar, recursively enumerable
G
grammar used to generate recursive enumerable language which is accepted by a Turing
e
machine.
g
• A type 0 grammar is without any restrictions.
d
• No restriction on the production rule, that is if there is a production from
α🡪β
α ∈ {Σ U Vn}* Vn {Σ U Vn}*
w
β ∈ {Σ U Vn}*
l e
n o www.knowledgegate.in
Type 1 Grammar
at e
• Also known as case sensitive Grammar, length increasing grammar, non-contracting grammar,
used to generate context sensitive language which is accepted by a linear bounded
automaton.
αAβ🡪αδβ
α , β ∈ {Σ U Vn}* A ∈ Vn
ge G
δ ∈ {Σ U Vn}+
or
α🡪β
l e d
w
α ∈ {Σ U Vn}* Vn {Σ U Vn}*
o
β ∈ {Σ U Vn}+
n
|α| <= |β|
www.knowledgegate.in
at e
• As from the rule we can understand that we cannot have null production, in order to solve that
problem, Production S🡪∈, is allowed if S do not appear on the right-hand side of the
production.
type 1 productions.
ge G
• A grammar is called type 1 or context-sensitive or context dependent if all its productions are
d
• Very difficult to have a parse tree
w l e
n o www.knowledgegate.in
Type 2 Grammar
at e
• Also known as Context Free Grammar, which will generate context free language that will be
accepted by push down automata. (NPDA default case)
• if there is a production, from
α🡪β
α ∈ Vn |α| = 1
ge G
β ∈ {Σ U Vn} *
l e d
• In other words, the L.H.S. has no left context or right context.
ow
• A grammar is called a type 2 grammar if it contains only type 2 productions.
• Eg ALGOL 60, PASCAL
n www.knowledgegate.in
Type 3 Grammar
at e
• Used to generate Regular Grammar which will generate regular language which will be
accepted by finite machine.
e G
• Regular grammar can be of two types either left linear or right linear.
g
• Left regular grammar, support two types of production
A 🡪 a / Ba
A, B ∈ Vn |A| = |B| = 1
a ∈ ∑*
• Right regular grammar
l e d
w
A 🡪 a / aB
A, B ∈ Vn |A| = |B| = 1
o
a ∈ ∑*
n
• however, if left-linear rules and right-linear rules are combined,
the language need no longer be regular.
www.knowledgegate.in
Q Consider the grammar
S → aaaS | a | aa
L(G) =?
at e
ge G
a) L(G) = {w: |w| mod 3 = 0}
l e d
n ow
b) L(G) = {w: |w| mod 3 = 1 or 2}
c) L(G)= L(a*)
at e
ge G
b) It sometimes fails to recognize grammars that are not regular
d) All of these
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> aAb
a
A -> aB / b
ge G
B -> c
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> AB / Bb
a
A -> b / c
ge G
B -> d
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> aSb / ∈
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> aA / abS
a
A -> bS / b
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> aAB
a
A -> aA / ∈
ge G
B -> b
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> AB
a
A -> aA / ∈
ge G
B -> bB / b
l e d
n ow
www.knowledgegate.in
t e
Q Consider the following grammar and identify it’s language?
S -> aSa / bSb / ∈
a
ge G
l e d
n ow
www.knowledgegate.in
Q If G is a grammar with productions
S → SaS | aSb | bSa | SS | ϵ
at e
where S is the start variable, then which one of the following strings is not
generated by G? (GATE-2017) (1 Marks)
(A) abab
ge G
(B) aaab
l e d
w
(C) abba
(D) babba
n o www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
Q Consider the regular grammar: (GATE-2005) (1 Marks)
S → X a | Ya
X → Za
at e
Z → Sa | ϵ
Y → Wa
W → Sa
ge G
l e d
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
w
minimum number of states required for the DFA?
a) 2
b) 3
c) 4
d) 5
n o www.knowledgegate.in
t e
Q What is the regular expression for the language generated by
S → aS | bA
a
G
A → d | ccA
dge
a) a*bd
w
b) a* (bd)(bcc)* d
l e
n o
c) a* b(cc)* d
d) None of these
www.knowledgegate.in
Q Write the grammar for the regular expression a*b*
at e
ge
b) S→ AB, A → aA | ϵ, B → bB | ϵG
a) S → AB, A → aA | bB | ϵ, B → bB |aA | ϵ
l e d
c) S → ab | ϵ, A → aA | ϵ, B → bB | ϵ
ow
d) None of these
n www.knowledgegate.in
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)
at e
P: L1 is regular
Which one of the following is TRUE?
(A) Both P and Q are true
ge G
Q: L2 is regular
l e d
w
(C) P is false and Q is true
n o
(D) Both P and Q are false
www.knowledgegate.in
at e
Q Consider alphabet ∑ = {0, 1}, the null/empty string ∈ and the sets of strings X0, X1 and
X2 generated by the corresponding non-terminals of a regular grammar. X0, X1 and X2 are related
as follows (GATE-2015) (2 Marks)
G
X0 = 1 X 1 X1 = 0 X 1 + 1 X 2 X2 = 0 X1 + {∈}
e
Which one of the following choices precisely represents the strings in X0?
e dg
l
(A) 10 (0* + (10)*)1
n w
(B) 10 (0* + (10)*)*1
o
(C) 1(0* + 10)*1
at e
Q Design a grammar that generates a language ‘L’, where L={a} over the
G
alphabet ∑={a}.
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, where every accepted string ‘w’ starts with substring s
a
G
i) s = b ii) s = ab iii) s = abb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ ends with substring ‘s’.
a
G
i) s = ab ii) s = aa iii) s = bab
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s.
a
G
i) abb ii) aba
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with a.
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b} such that every accepted string start and end with same symbol.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b} such that every accepted string start and end with different symbol.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XS.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XSX.
a
G
i) s= aa/bb ii) s=aaa/bbb
dge
w l e
n o www.knowledgegate.in
that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}, such
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b}, such that every string accepted must contain exactly two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b}, such that every string accepted must contain at least two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b}, such that every string accepted must contain at most two a’s.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
a
b} such that for every accepted string 2nd from left end is always b.
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 0(mod 3)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 3(mod 4)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W|a = 0(mod 3)?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W|a = 2(mod 3)?
a
ge G
l e d
• n ow
We actually did Regular Expression to Grammar
• www.knowledgegate.in
Regular Grammar to Regular Expression
t e
Q Consider the following Left recursive grammar and convert them into
Regular Expression?
a
A -> Aα / β
A -> Aα / β1 / β2
ge G
A -> Aα / β1 / β2 -------/ βn
l e d
n ow
www.knowledgegate.in
A -> Aα1 / Aα2 / β
at e
G
A -> Aα1 / Aα2 /----------Aαn / β
dge
w l e
n o www.knowledgegate.in
t e
A -> Aα1 / Aα2 /----------Aαn / β1 / β2 -------/ βm
a
ge G
l e d
n ow
www.knowledgegate.in
S -> 01S / 01
at e
ge G
l e d
n ow
www.knowledgegate.in
S -> 0011S / 01 / 10
at e
ge G
l e d
n ow
www.knowledgegate.in
S -> 01A / B11
A -> 011A / 01
at e
B -> 101B / 11
ge G
l e d
n ow
www.knowledgegate.in
S -> 011A / 101B
A -> 110A / 00
at e
B -> 11B / S
ge G
l e d
n ow
Regular Grammar to (Finite Automata)
www.knowledgegate.in
S -> 01S / 1
at e
ge G
l e d
n ow
www.knowledgegate.in
S -> 011S / 01
at e
ge G
l e d
n ow
www.knowledgegate.in
S -> 001S / 10A
A -> 101A / 0 / 1
at e
ge G
l e d
n ow
• We actually did Right Regular Grammar to (Finite Automata)
• Left Regular Grammar to (Finite Automata)
www.knowledgegate.in
• Reverse the right hand side of every production.
• Construct the NFA.
at e
G
• Interchange initial and final state.
e
• Change the direction if edges.
S -> S10 / 01
e dg
w l
n o www.knowledgegate.in
• Finite Automata to Regular Grammar
at e
ge G
l e d
•
n ow
We actually did (Finite Automata) To Right Regular Grammar
• Finite Automata to Left Regularwww.knowledgegate.in
Grammar
• Obtain the regular Expression
• Reverse the regular Expression
at e
G
• Construct the finite automata
e
• Construct the right regular grammar
g
• Reverse right hand side of every production
l e d
n ow
www.knowledgegate.in
grammar can be converted into left regular grammar.
• Procedure to convert Right linear grammar to Left linear grammar
at e
• Every Left regular grammar can be converted into right regular and every right regular
G
• Obtain the RE from the grammar
e
• Reverse the RE
• Construct the finite automata for the regular expression
dg
• Now construct the right linear grammar
• Reverse the left hand side of every production to get a left linear grammar.
e
w l
n o www.knowledgegate.in
• Don’t
What computer science deals with?
at e
G
• So we do not study how to design a computer
• We do not study how to run a computer
• Do
ge
• We deal with problem solving, according to computer science a problem can be divided
as follows
d
l e
PROBLEM
w
SOLVABLE UNSOLVABLE
n o P TYPE
DECIDABLE UNDECIDABLE
NP TYPE
www.knowledgegate.in
Konigsberg Bridge Problem
at e
ge G
l e d
n ow
www.knowledgegate.in
t e
• 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.
a
G
• UNSOLVABLE - A problem is said to be unsolvable if neither we can solve it, nor we can proof
e
that the problem can not be solved.
decidable.
e dg
• P- if there exist a polynomial time algorithm to solve a problem then problem is said to be
l
• NP- if there exist a non- polynomial time algo to solve a problem.
n ow
www.knowledgegate.in
Decision properties
at e
• Approximately all the properties are decidable in case a finite automaton. Here
G
we will use machine model to proof decision properties.
e
i) Emptiness
ii) Non-emptiness
iii) Finiteness
e dg
iv) Infiniteness
w l
o
v) Membership
vi) Equality
n www.knowledgegate.in
Emptiness & Non-emptiness
at e
• Step 1: - select the state that cannot be reached from the initial states & delete them (remove
G
unreachable states)
d e
• Step 2: - if the resulting machine contains at least one final states, so then the finite automata
g
• Step 3: - if the resulting machine is free from final state, then finite automata accepts empty
language.
w l e
n o www.knowledgegate.in
Finiteness & Infiniteness
at e
• Step 1: - Select the state that cannot be reached from the initial state & delete them (remove
G
unreachable states)
e
• Step 2: - Select the state from which we cannot reach the final state & delete them (remove
dead states)
infinite language
e dg
• Step 3: - If the resulting machine contains loops or cycles then the finite automata accepts
l
• Step 4: - If the resulting machine do not contain loops or cycles then the finite automata
accepts finite language.
n ow
www.knowledgegate.in
Membership
at e
• Membership is a property to verify an arbitrary string is accepted by a finite automaton or not
G
i.e. it is a member of the language or not.
e
• Let M is a finite automata that accepts some strings over an alphabet, and let ‘w’ be any string
defined over the alphabet, if there exist a transition path in M, which starts at initial state &
member of M.
e dg
ends in anyone of the final state, then string ‘w’ is a member of M, otherwise ‘w’ is not a
w l
n o www.knowledgegate.in
Equality
at e
• Two finite state automata M1 & M2 is said to be equal if and only if, they accept
G
the same language.
dge
• Minimise the finite state automata and and the minimal DFA will be unique.
w l e
n o www.knowledgegate.in
Emptiness
RL
Y
DCFL
Y
CFL
Y
CSL
X
RS
N
at
N e
RES
Non-Emptiness
Finiteness
Y
Y
Y
Y
ge
Y
Y G X
X
N
N
N
N
Infiniteness
Membership
Y
Y
Y
Y
l e d Y
Y
X
X
N
Y
N
N
Equality
Ambiguity
∑*
n
Y
Y
Yow N
N
N
N
N
N
X
X
X
N
N
N
N
N
N
Halting Y Ywww.knowledgegate.in
Y X Y N
Closure Properties of Regular Languages
• Regular languages are closed under following operations
• Kleen Closure
at e
• Positive closure
• Complement
• Reverse Operator
ge G
d
• Prefix Operator
l e
• Suffix operator
• Concatenation
w
• Union
o
• Intersection
n
• Set Difference operator
• Symmetric Difference
www.knowledgegate.in
Q Consider the following two statements about regular languages:
at e
● S1: Every infinite regular language contains an undecidable language as a subset.
● S2: Every finite language is regular.
G
Which one of the following choices is correct? (GATE 2021) (2 MARKS)
dge
(c) Both S1 and S2 are true
w
(d) Neither S1 nor S2 is true
l e
n o www.knowledgegate.in
t e
Q If L is a regular language over ∑ = {a, b}, which one of the following languages
is NOT regular? (GATE – 2019) (1 Marks)
a
a) L⋅ LR {xy | x ∈ L, yR∈ L}
ge G
l e d
b) Suffix (L) = {y ∈ ∑* | ∃x ∈ ∑* such that xy ∈ L}
n ow
c) Prefix (L) = {x ∈ ∑* | ∃y ∈ ∑* such that xy ∈ L}
d) {w wR | w ∈ L}
www.knowledgegate.in
Q Consider the following two statements (GATE-2016) (1 Marks)
at e
I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ∗.
ge G
II. There exists a regular language A such that for all languages B, A ∩ B is regular.
l e d
w
(A) Only I is true
o
(B) Only II is true
n
(C) Both I and II are true
(D) Both I and II are false
www.knowledgegate.in
Q Which of the following is TRUE? (GATE-2007) (2 Marks)
a) Every subset of a regular set is regular.
at e
ge G
b) The union of two non-regular sets is not regular.
c) Every finite subset of a non-regular set is regular.
d
d) Infinite union of finite sets is regular
w l e
n o www.knowledgegate.in
Q Which of the following is true? (GATE – 2007) (1 Marks)
a) Infinite union of regular set is regular
at e
ge
c) finite union of infinite set is regular
G
b) The union of two non-regular net is not regular
d
d) every R.L is also C.F.L
w l e
n o www.knowledgegate.in
t e
Q Which of the following statements about regular languages is NOT true?
(GATE-2006) (1-Marks)
a
a) Every language has a regular superset
b) Every language has a regular subset
ge G
d
c) Every subset of a regular language is regular
l e
d) Every subset of a finite language is regular
w
n o www.knowledgegate.in
Q Which of the following statement is false? (GATE – 1998) (1 Marks)
a) Every finite subset of a non – regular set is regular
at e
ge G
b) Every subset of a regular set is regular
c) Every finite subset of a regular set is regular
d
d) The intersection of two regular sets in regular
w l e
n o www.knowledgegate.in
t e
Q.Let L1,L2 be two regular languages and L3 a languages which is not regular. Which of
a
the following statements is/are always TRUE? (Gate 2024,CS) (1 Marks) (MSQ)
G
(a) L1 = L2 if and only if L1 ∩ L’2 =𝜙
e
(b) L1 ⋃ L3 is not regular
g
(c) (L3)‘ is not regular
(d) (L1)‘ ⋃ (L2)’ is regular
l e d
n ow
www.knowledgegate.in
Q. Consider the two lists List I and List II given below:
at e
ge G
l e d
For matching of items in List I with those in List II, which of the following option(s) is/are
CORRECT? (Gate 2025)
w
A) (i) – (a), (ii) – (b), and (iii) – (c)
o
B) (i) – (b), (ii) – (a), and (iii) – (c)
n
C) (i) – (b), (ii) – (c), and (iii) – (a)
D) (i) – (a), (ii) – (c), and (iii) – (b)
www.knowledgegate.in
Q. Consider the following two languages over the alphabet {𝑎, 𝑏}:
at e
ge G
𝐿2 = { 𝛼𝛽𝛼 | 𝛼 ∈ {𝑎}+ AND 𝛽 ∈ {𝑎, 𝑏}+ }
d
A) Both 𝐿1 and 𝐿2 are regular languages.
e
B) 𝐿1 is a regular language but 𝐿2 is not a regular language.
w l
C) 𝐿1 is not a regular language but 𝐿2 is a regular language.
D) Neither 𝐿1 nor 𝐿2 is a regular language.
n o www.knowledgegate.in
Union
RL
Y
DCFL
N
CFL
Y
CSL
Y
RS
Y
at
Y e
RES
Intersection
Complement
Y
Y
N
Y
ge
N
N
G Y
Y
Y
Y
Y
N
d
Set Difference Y N N Y Y N
Kleene Closure
Positive Closure
w
Y
Y
N
N
l e Y
Y
Y
Y
Y
Y
Y
Y
o
Concatenation Y N Y Y Y Y
n
Intersection
with regular set Y Y Y Y Y Y
Reverse Y Y Y Y Y Y
Subset N Nwww.knowledgegate.in
N N N N
RL
Y
DCFL
N
CFL
Y
CSL
N
a
Nt
RS
e RES
Y
G
Homomorphism
∈ Free Homomorphism
Y
dge N Y Y Y Y
e
Inverse Homomorphism Y Y Y Y Y Y
w
Substitution
Yl N Y N N Y
n o
∈ Free Substitution
at e
•
•
•
e G
In moore and mealy machine no need to define the final states
No concepts of dead states and no concepts of final states
g
Mealy and Moore Machines are equivalent in power.
l e d
n ow
George H Mealy Edward F Moore
www.knowledgegate.in
Moore Machine
at e
• Q is a finite set of states:
• ∑ is the input alphabet:
ge G
d
• Δ is the output alphabet.
l e
• δ is the transition function Q x ∑ into Q
w
• λ is the output function mapping Q into Δ and
o
• q0 is the initial state.
n www.knowledgegate.in
Examples: The below table shows the transition table of a Moore Machine.
at e
ge G
l e d
n ow
• In moore machine for every state output is associated. If the length of i/p string is n, then
length of o/p string will be n+1. Moore machine response for empty string ∈.
www.knowledgegate.in
t e
Q construct a Moore machine take all the string of a’s and b’s as i/p and
a
counts the no of a’s in the i/p string in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the
a
no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the
a
no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Moore machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
a
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
ge G
l e d
n ow
www.knowledgegate.in
Mealy Machine
at e
• Mealy machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where all the symbols except λ have the same
G
meaning as in the Moore machine. λ is the output function mapping Q x ∑ into Δ.
dge
• In case of mealy machine, the output symbol depends on the transition.
w l e
n o www.knowledgegate.in
Example: The below table shows the transition table of a Mealy Machine.
at e
ge G
l e d
n ow
• If the length of i/p string is n, then length of o/p string will be n.Mealy machine do not response for empty string ∈.
www.knowledgegate.in
t e
Q construct a Mealy machine take all the string of a’s and b’s as i/p and
a
counts the no of a’s in the i/p string in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts
a
the no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts the
a
no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
ge G
l e d
n ow
www.knowledgegate.in
t e
Q construct a Mealy machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
a
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
ge G
l e d
n ow
www.knowledgegate.in
CONVERSION OF MOORE TO MEALY MACHINE
• Let us take an example to understand the conversion:
at e
• Convert the following Moore machine into its equivalent Mealy machine.
ge G
l e d
n ow
www.knowledgegate.in
of states onto to the incoming transitions.
at e
• To convert a mealy machine to moore machine all you need to do is just push out the outputs
• While conversion from moore to mealy machine, the number of states will we same and there
G
will be no extra states.
e
• The equivalent Moore Machine will be:
e dg
w l
n o www.knowledgegate.in
t e
PROCEDURE FOR TRANSFORMING A MEALY MACHINE INTO A MOORE MACHINE
Consider the Mealy Machine:
a
ge G
l e d
n ow
www.knowledgegate.in
at e
Q Given the following state table of an FSM with two states A and B, one input and one output:
If the initial state is A=0, B=0, what is the minimum length of an input string which will take the
machine to the state A=0, B=1 with Output = 1? (GATE-2009) (2 Marks)
(A) 3
Present
State A
0
Present
State B
0
(B) 4
I/p
0
Next
State A
0
(C) 5
Next
ge
State B
G
O/p
1
(D) 6
d
0 1 0 1 0 0
e
1 0 0 0 1 0
l
1 1 0 1 0 0
0 0 1 0 1 0
w
0 1 1 0 0 1
1 0 1 0 1 1
o
1 1 1 0 0 1
n www.knowledgegate.in
from the least significant bit. (GATE-2005) (1 Marks)
Which one of the following is TRUE?
at e
Q The following diagram represents a finite state machine which takes as input a binary number
e G
(A) It computes 1’s complement of the input number
(B) It computes 2’s complement of the input number
g
d
(C) It increments the input number
e
(D) It decrements the input number
w l
n o www.knowledgegate.in
at e
Q The Finite state machine described by the following state diagram with A as starting state,
where an arc label is x / y and x stand for 1-bit input and y stands for 2- bit output (GATE-2002) (2
Marks)
G
(A) Outputs the sum of the present and the previous bits of the input.
dge
(B) Outputs 01 whenever the input sequence contains 11.
w l e
n o www.knowledgegate.in
by replacing the first 1 in any subsequence of consecutive 1’s by a 0. Consider the following example.
Input sequence : 00100011000011100
Output sequence : 00000001000001100
at e
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
G
A Mealy Machine is a state machine where both the next state and the output are functions of the present state and the current
input. The above mentioned circuit can be designed as a two-state Mealy machine. The states in the Mealy machine can be
e
represented using Boolean values 0 and 1. We denote the current state, the next state, the next incoming bit, and the output bit
g
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
Boolean expressions corresponding to t and y in terms of s and b? (GATE 2021) (2 MARKS)
(a) t = s+b y = sb
(b) t = b y = sb
l e d
o
(c) t = b y = sb’
n w
(d) t = s+b y = sb'
www.knowledgegate.in
Pumping Lemma For Regular Languages
at e
∙ Pumping Lemma is used as a proof for irregularity of a language. Thus, if a language is regular, it always satisfies
G
pumping lemma. If there exists at least one string made from pumping which is not in L, then L is surely not
e
regular.
g
∙ The opposite of this may not always be true. That is, if Pumping Lemma holds, it does not mean that the
d
language is regular.
e
∙ Pumping Lemma is used to prove that some of the language is non-regular.
l
∙ For the pumping lemma, i/p is NRL & o/p is also NRL.
w
n o Pumping Lemma
www.knowledgegate.in
Pumping Lemma For Regular Languages
at e
∙ For any regular language L, there exists an integer n, such that for all z ∈ L with |z| ≥ n, there
G
exists u, v, w ∈ Σ∗, such that z = uvw, and
e
o |uv| ≤ n
g
o |v| ≥ 1
d
o for all i ≥ 0: uviw ∈ L
l e
∙ In simple terms, this means that if a string v is ‘pumped’, i.e., if v is inserted any number of
w
times, the resultant string still remains in L.
n o www.knowledgegate.in
Process of pumping Lemma
∙ Suppose that we need to prove that language L is a non-regular.
at e
G
∙ Assume that L is a regular language, then L must satisfy pumping lemma property.
e
∙ Choose z ∈ L such that |z| <= n, split z into 3 parts.
g
o |uv| ≤ n
d
o |v| ≥ 1
l e
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.
w
n o www.knowledgegate.in
Q Proof that language L = {ambn | m=n} is non-regular?
at e
L = {ab, aabb, aaabbb, aaaabbbb, ---}
z∈L
Z = akbk
ge G
l e d
w
For i=1 🡪 uviw 🡪 akbk
n o
For i=2 🡪 uviw 🡪 ak+1bk ∉ L
at e
ge G
l e d
n ow
www.knowledgegate.in
Q Proof that language L = {anbn | n is a prime number} ?
at e
ge G
l e d
n ow
www.knowledgegate.in
Q Proof that language L = {an^2 | n>= 0} ?
at e
ge G
l e d
n ow
www.knowledgegate.in
Q For Σ = {a, b}, let us consider the regular language
L = {x ∣ x = a2 + 3k or x = b10 + 12k, k ≥ 0}
at e
Which one of the following can be a pumping length (the constant guaranteed by the pumping
lemma) for L? (GATE- 2019)
ge G (D) 24
l e d
n ow
www.knowledgegate.in
t e
Q. Consider a finite state machine (FSM) with one input 𝑋 and one output 𝑓, represented by the
a
given state transition table. The minimum number of states required to realize this FSM is
G
________. (Answer in integer) (Gate 2025)
dge
w l e
n o www.knowledgegate.in
CONTEXT-FREE LANGUAGES AND PUSH DOWN AUTOMATA
at e
• We Already understand the limitation of finite automata, that it cannot do the infinite comparison
G
between the symbols.
e
• Let us consider L = {an bn | n >= 1}. This is not regular, as it has to remember the number of a's in a
g
string and so it will require an infinite number of states, which is logically not possible.
d
• 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.
l e
• This type of arrangement where a finite automaton has a stack leads to the generation of a
pushdown automaton.
w
n o www.knowledgegate.in
BLOCK DIAGRAM OF PDA
at e
• Finite control unit is also called as memory unit it is static and limited. So to process the i/p string if the static
memory is not sufficient then we can use the stack.
g G
• 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
e
• The accepting power of a pda is more than that of finite automata and less than that of linear bounder automata
l e d
• The power of non-deterministic pda is more than the power of deterministic pda.
n ow
www.knowledgegate.in
Formal Definition of DPDA
A DPDA is a 7-tuple, namely (Q, ∑, Γ, δ, q0, Z0, F), where
at e
(i) Q – is a finite nonempty set of states,
(ii) ∑ – is a finite nonempty set of input symbols,
(iii) Γ – is a finite nonempty set of pushdown symbols,
ge G
d
(iv) q0 – is a special state called the initial state,
l e
(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
w
(vii) δ – is a transition function from Q x (∑ U {∈}) x Γ to the set of finite subsets of Q x Γ*.
n o www.knowledgegate.in
Representation of States
at e
(1) PUSH – one symbol can be inserted into the stack at one time.
δ(qi, a, z0) = (qj, az0)
ge G
l e d
n ow
www.knowledgegate.in
Representation of States
at e
(2) POP – one symbol can be deleted from the stack at one time.
δ(qi, a, z0) = (qj, ε)
ge G
l e d
n ow
www.knowledgegate.in
Representation of States
at e
(3) SKIP – IT means no stack operation, status of the stack will remain same, before
a after the operation
δ(qi, a, z0) = (qj, z0)
ge G
l e d
n ow
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
Instantaneous Description (ID)
at e
e G
• An initial ID is (q0, x, Z0), this means that initially the pda is in the initial state q0, the input
g
string to be processed is x and the PDS has only one symbol, namely Z0.
l e d
n ow
• ACCEPTANCE BY PDA There is no change in the language acceptance
www.knowledgegate.in
capability of the pda either we accept by final state of empty stack.
t e
Q Design a Deterministic Push Down Automata for L = {a, ab}?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a Deterministic Push Down Automata for {an bn | n >= 1} ?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a Deterministic Push Down Automata for {an b2n | n >= 1} ?
a
ge G
l e d
n ow
www.knowledgegate.in
Q Design a PDA for {w c wr | w ∈(a, b)*} ?
at e
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Construct PDA that accepts L = {|w|a = b | w € (a, b)*} ?
a
ge G
l e d
n ow
www.knowledgegate.in
Q consider the following mapping and find the correct language?
δ (q0, 1, z0) = (q0, xz0)
at e
G
δ (q0, 1, x) = (q0, xx)
e
δ (q0, 0, x) = (q1, €)
g
δ (q1, 0, x) = (q1, €)
d
δ (q1, €, x) = (q1, €)
e
δ (q1, €, z0) = (qF, z0)
w
a) L = {am bn | m = n} l
o
b) L = {am bn | m != n}
n
c) L = {am bn | m >= n}
d) L = {am bn | m <= n}
www.knowledgegate.in
Q consider the following mapping and find the correct language?
δ (q0, a, z0) = (q1, z0)
δ (q0, b, z0) = (q2, z0)
at e
δ (q1, a, z0) = (q1, z0)
δ (q1, b, z0) = (q2, z0)
δ (q2, a, z0) = (q2, z0)
ge G
d
δ (q2, b, z0) = (q0, z0)
e
δ (q1, €, z0) = (qf, z0)
w l
o
a) ending with a
n
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
Non- Deterministic PDA
• Non- Deterministic PDA can also be defined using 7 tuples.
at e
G
• δ: Q x {∑ U ∈} x Γ → 2(Q x Γ* )
dge
• i.e. on a given input symbol and stack symbol a NPDA can move to more than one state.
w l e
n o www.knowledgegate.in
t e
Q Construct pda that accepts a language L = {w wr | w € (a, b)*}?
a
ge G
l e d
n ow
www.knowledgegate.in
at e
(GATE-2021)
ge G
l e d
n ow
www.knowledgegate.in
Q In a pushdown automaton P=(Q,Σ,Γ,δ,q0,F), a transition of the form,
at e
G
where p,q∈Q, a∈σ∪{ϵ}, X,Y,∈Γ∪{ϵ}, represents
(q,Y) ∈ δ(p,a,X)
dge
Consider the following pushdown automaton over the input alphabet Σ={a,b} and stack alphabet Γ={#,A}.
l e
The number of strings of length 100 accepted by the above pushdown automaton is ___________ .(GATE
w
2021) (2 MARKS)
n o www.knowledgegate.in
t e
Q Which one of the following languages over ∑ = {a, b} is NOT context-free?
(GATE-2019) (2 Marks)
a
G
a) {an bi | i ∈ {n, 3n, 5n}, n≥ 0} b) {w an wR bn | w ∈ {a, b}*, n≥ 0}
c) {w wR | w ∈ {a, b}*}
dge
d) {wan bn wR | w ∈ {a, b}*, n≥ 0}
w l e
n o www.knowledgegate.in
Q Consider the following languages:
I. {am bn cp dq ∣ m + p = n + q, where m, n, p, q ≥ 0}
at e
m n p q
ge G
II. {am bn cp dq ∣ m = n and p = q, where m, n, p, q ≥ 0}
III. {am bn cp dq ∣ m = n = p and p ≠ q, where m, n, p, q ≥ 0}
IV. {a b c d ∣ mn = p + q, where m, n, p, q ≥ 0}
l e d
n ow
Which of the above languages are context-free?
(GATE-2018) (2 Marks)
a) I and IV only
c) II and III only
b) I and II only
d) II and IV only
www.knowledgegate.in
Linear Grammar in Computer Science
at e
• A linear grammar is a type of context-free grammar where each production's right-hand side contains at most
G
one nonterminal symbol.
• Example of a simple linear grammar:
e
• Let G be a grammar with nonterminal set N={S}, terminal set Σ={a,b}, and the start symbol S.
• Production rules:
g
• S→aSb
d
• S→ε
• This grammar generates the language L={anbn∣n≥0}, which is a linear language.
e
• Types of Linear Grammars:
l
• 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.
w
• Both left-linear and right-linear grammars generate regular languages.
n o www.knowledgegate.in
• General Linear Grammars:
at e
• Nonterminal symbols can appear at either end of the production, but not necessarily always at the same end.
• Any linear grammar can be transformed into this form without changing the language generated.
G
• For example, the grammar:
• S→aAS
e
• A→SbA
• S→ε
g
• generates the same language as the example above.
l e d
n ow
www.knowledgegate.in
• Relation to Other Languages:
t e
• All regular languages are linear, but not all linear languages are regular. For example,
{anbn∣n≥0} is linear but non-regular.
a
G
• All linear languages are context-free, but not all context-free languages are linear. For
example, the well-balanced bracket language is context-free but not linear.
e
• Determinism and Complexity:
g
• Regular linear languages are deterministic, but some linear languages are
d
nondeterministic.
• For example, the language of even-length palindromes (generated by the grammar
l e
S→0S0∣1S1∣ε) is nondeterministic.
• Nondeterministic linear languages cannot always be recognized in linear time.
w
• Moreover, it is undecidable whether a given context-free language is linear.
n o www.knowledgegate.in
at e
Q Consider the transition diagram of a PDA given below with input alphabet ∑ = {a, b}and
stack alphabet Γ = {X, Z}. Z is the initial stack symbol. Let L denote the language
accepted by the PDA. (GATE-2016) (2 Marks)
ge G
l e d
n ow
www.knowledgegate.in
Q Consider the following languages (GATE-2016) (1 Marks)
L1 = {an bm cn: m, n >= 1}
at e
L2 = {an bn c2n: n >= 1}
ge G
l e d
w
Which one of the following is TRUE?
(A) Both L1 and L2 are context-free
o
(B) L1 is context-free while L2 is not context-free.
n
(C) L2 is context-free while L1 is not context-free
(D) Neither L1 nor L2 is context-free.
www.knowledgegate.in
t e
Q Which of the following languages are context-free? (GATE-2015) (2 Marks)
L1 = {am bn an bm ⎪ m, n ≥ 1}
a
L2 = {am bn am bn ⎪ m, n ≥ 1}
ge G
L3 = {am bn ⎪ m = 2n + 1}
l e d
n ow
(A) L1 and L2 only
(D) L3 only
www.knowledgegate.in
at e
ge G
l e d
n ow
Here, wr is the reverse of the string w. Which of these languages are deterministic Context-free
languages? (GATE-2014) (2 Marks)
(A) None of the languages
(C) Only L1 and L2
(B) Only L1
(D) All the three languages
www.knowledgegate.in
Q Consider the language L1, L2, L3 as given below. (GATE-2011) (2 Marks)
L1 = {ap bq | p, q ∈N}
at e
L2 = {ap bq | p, q ∈N and p=q}
ge G
L3 = {ap bq cr | p, q, r ∈N and p = q = r}
l e d
Which of the following statements is NOT TRUE?
w
(A) Push Down Automata (PDA) can be used to recognize L1 and L2
o
(B) L1 is a regular language
n
(C) All the three languages are context free
(D) Turing machine can be used to recognize all the three languages
www.knowledgegate.in
Q Consider the languages (GATE-2010) (2 Marks)
L1 = {0i 1j | i != j} L2 = {0i 1j | i = j}
at e
ge G
d
i j i j
L3 = {0 1 | i = 2j+1} L4 = {0 1 | i != 2j}
w l e
o
(B) Only L2 and L3 are context free
n
(C) Only L1 and L2 are context free
(D) All are context free
www.knowledgegate.in
Q Which one of the following is FALSE? (GATE-2009) (2 Marks)
(A) There is unique minimal DFA for every regular language
at e
G
(B) Every NFA can be converted to an equivalent PDA.
e
(C) Complement of every context-free language is recursive.
e dg
(D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA.
w l
n o www.knowledgegate.in
Q Consider the following languages. (GATE-2008) (2 Marks)
L1 = {ai bj ck | i = j, k ≥ 1} L2 = {ai bj | j = 2i, i ≥ 0}
at e
Which of the following is true?
ge G
(B) L1 ∩ L2 = ∅ and L1 is non-regular
l e d
w
(C) L1 ∩ L2 is not a CFL but L2 is
n o
(D) There is a 4-state PDA that accepts L1,
www.knowledgegate.in
t e
Q The language L = {0i21i | i≥0} over the alphabet {0,1, 2} is: (GATE-2007) (2 Marks)
a) not recursive.
a
c) is a regular language.
ge G
b) is recursive and is a deterministic CFL.
d
d) is not a deterministic CFL but a CFL
w l e
n o www.knowledgegate.in
Q (GATE-2006) (1 Marks)
at e
ge G
l e d
n o
(A) L1 onlyw
(C) L1 and L2
(B) L3 Only
(D) L2 and L3
www.knowledgegate.in
Q Consider the languages: (GATE-2005) (2 Marks)
L1 = {w wR |w ∈ {0, 1}*}
at e
e G
L2 = {w # wR | w ∈ {0, 1}*}, where # is a special symbol
g
L3 = {w w | w ∈ (0, 1}*)
l e d
n ow
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
at e
Q Let Nf and Np denote the classes of languages accepted by non-deterministic finite automata
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,
G
respectively. Which one of the following is TRUE? (GATE-2005) (1 Marks)
e
(A) Df ⊂ Nf and Dp ⊂ Np (B) Df ⊂ Nf and Dp = Np
e dg
(C) Df = Nf and Dp = Np
w l (D) Df = Nf and Dp ⊂ Np
n o www.knowledgegate.in
Q. The language {0n 1 2 n | 1<=n<=1 06} is : (GATE 2005, 1 Marks)
a) Regular
at e
b)
c)
d)
Context free but not regular
e G
Context free but its complement is not context free
Not Context free
g
l e d
n ow
www.knowledgegate.in
t e
Q The language {am bn Cm+n | m, n ≥ 1} is (GATE-2004) (1 Marks)
a
ge G
(A) regular
l e d
n w
(B) context-free but not regular
o
(C) context sensitive but not context free
(D) type-0 but not context sensitive
www.knowledgegate.in
t e
Q The language accepted by a Pushdown Automation in which the stack is
a
limited to 10 items is best described as (GATE-2003) (1 Marks)
g (D) Recursive
l e d
n ow
www.knowledgegate.in
automatan? (GATE - 1997, 1 Marks)
a) {w ⊂ w≥R | w ∈ (a,b)*}
at e
Q. Which of the following language over {a,b,c} is accepted by a deterministic pushdown
b) {wwR| w ∈ (a,b,c)*
c) {anbncn | n>=0}
g
d) {w | w is a palindrome over {a,b,c})
e G
l e d
n ow
www.knowledgegate.in
t e
Q Identity the language generated by following grammar where S is the
start variable. (GATE-2017) (2 Marks)
a
S -> XY
X -> aX | a
ge G
Y -> aYb | ∈
l e d
n ow
a) {am bn| m >= n, n > 0}
b) {am bn| m >= n, n >= 0}
c) {am bn| m > n, n >= 0}
d) {am bn| m > n, n > 0}
www.knowledgegate.in
and T are non-terminals. (GATE-2017) (2 Marks)
G1: S → aSb | T,T → cT | ϵ
at e
Q Consider the context-free grammars over the alphabet {a, b, c} given below. S
ge G
d
G2: S → bSa | T,T → cT | ϵ
w
The language L(G1) ∩ L(G2) is
l e
o
(A) Finite
n
(B) Not finite but regular
(c) Context-Free but not regular
(D) Recursive but not context-free
www.knowledgegate.in
t e
Q Consider the following context-free grammar over the alphabet ∑ = {a, b, c} with S as the start
symbol: (GATE-2017) (2 Marks)
a
G
S → abScT | abcT
T → bT | b
dge
l e
Which of the following represents the language generated by the above grammar?
a) {(ab)n(cb)n | n >= 1 }
w
o
b) {((ab)n c bm1 c bm2...c bmn | n, m1, m2, ....., mn >= 1 }
n
c) {(ab)n (cbm)n | m,n >= 1 }
ge G
(A) {an bm |n, m ≥ 0}
l e d
w
(B) {w ∈ {a, b}* | w has equal number of a’s and b’s}
n
(D) {a, b}*o
(C) {an |n ≥ 0} ∪ {bn |n ≥ 0} ∪ {an bn |n ≥ 0}
www.knowledgegate.in
Q Consider the following context-free grammars:
at e
ge G
d
Which one of the following pairs of languages is generated by G1 and G2, respectively (GATE-2016) (2 Marks)
w l e
n o www.knowledgegate.in
Q S -> aSa | bSb | a | b (GATE-2009) (2 Marks)
at e
The language generated by the above grammar over the alphabet {a, b} is the set of
ge G
(A) All palindromes
l e d
w
(B) All odd length palindromes.
n o
(C) Strings that begin and end with the same symbol
at e
A → 0A | A0 | 1
B → 0B00 | 1
ge G
grammar is
(A) {0n 102n | n ≥ 1}
l e d
S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this
n ow
(B) {0i 10j 10k | i, j, k ≥ 0} ∪ {0n 102n | n ≥ 0}
(D) The set of all strings over {0, 1} containing at least two 0’s
www.knowledgegate.in
Q Language L1 is defined by the grammar: S
1
-> aS1b | ε
at e
G
Language L2 is defined by the grammar: S -> abS2 | ε
2
dge
l e
Which one of the following is TRUE? (GATE-2007) (2 Marks)
w
a) Both P and Q are true
o
b) P is true and Q is false
n
c) P is false and Q is true
www.knowledgegate.in
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
at e
B → y | z | yB | zB
ge G B → y | yS
l e d
Which one of the following choices describes the properties satisfied by the strings in these languages?
w
a) G1: No y appears before any x, G2: Every x is followed by at least one y
o
b) G1: No y appears before any x, G2: No x appears before any y
n
c) G1: No y appears after any x,
www.knowledgegate.in
Q Consider the grammar given below (GATE – 2007) (2 Marks)
S → xB | yA
A → x | x S| y AA
at e
G
B → y | y S| x BB
dge
Consider the following strings.
i) xxyyx ii) xxyyxy
w
iv) yxxy v) yxx
iii) xyxy
vi) xyx
l e
n o
Which of the above strings are generated by the grammar?
a) i), ii) and iii)
c) ii), iii) and iv)
b) ii), v) and vi)
d) i), iii) and iv)
www.knowledgegate.in
t e
Q Which one of the following grammars generates the language L = {ai bj | i ≠ j} (GATE-2006) (1 Marks)
a
ge G
l e d
n ow
www.knowledgegate.in
and ϵ denotes the empty string (GATE-2006) (1 Marks)
S → aSa | bSb | a | b | ϵ
at e
Q In the context-free grammar below, S is the start symbol, a and b are terminals,
ge G
l e d
Which of the following strings is NOT generated by the grammar?
w
(A) aaaa (B) baba
o
(C) abba (D) babaaabab
n www.knowledgegate.in
Marks)
Which of the following is True?
at e
Q. Let L denotes the language generated by the grammar S -> 0S0/00. (GATE 2000, 1
a) L = 0+
b) L is regular but not 0+
c) L is context free but not regular
ge G
d
d) L is not Context free
w l e
n o www.knowledgegate.in
{xn yn such that n>= 1} (GATE -1995, 2 Marks)
1. E -> xEy | xy
at e
Q. Which of the following definitions below generates the same language as L, where L =
2. xy | (x+ syy+)
3. x+y+
ge G
d
a) 1 only
b) 1 and 2
c)
d)
2 and 3
2 only
w l e
n o www.knowledgegate.in
Q. Consider a context-free grammar 𝐺 with the following 3 rules.
𝑆 → 𝑎𝑆
𝑆 → 𝑎𝑆𝑏𝑆
at e
𝑆→𝑐
e G
Let 𝑤 ∈ 𝐿(𝐺). Let 𝑛𝑎(𝑤), 𝑛𝑏(𝑤), 𝑛𝑐(𝑤) denote the number of times 𝑎, 𝑏, 𝑐 occur in 𝑤,
g
respectively. Which of the following statements is/are TRUE? (Gate 2024 CS) (2 Marks)
d
(MSQ)
(a) 𝑛𝑎(𝑤) > 𝑛𝑏(𝑤)
w l e
o
(c) 𝑛𝑐(𝑤) = 𝑛𝑏(𝑤) + 1
n
(d) 𝑛𝑐(𝑤) = 𝑛𝑏(𝑤) ∗ 2
www.knowledgegate.in
t e
Q. Which ONE of the following languages is accepted by a deterministic pushdown automaton?
(Gate 2025)
a
G
A) Any regular language.
e
B) Any context-free language.
g
C) Any language accepted by a non-deterministic pushdown automaton.
d
D) Any decidable language.
w l e
n o www.knowledgegate.in
Decision properties
at e
Following properties are decidable in case a CFL. Here we will use Grammar model
G
to proof decision properties.
i) Emptiness
ii) Non-emptiness
dge
iii) Finiteness
w l e
o
iv) Infiniteness
n
v) Membership
www.knowledgegate.in
t e
Q consider the following CFG and identify which of the following CFG generate Empty language?
S -> aAB / Aa
a
A -> a
ge G
d
S -> aAB
e
A -> a / b
S -> aAB / aB
w l
A -> aBb
B -> aA
n o www.knowledgegate.in
t e
Q consider the following CFG and identify which of the following CFG generate Finite
language?
a
G
S -> SS / AB
e
A -> BC / a
g
B -> CC / b
S -> AB
A -> B / a
l e d
S -> AB
A -> BC / a
B -> CC / b
C -> AB
n ow
www.knowledgegate.in
t e
Q consider the following CFG and check out the membership properties?
a
G
S -> AB / BB
A -> BA / AS / b
B -> AA / SB / a
dge
w1 = aba
w2 = abaab
w l e
n o
w3 = abababba
www.knowledgegate.in
•
CYK algorithm
In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is
at e
G
a parsing algorithm for context-free grammars, named after its inventors, John Cocke, Daniel Younger and Tadao
e
Kasami. It employs bottom-up parsing and dynamic programming.
g
• The standard version of CYK operates only on context-free grammars given in Chomsky normal form (CNF).
However any context-free grammar may be transformed to a CNF grammar expressing the same language (Sipser
d
1997).
e
• The importance of the CYK algorithm stems from its high efficiency in certain situations. Using Big O notation,
l
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
the CNF grammar G.
ow
This makes it one of the most efficient parsing algorithms in terms
of worst-case asymptotic complexity, although other algorithms exist
with better average running time in many practical scenarios.
n www.knowledgegate.in
i) Equality
Following properties are Undecidable in case a CFL
at e
ii) Ambiguity
ge G
l e d
n ow
www.knowledgegate.in
Q Which of the following problems is undecidable? (GATE-2014) (1 Marks)
at e
e G
(B) Deciding if a given string is generated by a given context-free grammar.
g
(C) Deciding if the language generated by a given context-free grammar is empty.
e d
(D) Deciding if the language generated by a given context-free grammar is finite.
l
n ow
www.knowledgegate.in
Q Which of the following are decidable? (GATE-2008) (2 Marks)
I. Whether the intersection of two regular languages is infinite
at e
G
II. Whether a given context-free language is regular
dg
IV. Whether a given grammar is context-free
e
III. Whether two push-down automata accept the same language
w l e
c). II and III d). II and IV
n o www.knowledgegate.in
(A) Membership problem for CFGs
at
(B) Ambiguity problem for CFGs.
e
Q Which of the following problems is undecidable? (GATE-2007) (1 Marks)
ge G
(C) Finiteness problem for FSAs.
l e d
(D) Equivalence problem for FSAs.
n ow
www.knowledgegate.in
Q Which one of the following statements is FALSE? (GATE-2004) (1 Marks)
at e
a) There exist context free languages such that all the context free grammars generating them
G
age ambiguous.
dge
b) An unambiguous context free grammar always has a unique parse tree for each string of the
e
c) Both deterministic and non – deterministic pushdown automata always accept the same set of
l
languages
w
d) A finite set of string from one alphabet is always a regular language.
n o www.knowledgegate.in
Q Consider the following decision problems? (GATE-2000) (2 Marks)
(P1) Does a given finite state machine accept a given string
at e
ge G
(P2) Does a given context free grammar generate an infinite number of stings
l e d
w
Which of the following statements is true?
o
(A) Both (P1) and (P2) are decidable
(B) Neither (P1) nor (P2) are decidable
n
(C) Only (P1) is decidable
(D) Only (P2) is decidable
www.knowledgegate.in
Emptiness
RL
Y
DCFL
Y
CFL
Y
CSL
X
RS
N
at
N e
RES
Non-Emptiness
Finiteness
Y
Y
Y
Y
ge
Y
Y G X
X
N
N
N
N
Infiniteness
Membership
Y
Y
Y
Y
l e d Y
Y
X
X
N
Y
N
N
Equality
Ambiguity
∑*
n
Y
Y
Yow N
N
N
N
N
N
X
X
X
N
N
N
N
N
N
Halting Y Ywww.knowledgegate.in
Y X Y N
Closure Properties of Deterministic Context Free Languages
• Deterministic Context Free Languages are closed under following operations
• Complement
at e
G
• Intersection with regular set
e
• Inverse Homeomorphism
g
• Deterministic Context Free Languages are not closed under following operations
d
• Union
• Concatenation
• Kleen closure
• homomorphism
w
• Substitution
• Reverse operator l e
n o
• Intersection
www.knowledgegate.in
Closure Properties of Context Free Languages
• Context Free Languages are closed under following operations
• Union
at e
G
• Concatenation
• Kleen Closure
e
• Substitution
g
• Homomorphism
• Inverse Homomorphism
d
• Reverse Operator
e
• Intersection with regular set
• Intersection
w
• Complement
l
• Context Free Languages are not closed under following operations
o
• Symmetric Difference
n www.knowledgegate.in
Union
RL
Y
DCFL
N
CFL
Y
CSL
Y
RS
atY
e
RES
G
Intersection Y N N Y Y Y
Complement
Set Difference
Y
Y
Y
N
N
N
dge Y
Y
Y
Y
N
N
e
Kleene Closure Y N Y Y Y Y
Positive Closure
Concatenation
Y
Y
w
N
N
l Y
Y
Y
Y
Y
Y
Y
Y
o
Intersection with
regular set Y Y Y Y Y Y
Reverse
Subset
n Y
N
Y
N
Y
N
Y
N
www.knowledgegate.in
Y
N
Y
N
Homomorphism
RL
Y
DCFL
N
CFL
Y
CSL
N
a
Nt
RS
e RES
Y
∈ Free Homomorphism
Y
ge G
N Y Y Y Y
Y
d Y Y Y Y Y
Inverse Homomorphism
Substitution
w
Y
l e N Y N N Y
o
∈ Free Substitution Y N Y Y Y Y
n
Quotient with regular set Y Y Y
www.knowledgegate.in
N Y Y
t e
Q For a string w, we define wR to be the reverse of w. For example, if w = 01101 then wR =
a
10110. Which of the following languages is/are context-free?(GATE 2021) (2 MARKS)
G
(A) {wxwRxR ∣ w,x∈{0,1}*}
dge
(D) {wxxRwR ∣ w,x∈{0,1}*}
w l e
n o www.knowledgegate.in
Q Consider the following languages:
L1 = {ww| w ∈ {a,b}*}
L2 = {anbncm |m,n >= 0}
at e
G
L3 = {ambncn |m,n >= 0}
e
Which of the following statements is/are FALSE?(GATE 2022) (2 MARKS)
e dg
(A) L1 is not context-free but L2 and L3 are deterministic context-free.
l
(C) L2 , L3 and L2 ∩ L3 all are context-free.
w
o
(D) Neither L1 nor its complement is context-free.
n www.knowledgegate.in
Q Consider the following languages:
L1 = {anwan | w ∈{a,b}* }
L2 ={wxwR | w, x ∈ {a,b}*,|w|,|x|> 0}
at e
G
Note that wR is the reversal of the string w. Which of the following is/are TRUE? (GATE 2022) (2
e
MARKS)
e dg
(C) L1 is regular and L2 is context-free.
w l
o
(D) L1 and L2 are context-free but not regular.
n www.knowledgegate.in
t e
Q Suppose that L1 is a regular language and L2 is a context-free language.
a
Which one of the following languages is NOT necessarily context-free?
G
(GATE 2021)
(a) L1 ∩ L2
dge
e
(b) L1 ⋅ L2
(c) L1 − L2
w l
n
(d) L1 ∪ L2
o www.knowledgegate.in
t e
Q Let L1 be a regular language and L2 be a context-free language. Which of the following
languages is/are context-free? (GATE 2021) (1 MARKS)
a
G
(A) L1∩L2'
(B) (L1'∪L2')'
(C) L1∪(L2∪L2')
dge
(D)(L1∩L2)∪(L1∩L2)
w l e
n o www.knowledgegate.in
Q Let L1 and L2 be any context-free language and R be any regular language. Then,
which of the following is correct? (GATE-2017) (2 Marks)
at e
I. L1 ∪ L2 is context-free.
III. L1 - R is context-free.
l e d IV. L1 ∩ L2 is context-free
n ow
a) I, II and IV only
c) II and IV only
b) I and III only
d) I only
www.knowledgegate.in
Q Consider the following languages over the alphabet ∑= {a, b, c}.
Let L1 = {an bn cm | m, n >= 0} and L2 = {am bn cn | m, n >= 0}.
at e
ge G
I. L1 ∪ L2
l e d
Which of the following are context-free languages? (GATE-2017) (2 Marks)
w
II. L1 ∩ L2
a) I only
n
c) I and II o b) II only
d) Neither I nor II
www.knowledgegate.in
t e
Q Which one of the following statements is FALSE? (GATE-2013) (1
Marks)
a
G
L1 = {0p 1q 0r ∣ p, q, r ≥ 0} L2 = {0p 1q 0r ∣p, q, r ≥ 0, p ≠ r}
dge
e
(A) L2 is context-free.
w l
(B) L1 intersection L2 is context-free.
n o
(C) Complement of L2 is recursive.
at e
ge G
d
a) Non recursive
b) Regular
c)
d)
Context Free but not regular
l e
Recursively enumerable but not context free
w
n o www.knowledgegate.in
t e
Q Let L be a context - free language and M a regular language. Then the language L ∩ M is
(GATE-2006) (1 Marks)
a
a) Always regular
e G
b) Never regular
g
l e d
c) Always a deterministic context free language d) Always a context – free language
n ow
www.knowledgegate.in
Q Consider the languages: (GATE-2005) (2 Marks)
L1 = {an bn cm | n, m > 0} L2 = {an bm cm | n, m > 0}
at e
ge G
e d
Which one of the following statements is FALSE?
(A) L1 ∩ L2 is a context-free language
l
n w
(B) L1 U L2 is a context-free language
o
(C) L1 and L2 are context-free language
www.knowledgegate.in
at e
Q Let L be a regular language and M be a context-free language, both over the alphabet Σ. Let Lc
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)
ge G
l e d
(A) It is necessarily regular but not necessarily context-free
w
(B) It is necessarily context-free.
n o
(C) It is necessarily non-regular.
www.knowledgegate.in
Q Which of the following statements is true? (GATE-2001) (1 Marks)
at e
(A) If a language is context free it can always be accepted by a deterministic push-down
automaton
ge G
(B) The union of two context free languages is context free
l e d
(C) The intersection of two context free languages is context free
n ow
(D) The complement of a context free language is context free
www.knowledgegate.in
Q Consider the following decision problems (GATE-2000) (2 Marks)
(P1) Does a given finite state machine accept a given string
at e
ge G
(P2) Does a given context free grammar generate an infinite number of stings
l e
Which of the following statements is true?d
w
(A) Both (P1) and (P2) are decidable
o
(B) Neither (P1) nor (P2) are decidable
n
(C) Only (P1) is decidable
(D) Only (P2) is decidable
www.knowledgegate.in
t e
Q Let L1 is context free language and L2 is a regular language which of the following
is/are false (GATE – 1999) (1 Marks)
a
ge G
a) L 1 – L2 is not context free
l e d
w
b) L1 ∩ L2 is context free
n o
c) ~ L1 is context free
d) ~ L2 is regular
www.knowledgegate.in
Q Context – free language is closed under: (GATE – 1999) (1 Marks)
a) Union, intersection b) Union, Kleene closure
at e
ge G
c) Intersection, complement
n ow
www.knowledgegate.in
t e
Q. Let L1 and L2 are context free language and R a regular set, one of the languages below
is not necessarily a context free language. Which one? (GATE 1996,1 Marks)
a
a)
b)
c)
L1 , L 2
L1 ∩ L2
L1 ∩ R
L1 ∪ L2
ge G
d
d)
w l e
n o www.knowledgegate.in
Q Context – free languages are (GATE – 1992) (1 Marks)
a) Closed under union b) Closed under complementation
at e
ge G
c) Closed under intersection
l e d
d) Closed under Kleene closure
n ow
www.knowledgegate.in
t e
Q. Let 𝐺1, 𝐺2 be Context Free Grammars (CFGs) and 𝑅 be a regular expression. For a grammar 𝐺,
let 𝐿(𝐺) denote the language generated by 𝐺.
a
G
Which ONE among the following questions is decidable? (Gate 2025)
A) Is 𝐿(𝐺1 ) = 𝐿(𝐺2 )?
B) Is 𝐿(𝐺1 ) ∩ 𝐿(𝐺2 ) = ∅?
C) Is 𝐿(𝐺1 ) = 𝐿(𝑅)?
dge
e
D) Is 𝐿(𝐺1 ) = ∅?
w l
n o www.knowledgegate.in
t e
Q. Consider the following two languages over the alphabet {𝑎, 𝑏, 𝑐}, where 𝑚 and 𝑛 are natural
numbers.
a
G
𝐿1 = {𝑎𝑚𝑏𝑚𝑐𝑚+𝑛 | 𝑚, 𝑛 ≥ 1}
𝐿2 = {𝑎𝑚𝑏𝑛𝑐𝑚+𝑛 | 𝑚, 𝑛 ≥ 1}
dge
Which ONE of the following statements is CORRECT? (Gate 2025)
e
A) Both 𝐿1 and 𝐿2 are context-free languages.
w l
B) 𝐿1 is a context-free language but 𝐿2 is not a context-free language.
C) 𝐿1 is not a context-free language but 𝐿2 is a context-free language.
D) Neither 𝐿1 nor 𝐿2 are context-free languages.
n o www.knowledgegate.in
Turing Machine
at e
• The Church-Turing thesis posits that any computational task performable by a human or machine can be
executed by a Turing machine. It is widely regarded as a fundamental theoretical model of computation in
G
computer science.
• Turing machines serve several key purposes:
e
• General Automaton: Turing machines are the most general form of automaton, capable of simulating any
g
algorithmic process.
• Type-0 Language Acceptance: They can recognize type-0 languages, which are the most complex in the
d
Chomsky hierarchy.
e
• Function Computation: Turing machines can compute any computable function.
l
• Undecidability & Complexity: They help determine the undecidability of certain languages and are used to
measure both time and space complexity for computational problems.
n ow
www.knowledgegate.in
• Components of a Turing Machine:
at e
• 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
G
two-way infinite tape.
• Read-Write Head: The head reads symbols from the tape and can also write over them. After reading or
e
writing, it moves one cell either to the left or right.
• Finite Control Unit: The control unit governs transitions based on the current state and symbol under the
g
read-write head. It determines the next action, ultimately leading to the machine’s output.
l e d
n ow
www.knowledgegate.in
FORMAL DEFINITION
A Turing machine M is a 7-tuple, namely (Q, ∑, Γ, δ, q0, b, F), where
at e
G
• Q is a finite nonempty set of states.
e
• Γ is a finite nonempty set of tape symbols,
g
• b ∈ Γ is the blank.
l d
• ∑ is a nonempty set of input symbols and is a subset of Γ and b ∉∑.
e
• δ 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
w
whether next the machine needs to move in left/ right.
o
• q0 ∈ Q is the initial state, and
n
• F ⊆ Q is the set of final states.
www.knowledgegate.in
Q Design a Turing machine for L = {ab}?
at e
ge G
l e d
n ow
www.knowledgegate.in
Q Design a Turing machine for L = {a, ab}?
at e
ge G
l e d
n ow
www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
Three representations:
REPRESENTATION OF TURING MACHINES
at e
G
• Instantaneous descriptions using move-relations.
e
• Transition table, and
• Transition diagram (transition graph).
e dg
w l
n o www.knowledgegate.in
LANGUAGE ACCEPTABILITY BY TURING MACHINES
at e
• 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.
e G
• q0w ⊢* α1pα2 for some p ∊ F and α1, α2 ∊ Γ *.
g
d
• M does not accept w if the machine M either halts in a non-accepting state or does not halt
e
and goes into a loop.
w l
n o www.knowledgegate.in
Q Design a Turing machine for L = {an bn | n >= 1}?
at e
ge G
l e d
n ow
www.knowledgegate.in
Q Design a Turing machine for L = {an bn cn| n >= 0}?
at e
ge G
l e d
n ow
www.knowledgegate.in
t
Q Design a Turing machine for L = {w c w | w ∊ {0, 1}* }?
a e
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a Turing machine for addition of two number in unary?
a
ge G
l e d
n ow
www.knowledgegate.in
t e
Q Design a Turing machine for converting unary number into binary
number?
a
ge G
l e d
n ow
www.knowledgegate.in
at e
Q A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The
tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}. The symbol B is the blank symbol
used to indicate end of an input string. The transition function of M is described in the following
G
table. Which of the following statements is true about M ?
0 1 B
e
(A) M does not halt on any string in (0 + 1)+
g
*
q0 q1, 1, R q1, 1, R Halt
(B) M does not halt on any string in (00 + 1)
d
q1 q1, 1, R q0, 1, L q0, B, L
e
(C) M halts on all string ending in a 0
w l
n o www.knowledgegate.in
Which of the following strings will not accepted?
a) 010101 b) 101010 c) 110011 d) Both a and b
t e
Q Consider the transition table of a TM given below. Here “b” represents the blank symbol.
a
ge G
l e d
n ow
www.knowledgegate.in
Q The given Turing machine accepts
a) set of all even palindromes over {0, 1}
at e
e G
b) strings over {0, 1} containing even number of 1’s
g
d
c) strings over {0, 1} containing even number of 1’s
e
and odd no. of 0’s
w
d) string over {0, 1} starting with zero
l
n o www.knowledgegate.in
Q Consider the following languages.
L1 = {ap | p is a prime number}
at e
G
L2 = {an bm c2m | n >= 0, m >= 0}
dge
e
L4 = {an bn | n >= 1}
w
II. L2 is not context free.
IV. L4 is deterministic context free
n
c) I and IV only
o
a) I, II and IV only b) II and III only
d) III and IV only
www.knowledgegate.in
Q Which of the following is true for the language
(A) It is not accepted by a Turing Machine
t e
(GATE-2008) (2 Marks)
a
(B) It is regular but not context-free
ge G
d
(C) It is context-free but not regular
l e
(D) It is neither regular nor context-free, but accepted by a Turing machine
w
n o www.knowledgegate.in
Q For S ∈ (0 + 1) * let d(s) denote the decimal value of s (e.g. d (101) = 5).
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?
at e
G
(A) L is recursively enumerable, but not recursive
dge
(C) L is context-free, but not regular
w l e
n o
(D) L is regular
www.knowledgegate.in
at e
Q L1 is a recursively enumerable language over Σ. An algorithm A effectively enumerates its words as w1, w2, w3, …
Define another language L2 over Σ Union {#} as {wi # wj : wi, wj ∈ L1, i < j}. Here # is a new symbol. Consider the
following assertions. (GATE-2004) (2 Marks)
G
S1 : L1 is recursive implies L2 is recursive
dge
Which of the following statements is true ?
w
(A) Both S1 and S2 are true
l e
o
(B) S1 is true but S2 is not necessarily true
n
(C) S2 is true but S1 is not necessarily true
(D) Neither is necessarily true
www.knowledgegate.in
• Deterministic and Non-Deterministic Turing Machines:
at e
• Deterministic: Each state and symbol pair leads to a single possible move.
• Non-Deterministic: Multiple moves may be possible for a given state and symbol.
G
However, non-deterministic Turing machines do not add computational power and can
e
always be converted into a deterministic Turing machine.
e dg
w l
n o www.knowledgegate.in
Versions of Turing Machines:
t e
• Multi-Tape Turing Machine: Uses multiple tapes with corresponding read/write heads. However, every multi-tape machine
can be simulated by a single-tape machine.
• Multi-Head Turing Machine: A machine with multiple read/write heads.
a
G
• 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.
e
• One-Way Infinite Tape (Semi-Infinite Tape): The tape is infinite in only one direction.
g
• Offline Turing Machine: The input tape is read-only and cannot be modified.
• Jumping Turing Machine: Can make multiple moves in one transition.
d
• 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.
e
• Finite Automaton with Queue: Combines a finite automaton with an unbounded queue.
l
• 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.
w
• 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.
n o www.knowledgegate.in
Q Which of the following pairs have DIFFERENT expressive power? (GATE-2011) (1 Marks)
a) Deterministic finite automata (DFA) and non – deterministic finite automata (NFA)
at e
ge G
b) Deterministic push down automata (DPDA) and Non – deterministic push down automata (NPDA)
l e d
c) Deterministic single – tape Turing machine and Non – deterministic single tape Turing machine
w
d) Single – tape Turing machine and multi – tape Turing machine
n o www.knowledgegate.in
Halt in a Turing Machine
at e
• When a Turing machine reaches a state where no further transitions are defined or needed, it
G
is said to halt. There are two types of halts:
• Final Halt: The machine halts in a final (accepting) state, indicating that the input string is
accepted.
ge
• Non-Final Halt: The machine halts in a non-final state, meaning the input string is rejected.
d
• After processing an input string, a Turing machine can experience one of three outcomes:
e
• Final Halt: The machine accepts the string.
l
• Non-Final Halt: The machine rejects the string.
• Infinite Loop: The machine enters an infinite loop, in which case it is undecidable whether
w
the string is accepted or rejected.
n o www.knowledgegate.in
• Recursive Set:
Recursively Enumerable Languages
at
• A language L is a recursive set if it is accepted by a Turing machine in such a way that:
e
G
• 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).
e
• The membership property is clearly defined here—every string is either accepted or rejected.
g
• Recursively Enumerable Set (REL):
• A language L is recursively enumerable if it is accepted by a Turing machine, where:
d
• For all w∈L, the machine halts in a final state (accepts).
• For all w∉L, the machine may either halt in a non-final state (reject) or enter an infinite loop.
l e
• The membership property is not defined because the machine might never halt for certain strings.
• Decidability:
• A set is decidable if both the set and its complement are recognizable by a Turing machine.
w
• Some sets are not recognizable, meaning that even the members of the set cannot be identified, as there are
o
more languages than programs available to recognize them.
n www.knowledgegate.in
Q Let L be a language and L’ be its complement. Which one of the
following is NOT a viable possibility? (GATE-2014) (1 Marks)
at e
G
(A) Neither L nor L’ is recursively enumerable (r.e.).
dge
(B) One of L and L’ is r.e. but not recursive; the other is not r.e.
w l e
(C) Both L and L’ are r.e. but not recursive.
n o
(D) Both L and L’ are recursive
www.knowledgegate.in
Q Which of the following statements is false? (GATE-2008) (1 Marks)
(A) Every NFA can be converted to an equivalent DFA
at e
e G
(B) Every non-deterministic Turing machine can be converted to an equivalent
deterministic Turing machine
g
l e d
(C) Every regular language is also a context-free language
ow
(D) Every subset of a recursively enumerable set is recursive
n www.knowledgegate.in
t e
Q If L and L’ are recursively enumerable, then L is (GATE-2008) (1 Marks)
(A) regular
a
(B) context-free
ge G
(C) context-sensitive
l e d
n ow
(D) recursive
www.knowledgegate.in
language. Which one of the following is TRUE? (GATE-2005) (1 Marks)
L1’ 🡪 Complement of L1
at e
Q Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive
ge G
d
L2’ 🡪 Complement of L2
w l e
(A) L1′ is recursive and L2′ is recursively enumerable
o
(B) L1′ is recursive and L2′ is not recursively enumerable
n
(C) L1′ and L2′ are recursively enumerable
at e
• In computer science, a Universal Turing Machine (UTM) is a Turing machine capable of simulating any
G
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.
e
• Every Turing machine computes a fixed partial computable function from input strings over its
g
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
d
string, which describes the action table, followed by a string that describes the input tape, and
e
simulate the encoded Turing machine's behavior.
l
• In his 1936 paper, Turing described this concept in detail, stating:
w
• "It is possible to invent a single machine which can be used to compute any computable sequence.
o
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."
n www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
●L1 = { ⟨M⟩ ∣ M takes more than 2021 steps on all inputs }
●L2 = { ⟨M⟩ ∣ M takes more than 2021 steps on some input }
at e
Q For a Turing machine M, ⟨M⟩ denotes an encoding of M. Consider the following two languages.
G
Which one of the following options is correct? (GATE 2021) (2 MARKS)
dge
e
(d) Both L1 and L2 are undecidable
w l
n o www.knowledgegate.in
the following languages is/are NOT recursive? (GATE 2021)
(a) L = {⟨M⟩ ∣ M is a DFA such that L(M)=∅}
at e
Q Let ⟨M⟩ denote an encoding of an automaton M. Suppose that Σ={0,1}. Which of
e G
(b) L = {⟨M⟩ ∣ M is a DFA such that L(M)=Σ*}
g
d
(c) L = {⟨M⟩ ∣ M is a PDA such that L(M)=∅}
l e
(d) L = {⟨M⟩ ∣ M is a PDA such that L(M)=Σ*}
w
n o www.knowledgegate.in
Q L1 = { <M> | M takes at least 2016 steps on some input},
at e
G
L2 = { <M> | M takes at least 2016 steps on all inputs} and
dge
where for each Turing machine M, <M> denotes a specific encoding of M.
l e
Which one of the following is TRUE? (GATE-2016) (2 Marks)
w
o
(A) L1 is recursive and L2, L3 are not recursive
(B) L2 is recursive and L1, L3 are not recursive
n
(C) L1, L2 are recursive and L3 is not recursive
(D) L1, L2, L3 are recursive
www.knowledgegate.in
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)
at e
G
(A) decidable and recursively enumerable
dge
w l e
(C) undecidable and not recursively enumerable
n o
(D) decidable but not recursively enumerable
www.knowledgegate.in
Linear Bounded Automaton (LBA)
at e
• An LBA is a variant of a Turing machine with the following property: The tape
G
length is finite and bounded, unlike a traditional Turing machine that has an
e
infinite tape.
e dg
w l
n o www.knowledgegate.in
Decision properties
at e
G
• Following properties are decidable in case a RS.
e
• Membership
e dg
• All properties are undecidable in case of a REL.
w l
n o www.knowledgegate.in
Emptiness
RL
Y
DCFL
Y
CFL
Y
CSL
X
RS
N
RES
N
at e
G
Non-Emptin
Y Y Y X N N
ess
e
Finiteness Y Y Y X N N
g
Infiniteness Y Y Y X N N
d
Membershi
Y Y Y X Y N
e
p
l
Equality Y N N X N N
Ambiguity Y N N X N N
∑*
Halting
Y
n ow N
Y
N
Y
X
X
N
Y
N
www.knowledgegate.in
Q Which of the following is/are undecidable? (GATE 2022) (2 MARKS)
at e
e G
(B) Given a Turing machine M, decide if L(M) is regular.
g
(C) Given a Turing machine M, decide if M accepts all strings.
e d
(D) Given a Turing machine M, decide if M takes more than 1073 steps on every string.
l
n ow
www.knowledgegate.in
the language accepted by a machine M.
(I) For an unrestricted grammar G and a string w, whether w ϵ L(G)
at e
Q Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes
ge G
(II) Given a Turing machine M, whether L(M) is regular
l d
(IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language
e
Which one of the following statement is correct? (GATE-2018) (2 Marks)
a) Only I and II are undecidable
n ow
b) Only II is undecidable
www.knowledgegate.in
at e
Q Let L(R) be the language represented by regular expression R. Let L(G) be the language
generated by a context free grammar G. Let L(M) be the language accepted by a Turing machine
M. Which of the following decision problems are undecidable? (GATE-2017) (2 Marks)
G
I. Given a regular expression R and a string w, is w ∈ L(R)?
dge
III. Given a context-free grammar G, is L(G)=Σ∗ for some alphabet Σ?
w
a) I and IV only
l
b) II and III only
e
IV. Given a Turing machine M and a string w, is w ∈ L(M)?
n o
c) II, III and IV only d) III and IV only
www.knowledgegate.in
t e
Q Which of the following decision problems are undecidable (GATE-2016) (2
Marks)
a
ge G
(A) I and IV only
l e d
n w
(B) II and III only
o
(C) III and IV only
1) G is a CFG. Is L(G)=ϕ?
at e
2) G is a CFG. Is L(G)=Σ∗?
ge G
4) A is a DFA and N is an NFA. Is L(A)=L(N)?
l e d
w
(A) 3 only (B) 3 and 4 only
n o
(C) 1, 2 and 3 only (D) 2 and 3 only
www.knowledgegate.in
Q Which of the following problems are decidable? (GATE-2012) (2 Marks)
a) Does a given program ever produce an output?
at e
G
b) If L is a context-free language, then, is L’ also context-free?
dge
c) If L is a regular language, then, is L’ also regular?
a) 1, 2, 3, 4
w
b) 1, 2
l e
c) 2, 3, 4
n o d) 3, 4
www.knowledgegate.in
Q Which of the following is not decidable? (GATE – 1997) (1 Marks)
at e
a) Given a Turing machine M, a strings s and an integer k, M accepts s within k steps
ge G
l e d
c) Language accepted by a given finite state machine is not empty
ow
d) Languages generated by a context free grammar is non empty
n www.knowledgegate.in
Closure Properties of Recursive Set
• Recursive languages are closed under following operations
• Union
at e
G
• Concatenation
• Intersection
e
• Reverse
g
• Complement
• Inverse homomorphism
d
• Intersection with regular set
• Set Difference
l e
• Kleen closure
w
• Recursive languages are not closed under following operations
o
•
• Homomorphism
n
• Substitution
www.knowledgegate.in
Closure Properties of Recursive Enumerable Set
• Recursive Enumerable are closed under following operations
• Union
at e
G
• Concatenation
• Kleen Closure
e
• Intersection
g
• Substitution
• Homomorphism
d
• Inverse Homomorphism
e
• Intersection with regular set
l
• Reverse operation
w
• Recursive Enumerable are not closed under following operations
o
• Compliment
• Set Difference
n www.knowledgegate.in
Union
RL
Y
DCFL
N
CFL
Y
CSL
Y
RS
Y
RES
Y
at e
G
Intersection Y N N Y Y Y
e
Complement Y Y N Y Y N
g
Set Difference Y N N Y Y N
d
Kleene Closure Y N Y Y Y Y
e
Positive Closure Y N Y Y Y Y
l
Concatenation Y N Y Y Y Y
w
Intersection
Y Y Y Y Y Y
with regular set
o
Reverse Y Y Y Y Y Y
Subset N N N N N N
n www.knowledgegate.in
Homomorphism
RL
Y
DCFL
N
CFL
Y
CSL
N
RS
N
RES
Y
at e
G
∈ Free
e
Homomorphism Y N Y Y Y Y
Inverse
Homomorphism
Y Y
e
Y
dg Y Y Y
l
Substitution
Y N Y N N Y
ow
∈ Free Substitution
Quotient with
n
regular set
Y
Y
N
Y
Y
Y
Y
N
Y
Y
Y
www.knowledgegate.in
Q Which of the following statements is/are TRUE? (GATE 2022) (1 MARKS)
at e
e G
(B) If a language L and its complement L’ are both recursively enumerable, then L must be
recursive.
g
d
(C) Complement of a context-free language must be recursive.
l e
(D) If L1 and L2 are regular, then L1 ∩ L2 must be deterministic context-free.
w
n o www.knowledgegate.in
t e
Q The set of all recursively enumerable languages is (GATE-2018) (1 Marks)
a) closed under complementation.
a
b) closed under intersection.
ge G
e d
c) a subset of the set of all recursive languages.
l
ow
d) an uncountable set.
n www.knowledgegate.in
Q Consider the following types of languages (GATE-2016) (2 Marks)
L1 Regular, L2: Context-free L3: Recursive,
Which of the following is/are TRUE?
L4: Recursively enumerable.
at e
G
I. L3' U L4 is recursively enumerable
II. L2 U L3 is recursive
dge
IV. L1 U L2' is context-free
w l e
o
(A) I only (B) I and III only
n
(C) I and IV only (D) I, II and III only
www.knowledgegate.in
at e
Q For any two languages L1 and L2 such that L1 is context free and L2 is recursively enumerable
but not recursive, which of the following is/are necessarily true? (GATE-2015) (2 Marks)
1. L1' is recursive
2. L2' is recursive
ge G
3. L1' is context-free
l e d
w
4. L1' ∪ L2 is recursively enumerable
(A) 1 only
n o
(C) 3 and 4 only
(B) 3 only
at e
Q Let L be a language and L' be its complement. Which one of the following is NOT a viable
e G
b) One of L and L' is r.e. but not recursive; the other is not r.e.
g
e
c) Both L and L' are r.e. but not recursive.
l d
w
d) Both L and L' are recursive
n o www.knowledgegate.in
Q Which of the following statements is/are FALSE? (GATE-2013) (2 Marks)
at e
1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing
machine.
e G
2. Turing recognizable languages are closed under union and complementation.
g
3. Turing decidable languages are closed under intersection and complementation.
e d
4. Turing recognizable languages are closed under union and intersection.
l
w
(A) 1 and 4 only (B) 1 and 3 only
(C) 2 only
n o (D) 3 only
www.knowledgegate.in
at e
Q Let L1 be a recursive language. Let L2 and L3 be languages that are recursively enumerable but
not recursive. Which of the following statements is not necessarily true? (GATE-2010) (1 Marks)
(A) L2 – L1 is recursively enumerable.
ge G
(C) L2 ∩ L1 is recursively enumerable
l e d
n ow
(D) L2 ∪ L1 is recursively enumerable
www.knowledgegate.in
Q Which one of the following is FALSE? (GATE-2009) (1 Marks)
A) There is unique minimal DFA for every regular language
at e
e G
B) Every NFA can be converted to an equivalent PDA
g
d
C) Complement of every context-free language is recursive.
l e
D) Every non-deterministic PDA can be converted to an equivalent deterministic PDA
w
n o www.knowledgegate.in
order, which of the following statements is true? (GATE-2003) (1 Marks)
(A) L is necessarily finite
at e
Q If the strings of a language L can be effectively enumerated in lexicographic (i.e., alphabetic)
ge G
e d
(C) L is context free but not necessarily regular
l
w
(D) L is recursive but not necessarily context free
n o www.knowledgegate.in
Q Which of the following is true? (GATE-2002) (1 Marks)
(A) The complement of a recursive language is recursive.
at e
e G
(B) The complement of a recursively enumerable language is recursively enumerable.
g
d
(C) The complement of a recursive language is either recursive or recursively enumerable.
l e
(D) The complement of a context-free language is context-free.
w
n o www.knowledgegate.in
at e
ge G
l e d
n ow
www.knowledgegate.in
Cook-Levin Theorem (Cook's Theorem)
at e
• In computational complexity theory, the Cook-Levin theorem states that the Boolean satisfiability
problem (SAT) is NP-complete. This means:
G
• SAT is in NP, and any problem in NP can be reduced in polynomial time by a deterministic Turing
machine to SAT.
e
• An important implication of this theorem is that if a deterministic polynomial-time algorithm exists
g
for SAT, then every NP problem can be solved in polynomial time. This leads to the famous P vs NP
d
problem, one of the most important open questions in theoretical computer science.
w l e
n o www.knowledgegate.in
Stephen Cook's Contributions:
at e
• During his PhD, Cook worked on function complexity, focusing on multiplication. In his 1971 landmark paper,
"The Complexity of Theorem Proving Procedures", Cook formalized the concepts of polynomial-time reduction
G
(also known as Cook reduction) and NP-completeness. He also proved the existence of NP-complete problems,
showing that SAT is NP-complete.
e
• This theorem explores whether optimization problems, whose solutions can be efficiently verified, can also be
solved efficiently.
g
• Cook proposed that some optimization problems (with easily verifiable solutions) cannot be solved by efficient
d
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.
e
• In 1982, Cook received the Turing Award for his groundbreaking contributions to complexity theory.
w l
n o www.knowledgegate.in
at e
Q Let X be a recursive language and Y be a recursively enumerable but not recursive language. Let W and
Z be two languages such that Y reduces to W, and Z reduces to X (reduction means the standard
many-one reduction). Which one of the following statements is TRUE (GATE-2016) (2 Marks)
G
(A) W can be recursively enumerable and Z is recursive.
ge
(B) W can be recursive and Z is recursively enumerable.
d
e
(C) W is not recursively enumerable and Z is recursive.
w l
(D) W is not recursively enumerable and Z is not recursive
n o www.knowledgegate.in
Q Consider the following statements (GATE-2015) (2 Marks)
1. The complement of every Turning decidable language is Turning decidable
at e
e G
2. There exists some language which is in NP but is not Turing decidable
g
d
3. If L is a language in NP, L is Turing decidable
(A) Only 2
w
(B) Only 3
l
Which of the above statements is/are True?
e
n o
(C) Only 1 and 2 (D) Only 1 and 3
www.knowledgegate.in
at e
Q Language L1 is polynomial time reducible to language L2. Language L3 is polynomial time
reducible to L2, which in turn is polynomial time reducible to language L4. Which of the following
is/are True? (GATE-2015) (2 Marks)
G
I. If L4 ∈ P, L2 ∈ P
II. If L1 ∈ P or L3 ∈ P, then L2 ∈ P
dge
IV. If L4 ∈ P, then L1 ∈ P and L3 ∈ P
(A) II only
w
(B) III only
l e
n o
(C) I and IV only (D) I only
www.knowledgegate.in
at e
Q Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time
to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the
following is consistent with the above statement?(CS-2015) (2 Marks)
(A) Q1 is in NP, Q2 is NP hard
ge G
d
(B) Q2 is in NP, Q1 is NP hard
w
(C) Both Q1 and Q2 are in NP
l e
n o
(D) Both Q1 and Q2 are in NP hard
www.knowledgegate.in
Q consider the following two problems of graph. (GATE-2015) (2 Marks)
at e
1) Given a graph, find if the graph has a cycle that visits every vertex exactly once except the first visited vertex which
must be visited again to complete the cycle.
e G
2) Given a graph, find if the graph has a cycle that visits every edge exactly once.
g
e d
Which of the following is true about above two problems.
l
(A) Problem 1 belongs NP Complete set and 2 belongs to P
w
(B) Problem 1 belongs to P set and 2 belongs to NP Complete set
o
(C) Both problems belong to P set
n
(D) Both problems belong to NP complete set
www.knowledgegate.in
at
Q Let A ≤m B denotes that language A is mapping reducible (also known as many-to-one
reducible) to language B. Which one of the following is FALSE? (GATE-2014) (2 Marks)
(A) If A ≤m B and B is recursive then A is recursive. e
e G
(B) If A ≤m B and A is undecidable then B is undecidable.
g
e d
(C) If A ≤m B and B is recursively enumerable then A is recursively enumerable.
l
w
(D) If A ≤m B and B is not recursively enumerable then A is not recursively enumerable.
n o www.knowledgegate.in
Q (GATE-2014) (2 Marks)
at e
ge G
(A) solvable in polynomial time by reduction to directed graph reachability
l e d
(B) solvable in constant time since any input instance is satisfiable
w
(C) solvable in constant time since any input instance is satisfiable.
n o
(D) NP-hard, but not NP-complete
www.knowledgegate.in
t e
Q Assuming P ≠ NP, which of the following is TRUE? (GATE-2012) (1 Marks)
a) NP-complete = NP
a
b) NP-complete ∩ P = ∅
ge G
c) NP-hard = NP
l e d
ow
d) P = NP-complete
n www.knowledgegate.in
at e
Q Suppose a polynomial time algorithm is discovered that correctly computes the largest clique
in a given graph. In this scenario, which one of the following represents the correct Venn diagram
of the complexity classes P, NP and NP Complete (NPC)? (GATE-2012) (1 Marks)
ge G
l e d
n ow
www.knowledgegate.in
following is TRUE? (GATE-2009) (1 Marks)
a) There is no polynomial time algorithm for πA
at e
Q Let πA be a problem that belongs to the class NP. Then which one of the
ge G
b) If πA can be solved deterministically in polynomial time, then P = NP
l e d
c) If πA is NP-hard, then it is NP-complete
ow
d) πA may be undecidable
n www.knowledgegate.in
Which of the following is TRUE? (GATE – 2008) (2 Marks)
a) IF X can be solved in polynomial, time then so can Y
at e
Q For problem X and Y, Y is NP – complete and X reduces to Y in polynomial time.
b) X is NP – complete
ge G
c) X is NP – hard
l e d
ow
d) X is in NP – but not necessarily NP – complete
n www.knowledgegate.in
at e
Q The subset-sum problem is defined as follows: Given a set S of n positive integers and a
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?
G
(GATE-2008) (2 Marks)
e
a) Q solves the subset-sum problem in polynomial time when the input is encoded in unary
dg
b) Q solves the subset-sum problem in polynomial time when the input is encoded in binary
e
l
c) The subset sum problem belongs to the class NP
w
n o
d) The subset sum problem is NP-hard
www.knowledgegate.in
Q A problem in NP is NP – complete if [GATE - 2006] (2 Marks)
a) It can be reduced to the 3 – SAT problem polynomial time
at e
e G
b) The 3-SAT problems can be reduced to it in polynomial time
g
l e d
c) It can reduce to any other problem in NP in polynomial time
ow
d) Some problem in NP can be reduced to it in polynomial time
n www.knowledgegate.in
at e
Q. Let SHAM3 be the problem of finding a Hamiltonian cycle in graph G = (V,E) with |V|
divisible 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)
ge G
d
b) SHAM3 is NP-Hard but DHAM3 is not
c) DHAM3 is NP-Hard ut SHAM3 is not
l e
d) Neither DHAM3 nor SHAM3 is NP - Hard
w
n o www.knowledgegate.in
at e
Q Let S be an NP – complete problem Q and R be two other problems not known to
be in NP. Q is polynomial – time reducible to S and S is polynomial – time reducible
to R. Which one of the following statements is true? (GATE-2006) (2 Marks)
a) R is NP – complete
ge G
d
b) R is NP – hard
w
c) Q is NP – complete
l e
n o
d) Q is NP- hard
www.knowledgegate.in
at e
Q Consider three decision problems P1, P2 and P3. It is known that P1 is decidable
and P2 is undecidable. Which one of the following is TRUE? (GATE-2005) (2 Marks)
(A) P3 is decidable if P1 is reducible to P3
ge G
(B) P3 is undecidable if P3 is reducible to P2
l e d
(C) P3 is undecidable if P2 is reducible to P3
ow
(D) P3 is decidable if P3 is reducible to P2’s complement
n www.knowledgegate.in
α : Given G(V,E) does G have an independent set of size |V| - 4?
β : Given G(V,E) does G have an independent set of size 5?
at e
Q. Consider the following two problems on undirected graphs: (GATE 2005, 1 Marks)
ge G
d
b) α is NP Complete and β is in P
c) Both α and β are NP - Complete
d) Both α and β are in P
w l e
n o www.knowledgegate.in
at e
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
from Π to 3-SAT. Which of the following can be inferred from these reductions? (GATE-2003) (2 Marks)
G
(A) Π is NP-hard but not NP-complete
dge
w
(C) Π is NP-complete
l e
n o
(D) Π is neither NP-hard, nor in NP
www.knowledgegate.in