Toc Notes Lyst1730367817560
Toc Notes Lyst1730367817560
www.knowledgegate.in
www.knowledgegate.in
INTRODUCTION TO THEORY OF COMPUTATIONS
• Theory of Computation (TOC) is a branch of theoretical computer science that addresses:
• What can be computed, How efficiently can it be computed, What limitations exist in computation?
• It involves the study of abstract machines, also known as automata, and mathematical models that define what
problems can be solved using these machines.
• TOC focuses on different computational models, their capabilities, and the complexity of solving problems. The
main areas it deals with include:
• Automata Theory: Studies different types of automata (e.g., finite automata, pushdown automata) and their
abilities to solve problems.
• Formal Languages: Explores the classification of languages and grammars that machines can recognize.
• Computability Theory: Investigates which problems can or cannot be solved by any computational model.
• Complexity Theory: Considers the resources (time, space) needed to solve problems and categorizes them
based on difficulty (e.g., P, NP).
www.knowledgegate.in
www.knowledgegate.in
PROBLEM
• Machine Communication:
• Machines play a crucial role in human development, and we need a language to communicate with them.
However, this language need not be as complex as natural languages.
• Formal vs. Informal Languages:
• Machines use formal languages, which are structured and concise, unlike informal languages used in daily
human interaction.
• Language Definition:
• A language is "a system suitable for expressing ideas, facts, or concepts" using a set of symbols.
www.knowledgegate.in
www.knowledgegate.in
METHODS TO DEFINE LANGUAGE
• In natural language, we can list a finite and predefined set of words in a dictionary, but the
sentences formed using these words are infinite. To determine which sentences are valid or
invalid, we use grammar or rules as a mechanism.
www.knowledgegate.in
www.knowledgegate.in
MATHEMATICL DEFINATION OF LANGUAGE
• SYMBOL- Symbols are the basic building blocks, which can be any character/token. (cow,
sheep, , white flag, , , etc.) (in English we called them as letters).
• ALPHABET- An alphabet is a finite non empty set of symbols, (every language has its own alphabet). here in toc,
we use symbol Σ for depicting alphabet. e.g. Σ = {0,1}. for English Σ = {a, b, c, …., z} (in English also alphabet is a
set of letters, thought in general we called them as alphabet).
• STRING - It is a finite sequence of symbols (which are the member of set alphabet). E.g. Σ = {a, b} String- aabb,
aa, b, so on. (in English we called them as words).
• LANGUAGE - A language is defined as a set of strings. In the next level we consider programs as a string and
programming constructs/tokens like int, floats as letters/symbols.
www.knowledgegate.in
www.knowledgegate.in
• Similarly, in our system we have finite number of symbols/letters but using those letters we can
generate infinite strings/words.
• So, we may have languages that have infinite number of words, so it is not possible for us to list them,
we have to use some framework, which can somehow represent the same language. There are mainly
two methods to represent a language
• by a grammar that generates a language [RG generate RL]
• by a machine that accepts a language [FA accept RL language]
Machine Grammar
www.knowledgegate.in
www.knowledgegate.in
SOME BASIC OPERATIONS ON STRINGS
• So, before we proceed further let’s do a little home work on string, which will help us
throughout the subject.
• Length of a string - It is defined as number symbol in the string. Denoted like |W|, e.g. length
of string |00110| = 5.
• |aaba| =
• |010| =
www.knowledgegate.in
www.knowledgegate.in
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 =
xw =
w = w1 w2 w3… … wm x = x1 x2 x3… … xn
wx =
www.knowledgegate.in
Reverse of a string – If there is a string w then reverse of a string a denoted by
wr it is just the same string but written in reverse order.
W = w 1 w2 w3 … … wn
wr =
|w| |wr|
www.knowledgegate.in
www.knowledgegate.in
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
w2 = ww
w1 = w
w0 =
w∈ = ∈w =
www.knowledgegate.in
www.knowledgegate.in
Substring- Any string of consecutive symbols in some string ‘w’ can be collectively
said as a substring. E.g. w= abab its substrings can be ab, a, ba…etc.
S u b s t r i n g
1. utg
2. sbr
3. rts
4. str
5. sub
6. ∈
www.knowledgegate.in
www.knowledgegate.in
Q Consider a sting ‘GATE’ find the total number of substring possible?
Substring of length Substring of length Substring of length Substring of
Substring of length 0
1 2 3 length 4
Number of sting
1 4 3 2 1
possible
SUBSTRINGS
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
www.knowledgegate.in
Q Consider a sting ‘GATE’ find the total number of prefix and suffix possible?
Prefix(GATE) =
Suffix(GATE) =
www.knowledgegate.in
∑0 =
∑1 =
∑2 =
∑3 =
• ∑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
www.knowledgegate.in
Kleene closure- If ∑ is a set of symbols, then we use ∑* to denote the set of strings obtained by
concatenating zero or more symbols from ∑ of any length, in general any string of any length
which can have only symbols specified in ∑.
• ∑* = ∞=𝑖ڂ
𝑖=0 𝑤 𝑤 = 𝑖} (using the symbols from the alphabet ∑)
Positive closure – If ∑ is a set of symbols, then we use ∑ + to denote the set of strings obtained by
concatenating one or more symbols from ∑ of any length, in general any string of any length
which can have only symbols specified in ∑ (except ∈).
• ∑+ = ∞=𝑖ڂ𝑖=1 𝑤 𝑤 = 𝑖} (using the symbols from the alphabet ∑)
www.knowledgegate.in
www.knowledgegate.in
LANGUAGES
• 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 ∑*
• Lc =
• The reverse of a language is the set of all the strings after reversal
Lr =
• The concatenation of two languages L1 and L2 is the set of all the strings obtained by concatenating any elements
of L1 and L2.
• L1L2 =
• L* =
www.knowledgegate.in
www.knowledgegate.in
Q Given the language L = {ab, aa, baa}, which of the following strings are in L*? (GATE-2012) (1
Marks)
1) abaabaaabaa
2) aaaabaaaa
3) baaaaabaaaab
4) baaaaabaa
(A) 1, 2 and 3
(B) 2, 3 and 4
(C) 1, 2 and 4
(D) 1, 3 and 4
www.knowledgegate.in
www.knowledgegate.in
Q In a string of length n, how many proper prefixes can be generated
a) 2𝑛 b) n c) n (n + 1)/2 d) n – 1
www.knowledgegate.in
www.knowledgegate.in
Q The number of substrings (of all lengths inclusive) that can be formed from a
character string of length n is
2 𝑛(𝑛−1) 𝑛(𝑛+1)
a) n! b) 𝑛 c) -1 d) +1
2 2
www.knowledgegate.in
www.knowledgegate.in
Q Suppose 𝐿1 = {10, 1} and 𝐿2 = {011, 11}. How many elements are there
in L = 𝐿1 𝐿2
a) 4 b) 3 c) 2 d) None of these
www.knowledgegate.in
www.knowledgegate.in
Q Let 𝑥𝑛 denote the number of binary strings of length n that contain no
consecutive 0s, which of the following recurrences does 𝑥𝑛 satisfy?
a) 𝑥𝑛 = 2𝑥𝑛−1 b) 𝑥𝑛 = 𝑥 𝑛 + 1
2
c) 𝑥𝑛 = 𝑥 𝑛 + n d) 𝑥𝑛 = 𝑥𝑛−1 + 𝑥𝑛−2
2
www.knowledgegate.in
Automaton
• 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
refers to a machine that follows predefined rules to execute complex tasks autonomously.
Examples include automatic machine tools, packing machines, and photo printing devices.
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts a language ‘L’, where L={a}
over the alphabet ∑={a}.
www.knowledgegate.in
www.knowledgegate.in
FINITE AUTOMATA
• A finite automaton is a computational model with a limited set of states, where control shifts
between states based on external inputs. It is commonly used as an abstract machine in
computer science for recognizing patterns in symbol strings. Finite automata have applications
in pattern matching, lexical analysis, parsing, and more. Finite automata can be broadly
classified into two types-
1. Finite automata without output
1. Deterministic finite automata.
2. Non deterministic finite automata.
3. Non deterministic finite automata with ∈
www.knowledgegate.in
www.knowledgegate.in
• 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
the amount of information to be stored is strictly bounded.
www.knowledgegate.in
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
• is a finite non-empty set of finite input alphabet
• is a transition function, ( : Q × → Q)
• S is initial state (always one) (S Q)
• F is a set of final states (F Q) (0<=|F|<=N, where n is the number of states)
www.knowledgegate.in
www.knowledgegate.in
A deterministic finite automaton (DFA) operates through
various components:
• Input Tape: Divided into squares, each containing a
symbol from the input alphabet. It has end markers
(¢ at the left and $ at the right) or can be infinite. The
input string lies between these markers.
• Reading Head: This head reads one square at a time
and moves to the right.
• Finite Control: Acts as the inference engine and
manages transitions between states.
• A DFA ensures a unique computation for each input
string, making it deterministic. DFAs are commonly
used in tasks like lexical analysis (spell checking) in
compiler design.
www.knowledgegate.in
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
state has an arrow pointing to it, and the final state is represented by two a b
concentric circles. q0
Q
q1
TRANSITION TABLE- A two-dimensional table where rows represent states, and
columns represent input symbols. The table shows how the machine transitions
between states based on inputs.
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.
www.knowledgegate.in
www.knowledgegate.in
ACCEPTANCE BY DFA
• Let ‘w’ be any string designed from the alphabet , corresponding to w, if there
exist a transition for which it starts at the initial state and ends in any One of the
final states, then the string ‘w’ is said to be accepted by the finite automata. δ *
(q0, w) = qf for some qf ∈ F.
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following table of an FA
IF the final state is 𝑞4 , the which of the following strings will be accepted?
1. aaaaa
2. aabbaabbbbb
3. bbabababbb
a) 1 and 2
b) 2 and 3
c) 3 and 1
d) all of the above
www.knowledgegate.in
www.knowledgegate.in
Q In the automaton below, s is the start state and t are the only final state. (GATE-2006) (2
Marks)
languages. www.knowledgegate.in
Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, where every accepted string ‘w’ starts with substring s
i) s = b
ii) s = ab
iii) s = abb
www.knowledgegate.in
www.knowledgegate.in
Conclusion
www.knowledgegate.in
www.knowledgegate.in
Q design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ ends with substring ‘s’.
i) s = ab
ii) s = aa
iii) s = bab
www.knowledgegate.in
www.knowledgegate.in
Conclusion
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following language:
L = { w∈{0,1}∗ ∣ w ends with the substring 011 }
Which one of the following deterministic finite automata accepts L? (GATE 2021) (2 MARKS)
(A)
(B)
(C)
(D)
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s.
i) abb
ii) aba
www.knowledgegate.in
www.knowledgegate.in
Conclusion
www.knowledgegate.in
www.knowledgegate.in
Q No of states in a minimal dfa that accepts all the strings of a, b such
that every string must have ‘aabab’ as sub string
a) 5 b) 6 c) 7 d) none
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following Deterministic Finite Automata (GATE-2015) (2 Marks)
Which of the following is true?
b) End with 0
c) End with 00
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following machine M
What is the language L(M) accepted by this machine?
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with a.
www.knowledgegate.in
www.knowledgegate.in
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.
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with different symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XSX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Consider the machine M shown below L(M)?
www.knowledgegate.in
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 d) 3
www.knowledgegate.in
www.knowledgegate.in
Consider the transition diagram of an DFA as given below:
Q Which should be the final state(s) of the DFA if it should accept strings starting with ‘a’ and ending with ‘b’?
a) 𝑞0 b) 𝑞1 c) 𝑞0 , 𝑞1 d) 𝑞3
Q Which of the following strings will be accepted if 𝑞0 and 𝑞1 are accepting states?
1. ababab 2. Babaaa 3. aaaba
a) 1,2 b) 2,3 c) 1,3 d) None of these
Q Which of the following represents the set of accepting states if the language to be accepted contains strings
having the same starting and ending symbols?
a) {𝑞0 } b) {𝑞0 , 𝑞3 } c) {𝑞3 } d) {𝑞3 , 𝑞1 }
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ accepted must be like
i) |w| = 3
ii) |w|<=3
iii) |w|>=3
www.knowledgegate.in
www.knowledgegate.in
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.
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
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
www.knowledgegate.in
www.knowledgegate.in
Q The minimum possible number of states of a deterministic finite automaton that
accepts a regular language L is_______(GATE-2017) (2 Marks)
L = {w1aw2 | w1, w2 ∈ {a, b}*, |w1| = 2, |w2|>=3}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the machine M (GATE-2005) (2 Marks)
The language recognized by M is :
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string ‘w’ accepted must be like
i) |w| = 0(mod 3) ii) |w|=1(mod 4)
www.knowledgegate.in
www.knowledgegate.in
Conclusion
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string accepted must contain
i) number of a is, |w|a = 0(mod 2) ii) number of b is, |w|b = 1(mod 2)
www.knowledgegate.in
www.knowledgegate.in
Q How many minimum states are required in a DFA to find whether a given binary string
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
www.knowledgegate.in
www.knowledgegate.in
Q The smallest finite automation which accepts the language {x | length of x is
divisible by 3} has (GATE-2002) (2 Marks)
(A) 2 states (B) 3 states (C) 4 states (D) 5 states
www.knowledgegate.in
www.knowledgegate.in
Q Let ∑ = {0, 1}, then an automaton A accepting only those words from ∑ having an
odd number of 1’s requires _________ states including the start state
a) 2 b) 3 c) 4 d) 5
www.knowledgegate.in
www.knowledgegate.in
Q The smallest finite automaton which accepts the language {x length of x is
divisible by 500} has
a) 200 states b) 300 states c) 400 states d) 500 states
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string accepted must contain odd occurrence of the substring ‘ab’.
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string accepted must contain even occurrence of the substring ‘baa’.
www.knowledgegate.in
www.knowledgegate.in
Q how many DFA can be designed, with a fixed initial state, over an
alphabet ∑ = {a, b}, and the number of states be two.
www.knowledgegate.in
www.knowledgegate.in
• If no of states is |Q| = n, and no of input alphabet |∑| = m
• Then no of states will bewww.knowledgegate.in
www.knowledgegate.in
nn*m * 2n
Q how many DFA can be constructed over the alphabet, such that no of states |Q|
= 2 and size of input alphabet is |∑| = 2, that accepts empty language(Φ)?
www.knowledgegate.in
www.knowledgegate.in
Q how many DFA can be constructed over the alphabet, such that no of states |Q|
= 2 and size of input alphabet is |∑| = 2, that accepts universal language (∑ *)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 2nd from left end is always b.
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 4th from left end is always a.
• No of states will be
www.knowledgegate.in
n+2, if position is n
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 2nd from right end is always b.
www.knowledgegate.in
www.knowledgegate.in
Q The no of final states in a minimal DFA, that accept all string over a, b
such that 4nd symbol from right end is always b.
a) 2 b) 4 c) 8 d) none
www.knowledgegate.in
www.knowledgegate.in
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)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b}, such that
every string ‘w’ which is accepted starts with ‘abbb’ & length is divisible by 3(mod 15)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain be like,
no of a = 0(mod 2) || no of b = 0(mod 2) ?
cross product method(one more approach , where concentrate on even and odd logic)
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain be like, no of a = 0(mod
2) && no of b = 0(mod 2)?
www.knowledgegate.in
www.knowledgegate.in
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)?
• if, n(mod m) && p(mod r), then the no of states will be m*r, if m & r are
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
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 (D) 48
www.knowledgegate.in
www.knowledgegate.in
Q The following finite state machine accepts all those binary strings in which the
number of l’s and 0’s is respectively. (GATE-2004) (2 Marks)
(A) divisible by 3 and 2
www.knowledgegate.in
Q Consider the following DFA in which 𝑠0 is the start and 𝑠1 , 𝑠3 are the final sates. What language
does this DFA recognize? (GATE-2007) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
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)
www.knowledgegate.in
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
equivalent
i) 0(mod 3)
ii) 2(mod 4)
iii) 0(mod 5)
iv) 2(mod 6)
v) 3(mod 8)
on a format of m (mod n)
1) if n is odd, number of states will be n
2) if n is even and n=2m, then number of states will be m+1
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
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}
(B) L ∪ {01}
(C) {0,1}* – L
(D) L⋅L
www.knowledgegate.in
www.knowledgegate.in
COMPLIMENT OF DFA
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must not contain a substring aaa?
www.knowledgegate.in
www.knowledgegate.in
Note
• The finite automata which is obtained by interchanging final & non-final states is known as
complement of the finite automata.
• No of final states in a FA and it’s Complement FA may have different final states
www.knowledgegate.in
www.knowledgegate.in
Q Deterministic automata of a language over alphabets {0, 1}, which does not
contain 3 consecutive 0’s. Minimum how many states ‘S’ DFA will have and how
many of them will final states, F?
a) ISI = 5 and IFI = 1 b) ISI = 5 and IFI = 4
c) ISI = 4 and IFI = 1 d) ISI = 4 and IFI = 3
www.knowledgegate.in
www.knowledgegate.in
Q construct the DFA for the following languages:
i) L= {am bn | m, n >= 0} ii) L = {am bn cp | m, n, p >= 0}
www.knowledgegate.in
(B) 1
(C) 2
(D) 3
www.knowledgegate.in
www.knowledgegate.in
Q The FSM over an alphabet {a, b} shown in the figure accepts
www.knowledgegate.in
www.knowledgegate.in
Q Definition of a language L with alphabet {a} is given as following.
L = {ank| k>0, and n is a positive integer constant}
What is the minimum number of states needed in DFA to recognize L? (NET-DEC-
2018) (2 Marks) (GATE-2011)
(A) k+1 (B) n+1 (C) 2(n+1) (D) 2(k+1)
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following set can be recognized by a deterministic Finite state
Automation? (GATE–1998) (2 Marks)
a) The numbers 1,2,4, 2𝑛 , written in unary
b) The set of binary string in which the number of zeroes is the same as the
number of ones.
www.knowledgegate.in
www.knowledgegate.in
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
is shown below. (GATE-2012) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
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)
(A) 1 (B) 5 (C) 7 (D) 8
www.knowledgegate.in
www.knowledgegate.in
MINIMIZATION OF FINITE AUTOMATA
• The process of removing states that do not affect the language-accepting capability of a deterministic finite
automaton (DFA). The result is a minimal deterministic finite automaton (MFA), which is unique for a given
language.
• Designing a minimal DFA directly can be difficult, so the recommended approach is to first design a DFA and then
minimize it.
• States in DFA can be classified as:
• Productive States: These states contribute to the machine’s ability to accept a language. Their presence
affects the language-accepting power.
• Non-Productive States: These states do not add any value to the language-accepting capability of the
machine and can be removed during minimization.
• NOTE- MFA is always unique for a language.
www.knowledgegate.in
www.knowledgegate.in
• 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
• 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
dead state is sufficient to complete the functionality.
• Unreachable Sate- It is that state which cannot be reached starting from initial state by parsing any input string.
www.knowledgegate.in
www.knowledgegate.in
• 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).
• More formally, two states ql and q2 are equivalent (denoted by q1≅ q2) if both δ (q1, x) and δ
(q2, x) are final states or both of them are non-final states for all x ∈ ∑*. If q1 and q2 are k-
equivalent for all k ≥ 0, then they are k-equivalent.
www.knowledgegate.in
www.knowledgegate.in
Procedure of Minimization
• For this first of all, group all the non-final states in one set and all final states in another set.
• Now, on both the sets, individually check, whether any of the underlying elements (states) of
that particular set are behaving in the same way, that is are they having same transition(to
same set) on each input alphabet.
• if the answer is yes, then these two states are equal, otherwise not.
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q IF a DFA is represented by the following transition table, then how
many states does the corresponding minimal DFA contains?
a) 2
b) 3
c) 4
d) 5
www.knowledgegate.in
www.knowledgegate.in
Q Find weather the Conversion of the DFA below to MDFA is correct or not?
www.knowledgegate.in
www.knowledgegate.in
Q A deterministic finite automation (DFA)D with alphabet {a, b} is given below (GATE-2011) (2
Marks)
Which of the following finite state machines is a valid minimal DFA which accepts the same
language as D?
www.knowledgegate.in
www.knowledgegate.in
NON DETEMINISTIC FINITE AUTOMATA
• Non-determinism in finite automata means that an automaton has multiple possible moves in
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:
• Choice of Moves: At any given step, the automaton can choose from multiple transitions
for the same input.
• Theoretical Concept: Non-deterministic machines are theoretical models, not meant to be
physically implemented. They help simplify the design process but are not directly used in
practice.
• Purpose: NFAs are easier to design compared to deterministic automata (DFA), and every
NFA can be converted into an equivalent DFA for practical applications.
www.knowledgegate.in
www.knowledgegate.in
FORMAL DESCRIPTION OF NDFA
• A Non-Deterministic finite automaton (NDFA) is a 5-tuple (Q,,,S,F) where:
• Q is a finite and non-empty set of states
www.knowledgegate.in
www.knowledgegate.in
Some points to remember
• 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=
Accepting power of DFA.
• 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.
• NDFA is a theoretical engine and is not implementable, but it is very easy to design compare
to DFA. No concept of dead state, therefore complementation of NFA is also not possible.
NDFA will respond for only valid strings and no need to respond for invalid strings. (it is a
Incomplete system)
www.knowledgegate.in
www.knowledgegate.in
ACCEPTANCE BY NDFA
• Let ‘w’ be any string defined over the alphabet , corresponding to w, there can be multiple
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
accepted by the non-deterministic finite automata, otherwise not.
www.knowledgegate.in
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
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with same symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with different symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=SX , Where s = aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=XS , Where s = aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=XSX , Where s =
aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a NFA that accepts all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ accepted must be like
i) |w| = 3
ii) |w|<=3
iii) |w|>=3
www.knowledgegate.in
www.knowledgegate.in
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain exactly two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at least two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a NFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at most two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
such that for every accepted string 3rd from right end is always a.
www.knowledgegate.in
www.knowledgegate.in
Q The FSM shown in the figure accepts
a) all strings
b) no strings
c) ϵ - alone
d) None of these
www.knowledgegate.in
www.knowledgegate.in
Q (GATE-2014) (2 Marks)
(D) {q3}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following two finite automata. 𝑀1 accepts 𝐿1 and 𝑀2
accepts 𝐿2 Which one of the following is TRUE? (GATE-2008) (2 Marks)
a) 𝐿1 = 𝐿2
b) 𝐿1 ⊂ 𝐿2
c) 𝐿1 ∩ 𝐿2 = ф
d) 𝐿1 ∪ 𝐿2 ≠ 𝐿1
www.knowledgegate.in
www.knowledgegate.in
Q Consider the non-deterministic finite automaton (NFA) shown in the figure.
(GATE-2005) (2 Marks)
State X is the starting state of the automaton. Let the language accepted by the
NFA with Y as the only accepting state be L1. Similarly, let the language accepted by
the NFA with Z as the only accepting state be L2. Which of the following statements
about L1 and L2 is TRUE?
(A) L1 = L2 (B) L1 ⊂ L2 (C) L2 ⊂ L1 (D) None of the above
www.knowledgegate.in
www.knowledgegate.in
Q Consider the NFAM shown below. (GATE–2003) (2 Marks)
Let the language accepted by M be L. Let 𝐿1 be the language accepted by the NFA
𝑀1 , obtained by changing the accepting state and by changing the non – accepting
state of M to accepting states. Which of the following statements is True?
a) 𝐿1 = {0, 1} * - L b) 𝐿1 = {0, 1} * c) 𝐿1 ⊂ L d) 𝐿1 = L
www.knowledgegate.in
www.knowledgegate.in
NFA and DFA Equivalence
• 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
every NFA and DFA has equal power that means, for every language if a NFA is possible, then
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.
• If NFA have ‘n’ states which is converted into DFA which ‘m’ states than the relationship
between n and m will be 1<= m <= 2n
www.knowledgegate.in
www.knowledgegate.in
Q Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language.
Which of the following in NECESSARILY true? (GATE-2008) (2 Marks)
(A) m ≤ 2n (B) n ≤ m
(C) M has one accept state (D) m = 2n
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)
(A) N2 (B) 2N (C) 2N (D) N!
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)
a) k ≥ 2n b) k ≥ n c) k ≤ n2 d) k ≤ 2n
www.knowledgegate.in
www.knowledgegate.in
Procedure for Conversion
• There lies a fixed algorithm for the NFA and DFA conversion. Following things must be
considered
• Initial state will always remain same.
• Start the construction of ’ with the initial state & continue for every new state that comes
under the input column and terminate the process whenever no new state appears under
the input column.
• Every subset of states that contain the final state of the NFA is a final state in the resulting
DFA.
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
NFA WITH EPSILON MOVES (€-NFA)
• 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:
• Q is a finite and non-empty set of states
www.knowledgegate.in
www.knowledgegate.in
NULL-CLOSURE
• 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.
• €-Closure(qi)- The set of all the states which are at zero distance from the state q i is called €-
closure(qi). Or the set of all the states that can be reached from the state qi along € labelled
transition path, is known as €-closure(qi).
www.knowledgegate.in
www.knowledgegate.in
• Every state is at zero distance to itself.
• In NFA or DFA, distance between two states is always 1, because there could be no null
transitions.
• The Null closure Q is always a non-empty and finite state, because every state’s null closure is
that state only.
• €-closure(Φ) = Φ
• 𝑖=0 ( €-closure(qi))
€-closure (q0 , q1, q2 , q3--------, qn) =𝑛=𝑖ڂ
www.knowledgegate.in
www.knowledgegate.in
EQUIVALENCE BETWEEN NULL NFA TO NFA
• There will be no change in the initial state.
• No change in the total no. of states
• 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
contains at least one final state in the initial €-NFA.
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q if the given NFA is converted to NFA without ϵ - moves, which of the following denotes
the set of final states?
a) {𝑞2 } b) {𝑞1 , 𝑞2 } c) {𝑞0, 𝑞1, 𝑞2} d) can’t be determined
Q Which of the following strings will not be accepted by the given NFA?
a) 00 11 22 b) 11 22 c) 21 d) 22
www.knowledgegate.in
www.knowledgegate.in
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} c) {q0, q1, q2} d) {q0, q2, q3}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages and find which of them are regular?
1. L = {am bn | m, n >=0}
2. L = {am bn cp | m, n, p >= 0}
www.knowledgegate.in
www.knowledgegate.in
1. L = {am bn | m*n = finite}
www.knowledgegate.in
www.knowledgegate.in
1. L = {am bn | m = n | m, n> = 0}
3. L = {am bn | m != n | m, n > 0}
4. L = {am bn | m is divisible by n}
www.knowledgegate.in
1. L = {am bn | m + n = even}
2. L = {am bn cp | m = n = p}
3. L = {am bn cp | m + p = n}
4. L = {am bn | m + n = odd}
www.knowledgegate.in
www.knowledgegate.in
1. L = {w c wr | w Σ*}
2. L = {w c w | w Σ *}
3. L = {w c wr | w Σ +}
4. L= {w c w | w Σ +}
5. L = {w w | w Σ *}
6. L= {w wr | w Σ +}
www.knowledgegate.in
www.knowledgegate.in
1. L = {w c wr | c, w Σ *}
2. L = {c w wr | c, w Σ *}
3. L= {w wr c | c, w Σ *}
4. L = {w c wr | c, w Σ +
5. L = {c w wr | c, w Σ +}
6. L= {w wr c | c, w Σ +}
www.knowledgegate.in
www.knowledgegate.in
1. L = {w c w | c, w Σ *}
2. L = {c w w | c, w Σ *}
3. L= {w w c | c, w Σ *}
4. L = {w c w | c, w Σ +}
5. L = {c w w | c, w Σ +}
6. L= {w w c | c, w Σ +}
www.knowledgegate.in
www.knowledgegate.in
Q If L is a regular language over ∑ = {a, b}, which one of the following languages is NOT regular?
(GATE-2019) (2 Marks)
a) L⋅ LR = {xy | x ∈ L, yR ∈ L}
d) {w wR | w ∈ L}
www.knowledgegate.in
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}
L3: {ap bq cr ⎪ p, q, r ≥ 0}
www.knowledgegate.in
www.knowledgegate.in
Q Let L1 = {w ∈ {0, 1}∗ | w has at least as many occurrences of (110) ’s as (011)’s}.
www.knowledgegate.in
www.knowledgegate.in
GATECS2014Q15
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following is TRUE? (GATE-2014) (1 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Let P be a regular language and Q be context-free language such that Q P. (For
example, let P be the language represented by the regular expression p*q* and Q
be {pnqn |n N}). Then which of the following is ALWAYS regular? (GATE-2011) (1
Marks)
(A) P ⋂ Q (B) P - Q (C) *- P (D) * - Q
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following are regular sets? (GATE-2008) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following languages is (are) non-regular? (GATE-2008) (2 Marks)
L1 = {0m1n | 0 ≤ m ≤ n ≤ 10000}
www.knowledgegate.in
Q Which of the following languages is regular? (GATE-2007) (2 Marks)
a) {w wR |w ∈ {0, 1}+} b) {w wR x| x, w ∈ {0,1}+}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following two statements (GATE-2001) (2 Marks)
GATECS2000Q4
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages (GATE-2001) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Regular Expressions
• One way of describing regular language is via the notation of regular expression. An expression of
strings which represents regular language is called regular expression.
• The regular expressions are useful for representing certain sets of strings(Language) in an
algebraic fashion.
www.knowledgegate.in
www.knowledgegate.in
Regular Language:- Any set(language) represented by a regular expression is called a Regular
language. If for example, a, b ∈ ∑, then
• R = a denotes the L = {a}
• R = a* denotes the set {∈, a, aa, aaa, ...} known as Kleene closure.
www.knowledgegate.in
www.knowledgegate.in
Operators
When we view a in ∑ as a regular expression, we denote it by a.
• The iteration (or closure) of a regular expression R written as R*, is also a regular expression.
• 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
expression.
• The union of two regular expressions R1 and R2, written as R1 + R2, is also a regular expression.
www.knowledgegate.in
www.knowledgegate.in
IDENTITIES FOR Regular Expression
• Two regular expression are said to be equal if they generate same language.
• r1 = a*
• r2 = a* + (aa)*
www.knowledgegate.in
www.knowledgegate.in
हमारी language बताओ
• R={a}
• R={a + b}
• R={a + b + c}
• R={a.b}
• R={a.b + a}b
www.knowledgegate.in
www.knowledgegate.in
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
(B) T ⊂ S
(C) S = T
(D) S ∩ T = φ
www.knowledgegate.in
www.knowledgegate.in
FINITE AUTOMATA AND regular expression
www.knowledgegate.in
www.knowledgegate.in
Q design a regular expression that represent all strings over the alphabet
∑ = {a, b}, where every accepted string ‘w’ starts with substring s
i) s = b ii) s = ab iii) s = abb
www.knowledgegate.in
www.knowledgegate.in
Q design a regular expression that represent all strings over the alphabet
∑ = {a, b}. where every accepted string ‘w’ ends with substring ‘s’.
i) s = ab ii) s = aa iii) s = bab
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}. where every accepted string ‘w’ contains sub string
s.
i) abb ii) aba
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with a.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with
same symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with
different symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=SX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=XSX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the alphabet ∑ = {a, b},
such that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string accepted must contain exactly
two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string accepted must contain at least
two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string accepted must contain at most
two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that for every accepted string 2nd from left end is
always b.
www.knowledgegate.in
www.knowledgegate.in
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.
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 0(mod 3)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 3(mod 4)?
www.knowledgegate.in
www.knowledgegate.in
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)?
www.knowledgegate.in
www.knowledgegate.in
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)?
www.knowledgegate.in
www.knowledgegate.in
Q L = {am bn | m, n >= 0}
www.knowledgegate.in
www.knowledgegate.in
Q L = {am bn cp | m, n, p >= 1}
Q L = {an bn | n >= 1}
www.knowledgegate.in
www.knowledgegate.in
Q Write a regular expression for the language, L = {w c wr |w, c ∈ {a, b}+}
www.knowledgegate.in
www.knowledgegate.in
Q L = {am bn | m + n = even}
www.knowledgegate.in
www.knowledgegate.in
Algebraic Properties of regular expression
Closure Property - regular expressions satisfy closure property with respect to Union,
Concatenation and kleene closure. If R1 and R2 are regular expression then the following will also
be regular expression.
r1 + r2
r1.r2
r1*
r1+
www.knowledgegate.in
www.knowledgegate.in
Associative Property- regular expression satisfy associative property with respect
to union and intersection
www.knowledgegate.in
www.knowledgegate.in
Identity Property- The identity property is satisfied as follows-
r. = r
r+ = r
www.knowledgegate.in
www.knowledgegate.in
Inverse Property- The inverse property is not satisfied with respect to
concatenation and union.
r . =ε
r + =ϕ
www.knowledgegate.in
www.knowledgegate.in
Commutative Property-regular expressions are commutative with
respect to union but not with respect to concatenation.
r1+ r2 r2+ r1
r1. r2 r2. r1
www.knowledgegate.in
www.knowledgegate.in
Distributive Property-regular expression satisfy this property as follows-
r1(r2+r3) r1r2+r1r3
(r1+r2) r3 r1r3+r2r3
(r1.r2) + r3
www.knowledgegate.in
(r1 +r3). (r2 + r3)
www.knowledgegate.in
Idempotent Property-regular expressions satisfies idempotent property
with respect to union but not with respect to concatenation.
r1+r1 r1
r1. r1 r1
www.knowledgegate.in
www.knowledgegate.in
Identities for regular expressions
1. φ + r =
2. φ. r = r. φ =
3. ∈. r = r. ∈ =
4. ∈ * =
5. ф * =
www.knowledgegate.in
www.knowledgegate.in
1. r*r* =
2. r. r* =
3. r+. r* =
4. r+ r+ =
www.knowledgegate.in
www.knowledgegate.in
1. r + U r* =
2. r+ ⋂ r* =
www.knowledgegate.in
www.knowledgegate.in
1. (r*)* =
2. (r+)*=
3. ((r+)*)* =
4. ((r*)*)r+ =
www.knowledgegate.in
www.knowledgegate.in
1) (r1+r2)* (r1* + r2*)*
www.knowledgegate.in
www.knowledgegate.in
1. (r1+r2)* (r1* . r2*)*
www.knowledgegate.in
www.knowledgegate.in
r1(r2.r1)* (r1.r2)*r1
www.knowledgegate.in
www.knowledgegate.in
1. L(r*) = [L(r)]*
2. L(r+) = [L(r)]+
4. L(r1.r2) = L(r1).L(r2)
5. L((r1)) = L(r1)
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following are equal
a) a* b) (aa)* c) a(aa)* d) (a + ε) a*
www.knowledgegate.in
www.knowledgegate.in
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)*
b) (0+11+10(1+00)*01)*
c) (0*(1(01*0)*1)*)*
d) (0+11+11(1+00)*00)*
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following regular expressions represents the language: the set of all
binary strings having two consecutive 0s and two consecutive 1s? (GATE-2016) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Consider the languages L1 = Φ and L2 = {a}. Which one of the
following represents L1 L2*U L1* (GATE-2013) (1 Marks)?
www.knowledgegate.in
www.knowledgegate.in
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)
(D) The set of all strings that begin and end with either 0 or 1.
www.knowledgegate.in
www.knowledgegate.in
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)
(A) (0 + 1) * 11(0 + 1) * (B) 0 * 110 *
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following regular expressions is NOT equivalent to
the regular expression (a + b + c) *? (GATE-2004) (2 Marks)
(A) (a* + b* + c*)* (B) (a*b*c*)*
www.knowledgegate.in
www.knowledgegate.in
Q The regular expression 0*(10*)* denotes the same set as (GATE-2003)
(1 Marks)
(A) (1*0)*1* (B) 0 + (0 + 10)*
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is correct
a) (xx)*y = x(xy)* b) (xy)*x = x(yx)*
www.knowledgegate.in
www.knowledgegate.in
Q find the no of strings of length <= 3 generated by the (a + ab)+
www.knowledgegate.in
www.knowledgegate.in
Q which of the following statements are correct
a) r*, r+ always represent finite language.
c) r* = r+ if and only if r = ε
d) r* = r+ = r if r = Ф
www.knowledgegate.in
www.knowledgegate.in
EQUIVALENCE BETWEEN Regular Expression AND FINITE AUTOMATA
• ARDEN’S THEOREM is the mechanism for the construction of a regular expression from a
finite automaton.
Q Consider a DFA and convert it into regular expression using Arden’s theorem?
(A, a) = A
(A, b) = B
(B, a) = B
(B, b) = B
A is the initial state and B Is the final state
www.knowledgegate.in
www.knowledgegate.in
Q Consider a DFA and convert it into regular expression using Arden’s theorem?
(A, b) = A
(A, b) = B
(B, a) = C
(C, b) = C
A is the initial state and B,C Is the final state
www.knowledgegate.in
www.knowledgegate.in
• Steps used-
• For, every individual state of the DFA, write an expression for every incoming and outgoing
input alphabet.
• Apply Arden’s theorem as follows-
• 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.
www.knowledgegate.in
www.knowledgegate.in
Conversion from Finite Automata to regular expression
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q Which of the regular expressions given below represent the following
DFA? (GATE-2014) (2 Marks)
I) 0*1(1+00*1)* II) 0*1*1+11*0*1 III) (0+1)*1
www.knowledgegate.in
Q Let L = {w ∈ (0 + 1)* | w has even number of 1s}, i.e. L is the set of all bit strings with even
number of 1s. Which one of the regular expression below represents L? (GATE-2010)(2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q If the final states and non-final states in the DFA below are interchanged, then which of the
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
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following Finite State Automaton. The language accepted by this
automaton is given by the regular expression (GATE-2007) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Consider the automata given in previous question. The minimum state automaton
equivalent to the above FSA has the following number of states (GATE-2007) (1 Marks)
(A) 1 (B) 2 (C) 3 (D) 4
www.knowledgegate.in
www.knowledgegate.in
Q Which regular expression best describes the language accepted by the non-
deterministic automaton below? (GATE-2006) (1 Marks)
(A) (a + b)* a(a + b)b
(B) (abb)*
(D) (a + b)*
www.knowledgegate.in
www.knowledgegate.in
Conversion from regular expression in Finite Automata
i) R*
ii) (R1.R2)*
iii) (R1+R2)*
www.knowledgegate.in
www.knowledgegate.in
iv) (R1*R2.R3*)
v) R = a*b(ab)*
vi) R = (a + ba)*ab*
www.knowledgegate.in
www.knowledgegate.in
vii) R = (aa + aaa)*
viii) R = (a + aaaaa)*
www.knowledgegate.in
www.knowledgegate.in
1. 0 * 10 * 10 *
2. ((ab)* + c*)*
4. 0*(10 * 1*)*0*
www.knowledgegate.in
www.knowledgegate.in
1. a*b(b * + aa*b)*
2. ((11*0+0)(0 + 1)*0*1*)
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following regular expressions correctly represents the language of the finite
automaton given below? (GATE 2022) (1 MARKS)
www.knowledgegate.in
www.knowledgegate.in
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)
www.knowledgegate.in
www.knowledgegate.in
Q The number of states in the minimum sized DFA that accepts the language defined by
the regular expression (0+1)*(0+1)(0+1)* is __________________ (GATE-2016) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
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 (D) 8
www.knowledgegate.in
www.knowledgegate.in
Q The number of states in the minimal deterministic finite automaton corresponding to
the regular expression (0 + 1)*(10) is ____________ (GATE-2015) (1 Marks)
(A) 2 (B) 3 (C) 4 (D) 5
www.knowledgegate.in
www.knowledgegate.in
Q The length of the shortest string NOT in the language (over Σ = {a, b}) of the
following regular expression is ______________. (GATE-2014) (2 Marks)
a*b*(ba)*a*
(A) 2 (B) 3 (C) 4 (D) 5
www.knowledgegate.in
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.
a) 1 and 3 only
b) 2 and 4 only
c) 2 and 3 only
d) 3 and 4 only
www.knowledgegate.in
www.knowledgegate.in
Q Match the following NFAs with the regular expressions they
correspond to (GATE-2008) (2 Marks)
(A) P – 2, Q – 1, R – 3, S – 4
(B) P – 1, Q – 3, R – 2, S – 4
(C) P – 1, Q – 2, R – 3, S – 4
(D) P – 3, Q – 2, R – 1, S – 4
www.knowledgegate.in
www.knowledgegate.in
Q Consider the regular language L = (111 + 11111)*. The minimum
number of states in any DFA accepting this language is: (GATE-2006) (1
Marks)
(A) 3 (B) 5 (C) 8 (D) 9
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements is TRUE about the regular expression 01*0?
(GATE-2005) (1 Marks)
(A) It represents a finite set of finite strings.
www.knowledgegate.in
www.knowledgegate.in
Q the string 1101 does not belong to the set
a) 110*(0+1) b) 1(0+1)*101
www.knowledgegate.in
www.knowledgegate.in
Q which of the following re, over the Σ = {0, 1} denotes the set of all strings that
not contain 100 as sub-string
a) 0*(0+1)* b) 0*1010* c) 0*1*01 d) 0*(10+1)*
www.knowledgegate.in
www.knowledgegate.in
Formal Grammar
Language usually contains infinite number of strings. We cannot tabulate each and every string to
represent the language, therefore like automata, grammar is also a mathematical model of representing a
language, using which we can generate the entire language. Therefore, a grammar is usually thought of as
a language generator. A phrase-structure grammar (or simply a grammar) is a 4-tuple (VN, ∑, P, S), where
• VN is a finite nonempty set whose elements are called variables,
• ∑ is a finite nonempty set whose elements are called terminals, V N ⋂ ∑= Ф.
• S is a special variable (i.e., an element of V N (S Vn)) called the start symbol. Like every automaton has
exactly one initial state, similarly every grammar has exactly one start symbol.
• P is a finite set whose elements are α → β. where α and β are strings on V N ∑ ڂ. α has at least one
symbol from VN, the element of P are called productions or production rules or rewriting rules. {Σ U
Vn}* some writer refers it as total alphabet.
www.knowledgegate.in
www.knowledgegate.in
For a formal valid production
α→β
α {Σ U Vn}* Vn {Σ U Vn}*
β {Σ U Vn}*
www.knowledgegate.in
www.knowledgegate.in
Some points to note about productions
• Reverse substitution is not permitted. For example, if S → AB is a production, then we can replace S by
AB but we cannot replace AB by S.
• No inversion operation is permitted. For example, if S → AB is a production, it is not necessary that AB
→S is a production.
• To generate a string in the language, one begins with a string consisting of only a single start symbol.
The production rules are then applied in any order, until a string that contains neither the start symbol
nor designated nonterminal symbols is produced. A sequence of rule applications is called a derivation.
• A production rule is applied to a string by replacing one occurrence of the production rule’s left-hand
side in the string by that production rule’s right-hand side.
• L (G) is the set of all terminal strings derived from the start symbol S. G 1 and G2 are equivalent if L (G1)
= L (G2).
www.knowledgegate.in
www.knowledgegate.in
Defining a language by grammar
• The concept of defining a language using grammar is, starting from a start symbol using the
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
stages(strings) are called sentential forms. The language formed by the grammar consists of all
distinct strings that can be generated in this manner.
L (G) = {w | w ∑* , S →* W}
• →*(reflexive, transitive closure) means from s we can derive w in zero or more steps
www.knowledgegate.in
www.knowledgegate.in
Chomsky Classification of Languages
• 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
and more restrictions. The more restrictive the grammar, the easier the language will be to process;
the more liberal the grammar, the more complex the language will become.
www.knowledgegate.in
www.knowledgegate.in
LANGUAGES AND AUTOMATA
www.knowledgegate.in
www.knowledgegate.in
Type 0 Grammar
• Also known as Unrestricted Grammar, phase structured grammar, recursively enumerable
grammar used to generate recursive enumerable language which is accepted by a Turing
machine.
• A type 0 grammar is without any restrictions.
• No restriction on the production rule, that is if there is a production from
α→β
α {Σ U Vn}* Vn {Σ U Vn}*
β {Σ U Vn}*
www.knowledgegate.in
www.knowledgegate.in
Type 1 Grammar
• 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 δ {Σ U Vn}+
or
α→β
α {Σ U Vn}* Vn {Σ U Vn}*
β {Σ U Vn}+
|α| <= |β|
www.knowledgegate.in
www.knowledgegate.in
• 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.
• A grammar is called type 1 or context-sensitive or context dependent if all its productions are
type 1 productions.
www.knowledgegate.in
www.knowledgegate.in
Type 2 Grammar
• 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
β {Σ U Vn} *
• In other words, the L.H.S. has no left context or right context.
• A grammar is called a type 2 grammar if it contains only type 2 productions.
• Eg ALGOL 60, PASCAL
www.knowledgegate.in
www.knowledgegate.in
Type 3 Grammar
• Used to generate Regular Grammar which will generate regular language which will be
accepted by finite machine.
• Regular grammar can be of two types either left linear or right linear.
• Left regular grammar, support two types of production
A → a / Ba
A, B Vn |A| = |B| = 1
a ∑*
• Right regular grammar
A → a / aB
A, B Vn |A| = |B| = 1
a ∑*
• however, if left-linear rules and right-linear rules are combined,
the language need no longer be regular.
www.knowledgegate.in
www.knowledgegate.in
Q Consider the grammar
S → aaaS | a | aa
L(G) =?
c) L(G)= L(a*)
www.knowledgegate.in
Q The basic limitation of FSM is that
a) It cannot remember arbitrary large amount of information
d) All of these
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → aAb
A → aB / b
B→c
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → AB / Bb
A→b/c
B→d
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → aSb /
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → aA / abS
A → bS / b
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → aAB
A → aA /
B→b
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → AB
A → aA /
B → bB / b
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar and identify it’s language?
S → aSa / bSb /
www.knowledgegate.in
www.knowledgegate.in
Q If G is a grammar with productions
S → SaS | aSb | bSa | SS | ϵ
where S is the start variable, then which one of the following strings is not
generated by G? (GATE-2017) (1 Marks)
(A) abab
(B) aaab
(C) abba
(D) babba
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following grammar (GATE – 2004) (2 Marks)
S → bS | aA | b
A → bA | aB|
B → bB | aS| a
Let 𝑁𝑎 (w) and 𝑁𝑏 (w) denote the number of a’s and b’s in a string w respectively. The language
L(G)I {a, b}* generated by G is
a) {w | 𝑁𝑎 (w) > 3 𝑁𝑏 (w)}
www.knowledgegate.in
Q Consider the regular grammar: (GATE-2005) (1 Marks)
S → X a | Ya
X → Za
Z → Sa | ϵ
Y → Wa
W → Sa
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
minimum number of states required for the DFA?
a) 2
b) 3
c) 4
d) 5
www.knowledgegate.in
www.knowledgegate.in
Q What is the regular expression for the language generated by
S → aS | bA
A → d | ccA
a) a*bd
b) a* (bd)(bcc)* d
c) a* b(cc)* d
d) None of these
www.knowledgegate.in
www.knowledgegate.in
Q Write the grammar for the regular expression a*b*
a) S → AB, A → aA | bB | ϵ, B → bB |aA | ϵ
b) S→ AB, A → aA | ϵ, B → bB | ϵ
c) S → ab | ϵ, A → aA | ϵ, B → bB | ϵ
d) None of these
www.knowledgegate.in
www.knowledgegate.in
Q α → β and |α| ≤ |β| is a production rule for _________ grammar.
www.knowledgegate.in
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)
P: L1 is regular Q: L2 is regular
Which one of the following is TRUE?
(A) Both P and Q are true
www.knowledgegate.in
www.knowledgegate.in
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)
X0 = 1 X1 X 1 = 0 X 1 + 1 X2 X2 = 0 X1 + {∈}
Which one of the following choices precisely represents the strings in X0?
www.knowledgegate.in
Designing Grammar
Q Design a grammar that generates a language ‘L’, where L={a} over the
alphabet ∑={a}.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, where every accepted string ‘w’ starts with substring s
i) s = b ii) s = ab iii) s = abb
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}.
where every accepted string ‘w’ ends with substring ‘s’.
i) s = ab ii) s = aa iii) s = bab
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s.
i) abb ii) aba
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with a.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with same symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string start and end with different symbol.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=SX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XS.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that every accepted string w, is like w=XSX.
i) s= aa/bb ii) s=aaa/bbb
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain exactly two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at least two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at most two a’s.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a,
b} such that for every accepted string 2nd from left end is always b.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b} such that
for every accepted string 4th from right end is always a.
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 0(mod 3)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 3(mod 4)?
www.knowledgegate.in
www.knowledgegate.in
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W|a = 0(mod 3)?
www.knowledgegate.in
www.knowledgegate.in
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 → Aα / β
A → Aα / β1 / β2
A → Aα / β1 / β2 -------/ βn
www.knowledgegate.in
www.knowledgegate.in
A → Aα1 / Aα2 / β
A → Aα1 / Aα2 /----------Aαn / β
www.knowledgegate.in
www.knowledgegate.in
A → Aα1 / Aα2 /----------Aαn / β1 / β2 -------/ βm
www.knowledgegate.in
www.knowledgegate.in
S → 01S / 01
www.knowledgegate.in
www.knowledgegate.in
S → 0011S / 01 / 10
www.knowledgegate.in
www.knowledgegate.in
S → 01A / B11
A →011A / 01
B → 101B / 11
www.knowledgegate.in
www.knowledgegate.in
S → 011A / 101B
A →110A / 00
B → 11B / S
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
S → 011S / 01
www.knowledgegate.in
www.knowledgegate.in
S → 001S / 10A
A → 101A / 0 / 1
S → S10 / 01
www.knowledgegate.in
www.knowledgegate.in
• Finite Automata to Regular Grammar
www.knowledgegate.in
www.knowledgegate.in
• Every Left regular grammar can be converted into right regular and every right regular
grammar can be converted into left regular grammar.
• Procedure to convert Right linear grammar to Left linear grammar
• Obtain the RE from the grammar
• Reverse the RE
• Construct the finite automata for the regular expression
• Now construct the right linear grammar
• Reverse the left hand side of every production to get a left linear grammar.
www.knowledgegate.in
www.knowledgegate.in
What computer science deals with?
• Don’t
• So we do not study how to design a computer
• We do not study how to run a computer
• Do
• We deal with problem solving, according to computer science a problem can be divided
as follows
PROBLEM
SOLVABLE UNSOLVABLE
DECIDABLE UNDECIDABLE
www.knowledgegate.in
Konigsberg Bridge Problem
www.knowledgegate.in
www.knowledgegate.in
• SOLVABLE - A problem is said to be solvable if either we can solve it or if we can prove that the
problem cannot be solved.
• UNSOLVABLE - A problem is said to be unsolvable if neither we can solve it, nor we can proof
that the problem can not be solved.
• P- if there exist a polynomial time algorithm to solve a problem then problem is said to be
decidable.
www.knowledgegate.in
www.knowledgegate.in
Decision properties
• Approximately all the properties are decidable in case a finite automaton. Here
we will use machine model to proof decision properties.
i) Emptiness
ii) Non-emptiness
iii) Finiteness
iv) Infiniteness
v) Membership
vi) Equality
www.knowledgegate.in
www.knowledgegate.in
Emptiness & Non-emptiness
• Step 1: - select the state that cannot be reached from the initial states & delete them (remove
unreachable states)
• Step 2: - if the resulting machine contains at least one final states, so then the finite automata
accepts the non-empty language.
• Step 3: - if the resulting machine is free from final state, then finite automata accepts empty
language.
www.knowledgegate.in
www.knowledgegate.in
Finiteness & Infiniteness
• Step 1: - Select the state that cannot be reached from the initial state & delete them (remove
unreachable states)
• Step 2: - Select the state from which we cannot reach the final state & delete them (remove
dead states)
• Step 3: - If the resulting machine contains loops or cycles then the finite automata accepts
infinite language
• Step 4: - If the resulting machine do not contain loops or cycles then the finite automata
accepts finite language.
www.knowledgegate.in
www.knowledgegate.in
Membership
• Membership is a property to verify an arbitrary string is accepted by a finite automaton or not
i.e. it is a member of the language or not.
• 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 &
ends in anyone of the final state, then string ‘w’ is a member of M, otherwise ‘w’ is not a
member of M.
www.knowledgegate.in
www.knowledgegate.in
Equality
• Two finite state automata M1 & M2 is said to be equal if and only if, they accept
the same language.
• Minimise the finite state automata and and the minimal DFA will be unique.
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Emptiness Y Y Y X N N
Non-Emptiness Y Y Y X N N
Finiteness Y Y Y X N N
Infiniteness Y Y Y X N N
Membership Y Y Y X Y N
Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
Y Ywww.knowledgegate.in
Y X Y N
www.knowledgegate.in
Halting
Closure Properties of Regular Languages
• Regular languages are closed under following operations
• Kleen Closure
• Positive closure
• Complement
• Reverse Operator
• Prefix Operator
• Suffix operator
• Concatenation
• Union
• Intersection
• Set Difference operator
• Symmetric Difference
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following two statements about regular languages:
● S1: Every infinite regular language contains an undecidable language as a subset.
● S2: Every finite language is regular.
Which one of the following choices is correct? (GATE 2021) (2 MARKS)
www.knowledgegate.in
www.knowledgegate.in
Q If L is a regular language over ∑ = {a, b}, which one of the following languages
is NOT regular? (GATE – 2019) (1 Marks)
a) L⋅ LR {xy | x ∈ L, yR∈ L}
d) {w wR | w ∈ L}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following two statements (GATE-2016) (1 Marks)
I. If all states of an NFA are accepting states then the language accepted by the NFA is Σ ∗.
II. There exists a regular language A such that for all languages B, A ∩ B is regular.
Which one of the following is CORRECT?
www.knowledgegate.in
Q Which of the following is TRUE? (GATE-2007) (2 Marks)
a) Every subset of a regular set is regular.
b) The union of two non-regular sets is not regular.
c) Every finite subset of a non-regular set is regular.
d) Infinite union of finite sets is regular
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is true? (GATE – 2007) (1 Marks)
a) Infinite union of regular set is regular
b) The union of two non-regular net is not regular
c) finite union of infinite set is regular
d) every R.L is also C.F.L
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements about regular languages is NOT true? (GATE-
2006) (1-Marks)
a) Every language has a regular superset
b) Every language has a regular subset
c) Every subset of a regular language is regular
d) Every subset of a finite language is regular
www.knowledgegate.in
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
b) Every subset of a regular set is regular
c) Every finite subset of a regular set is regular
d) The intersection of two regular sets in regular
www.knowledgegate.in
www.knowledgegate.in
Q Let 𝐿1 and 𝐿2 are regular sets defined over alphabet ∑*. Mark the
false statement
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements are true?
i) The complement of a language is always regular
ii) The intersection of regular languages is regular
iii) The complement of a regular language is regular
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Union Y N Y Y Y Y
Intersection Y N N Y Y Y
Complement Y Y N Y Y N
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y
Positive Closure Y N Y Y Y Y
Concatenation Y N Y Y Y Y
Intersection
with regular set Y Y Y Y Y Y
Reverse Y Y Y Y Y Y
www.knowledgegate.in
Subset N Nwww.knowledgegate.in
N N N N
RL DCFL CFL CSL RS RES
Homomorphism Y N Y N N Y
∈ Free Homomorphism
Y N Y Y Y Y
Inverse Homomorphism Y Y Y Y Y Y
Substitution
Y N Y N N Y
∈ Free Substitution Y N Y Y Y Y
Quotient with regular set
www.knowledgegate.in
Y Y Y
www.knowledgegate.in
N Y Y
Moore and Mealy Machine
• Both moore and mealy machine are special case of DFA
• Both acts like o/p producers rather than language acceptors
• In moore and mealy machine no need to define the final states
• No concepts of dead states and no concepts of final states
• Mealy and Moore Machines are equivalent in power.
www.knowledgegate.in
Moore Machine
www.knowledgegate.in
www.knowledgegate.in
Examples: The below table shows the transition table of a Moore Machine.
• In moore machine for every state output is associated. If the length of i/p string is n, then
www.knowledgegate.in
length of o/p string will be n+1. Moore machine response for empty string .
www.knowledgegate.in
Q construct a Moore machine take all the string of a’s and b’s as i/p and
counts the no of a’s in the i/p string in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
www.knowledgegate.in
www.knowledgegate.in
Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the
no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
www.knowledgegate.in
www.knowledgegate.in
Q construct a Moore machine take all the string of a’s and b’s as i/p and counts the
no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
www.knowledgegate.in
www.knowledgegate.in
Q construct a Moore machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
www.knowledgegate.in
www.knowledgegate.in
Mealy Machine
• Mealy machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where all the symbols except λ have the same
www.knowledgegate.in
www.knowledgegate.in
Example: The below table shows the transition table of a Mealy Machine.
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts
the no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
www.knowledgegate.in
www.knowledgegate.in
Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts the
no of occurrence of sub-string ‘aa’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
www.knowledgegate.in
www.knowledgegate.in
Q construct a Mealy machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
www.knowledgegate.in
www.knowledgegate.in
CONVERSION OF MOORE TO MEALY MACHINE
• Let us take an example to understand the conversion:
• Convert the following Moore machine into its equivalent Mealy machine.
www.knowledgegate.in
www.knowledgegate.in
• To convert a mealy machine to moore machine all you need to do is just push out the outputs
of states onto to the incoming transitions.
• While conversion from moore to mealy machine, the number of states will we same and there
will be no extra states.
• The equivalent Moore Machine will be:
www.knowledgegate.in
www.knowledgegate.in
PROCEDURE FOR TRANSFORMING A MEALY MACHINE INTO A MOORE MACHINE
Consider the Mealy Machine:
www.knowledgegate.in
www.knowledgegate.in
Q Given the following state table of an FSM with two states A and B, one input and one output:
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 (B) 4 (C) 5 (D) 6
Present Present Next Next
I/p O/p
State A State B State A State B
0 0 0 0 0 1
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 1 0 0
0 0 1 0 1 0
0 1 1 0 0 1
1 0 1 0 1 1
1 1 1 0 0 1
www.knowledgegate.in
www.knowledgegate.in
Q The following diagram represents a finite state machine which takes as input a binary number
from the least significant bit. (GATE-2005) (1 Marks)
Which one of the following is TRUE?
(A) It computes 1’s complement of the input number
(B) It computes 2’s complement of the input number
(C) It increments the input number
(D) It decrements the input number
www.knowledgegate.in
www.knowledgegate.in
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)
(A) Outputs the sum of the present and the previous bits of the input.
www.knowledgegate.in
www.knowledgegate.in
Q Suppose we want to design a synchronous circuit that processes a string of 0’s and 1’s. Given a string, it produces another
string by replacing the first 1 in any subsequence of consecutive 1’s by a 0. Consider the following example.
Input sequence : 00100011000011100
Output sequence : 00000001000001100
A Mealy Machine is a state machine where both the next state and the output are functions of the present state and the current
input. The above mentioned circuit can be designed as a two-state Mealy machine. The states in the Mealy machine can be
represented using Boolean values 0 and 1. We denote the current state, the next state, the next incoming bit, and the output bit
of the Mealy machine by the variables s,t,b and y respectively. Assume the initial state of the Mealy machine is 0. What are the
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
(c) t = b y = sb’
www.knowledgegate.in
www.knowledgegate.in
Pumping Lemma For Regular Languages
• Pumping Lemma is used as a proof for irregularity of a language. Thus, if a language is regular, it always satisfies
pumping lemma. If there exists at least one string made from pumping which is not in L, then L is surely not
regular.
• The opposite of this may not always be true. That is, if Pumping Lemma holds, it does not mean that the
language is regular.
• Pumping Lemma is used to prove that some of the language is non-regular.
• For the pumping lemma, i/p is NRL & o/p is also NRL.
Pumping Lemma
www.knowledgegate.in
www.knowledgegate.in
Pumping Lemma For Regular Languages
• For any regular language L, there exists an integer n, such that for all z ∈ L with |z| ≥ n, there
exists u, v, w ∈ Σ∗, such that z = uvw, and
o |uv| ≤ n
o |v| ≥ 1
o for all i ≥ 0: uviw ∈ L
• In simple terms, this means that if a string v is ‘pumped’, i.e., if v is inserted any number of
times, the resultant string still remains in L.
www.knowledgegate.in
www.knowledgegate.in
Process of pumping Lemma
• Suppose that we need to prove that language L is a non-regular.
• Assume that L is a regular language, then L must satisfy pumping lemma property.
• Choose z ∈ L such that |z| <= n, split z into 3 parts.
o |uv| ≤ n
o |v| ≥ 1
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.
www.knowledgegate.in
www.knowledgegate.in
Q Proof that language L = {ambn | m=n} is non-regular?
www.knowledgegate.in
www.knowledgegate.in
Q Proof that language L = {ambn | m<n} is non-regular?
www.knowledgegate.in
www.knowledgegate.in
Q Proof that language L = {anbn | n is a prime number} ?
www.knowledgegate.in
www.knowledgegate.in
Q Proof that language L = {an^2 | n>= 0} ?
www.knowledgegate.in
www.knowledgegate.in
Q For Σ = {a, b}, let us consider the regular language
L = {x ∣ x = a2 + 3k or x = b10 + 12k, k ≥ 0}
Which one of the following can be a pumping length (the constant guaranteed by the pumping
lemma) for L? (GATE- 2019)
www.knowledgegate.in
www.knowledgegate.in
CONTEXT-FREE LANGUAGES AND PUSH DOWN AUTOMATA
• We Already understand the limitation of finite automata, that it cannot do the infinite comparison
between the symbols.
• Let us consider L = {an bn | n >= 1}. This is not regular, as it has to remember the number of a's in a
string and so it will require an infinite number of states, which is logically not possible.
• 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.
• This type of arrangement where a finite automaton has a stack leads to the generation of a
pushdown automaton.
www.knowledgegate.in
www.knowledgegate.in
BLOCK DIAGRAM OF PDA
• Finite control unit is also called as memory unit it is static and limited. So to process the i/p string if the static
memory is not sufficient then we can use the stack.
• 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
support three operations push, pop and skip.
• The accepting power of a pda is more than that of finite automata and less than that of linear bounder automata
• The power of non-deterministic pda is more than the power of deterministic pda.
www.knowledgegate.in
www.knowledgegate.in
Formal Definition of DPDA
A DPDA is a 7-tuple, namely (Q, ∑, Γ, δ, q0, Z0, F), where
(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,
(iv) q0 – is a special state called the initial state,
(v) Z0 – is a special pushdown symbol called the initial symbol on the pushdown store.
(vi) F – is a set of final states, a subset of Q and
(vii) δ – is a transition function from Q x (∑ U {∈}) x Γ to the set of finite subsets of Q x Γ*.
www.knowledgegate.in
www.knowledgegate.in
Representation of States
(1) PUSH – one symbol can be inserted into the stack at one time.
δ(qi, a, z0) = (qj, az0)
www.knowledgegate.in
www.knowledgegate.in
Representation of States
(2) POP – one symbol can be deleted from the stack at one time.
δ(qi, a, z0) = (qj, ε)
www.knowledgegate.in
www.knowledgegate.in
Representation of States
(3) SKIP – IT means no stack operation, status of the stack will remain same, before
a after the operation
δ(qi, a, z0) = (qj, z0)
note- if pda perform a push or a pop operation at least one’s during processing of
string than we say that pda is using the stack.
www.knowledgegate.in
www.knowledgegate.in
Instantaneous Description (ID)
• An initial ID is (q0, x, Z0), this means that initially the pda is in the initial state q0, the input
string to be processed is x and the PDS has only one symbol, namely Z0.
www.knowledgegate.in
capability of the pda either we accept by final state of empty stack.
Q Design a Deterministic Push Down Automata for L = {a, ab}?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Deterministic Push Down Automata for L = {a bn | n >= 0}?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Deterministic Push Down Automata for {an bn | n >= 1} ?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Deterministic Push Down Automata for {an b2n | n >= 1} ?
www.knowledgegate.in
www.knowledgegate.in
Q Design a PDA for {w c wr | w ∈(a, b)*} ?
www.knowledgegate.in
www.knowledgegate.in
Q Construct PDA that accepts L = {|w|a = b | w € (a, b)*} ?
www.knowledgegate.in
www.knowledgegate.in
Q consider the following mapping and find the correct language?
δ (q0, 1, z0) = (q0, xz0)
δ (q0, 1, x) = (q0, xx)
δ (q0, 0, x) = (q1, €)
δ (q1, 0, x) = (q1, €)
δ (q1, €, x) = (q1, €)
δ (q1, €, z0) = (qF, z0)
a) L = {am bn | m = n}
b) L = {am bn | m != n}
c) L = {am bn | m >= n}
d) L = {am bn | m <= n}
www.knowledgegate.in
www.knowledgegate.in
Q consider the following mapping and find the correct language?
δ (q0, a, z0) = (q1, z0)
δ (q0, b, z0) = (q2, z0)
δ (q1, a, z0) = (q1, z0)
δ (q1, b, z0) = (q2, z0)
δ (q2, a, z0) = (q2, z0)
δ (q2, b, z0) = (q0, z0)
δ (q1, €, z0) = (qf, z0)
a) ending with a
b) ending with a, contain even number of a
c) ending with a, contain odd number of a
d) ending with a, contain even number of b
www.knowledgegate.in
www.knowledgegate.in
Non- Deterministic PDA
• Non- Deterministic PDA can also be defined using 7 tuples.
• δ: Q x {∑ U ∈} x Γ → 2(Q x Γ* )
• i.e. on a given input symbol and stack symbol a NPDA can move to more than one state.
• Rest all other tuples are same as DPDA.
www.knowledgegate.in
www.knowledgegate.in
Q Construct pda that accepts a language L = {w wr | w € (a, b)*}?
www.knowledgegate.in
www.knowledgegate.in
(GATE-2021)
www.knowledgegate.in
www.knowledgegate.in
Q In a pushdown automaton P=(Q,Σ,Γ,δ,q0,F), a transition of the form,
The number of strings of length 100 accepted by the above pushdown automaton is ___________ .(GATE
2021) (2 MARKS)
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following languages over ∑ = {a, b} is NOT context-free?
(GATE-2019) (2 Marks)
a) {an bi | i ∈ {n, 3n, 5n}, n≥ 0} b) {w an wR bn | w ∈ {a, b}*, n≥ 0}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages:
I. {am bn cp dq ∣ m + p = n + q, where m, n, p, q ≥ 0}
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. {am bn cp dq ∣ mn = p + q, where m, n, p, q ≥ 0}
www.knowledgegate.in
Linear Grammar in Computer Science
• A linear grammar is a type of context-free grammar where each production's right-hand side contains at most
one nonterminal symbol.
• Example of a simple linear grammar:
• Let G be a grammar with nonterminal set N={S}, terminal set Σ={a,b}, and the start symbol S.
• Production rules:
• S→aSb
• S→ε
• This grammar generates the language L={anbn∣n≥0}, which is a linear language.
• Types of Linear Grammars:
• Left-Linear Grammars: Nonterminal symbols appear only at the left ends of the right-hand sides.
• Right-Linear Grammars: Nonterminal symbols appear only at the right ends of the right-hand sides.
• Both left-linear and right-linear grammars generate regular languages.
www.knowledgegate.in
www.knowledgegate.in
• General Linear Grammars:
• 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.
• For example, the grammar:
• S→aAS
• A→SbA
• S→ε
• generates the same language as the example above.
www.knowledgegate.in
www.knowledgegate.in
• Relation to Other Languages:
• All regular languages are linear, but not all linear languages are regular. For example,
{anbn∣n≥0} is linear but non-regular.
• 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.
• Determinism and Complexity:
• Regular linear languages are deterministic, but some linear languages are
nondeterministic.
• For example, the language of even-length palindromes (generated by the grammar
S→0S0∣1S1∣ε) is nondeterministic.
• Nondeterministic linear languages cannot always be recognized in linear time.
• Moreover, it is undecidable whether a given context-free language is linear.
www.knowledgegate.in
www.knowledgegate.in
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)
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages (GATE-2016) (1 Marks)
L1 = {an bm cn: m, n >= 1}
www.knowledgegate.in
Q Which of the following languages are context-free? (GATE-2015) (2 Marks)
L1 = {am bn an bm ⎪ m, n ≥ 1}
L2 = {am bn am bn ⎪ m, n ≥ 1}
L3 = {am bn ⎪ m = 2n + 1}
www.knowledgegate.in
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 (B) Only L1
(C) Only L1 and L2 (D) All the three languages
www.knowledgegate.in
www.knowledgegate.in
Q Consider the language L1, L2, L3 as given below. (GATE-2011) (2 Marks)
L1 = {ap bq | p, q N}
L3 = {ap bq cr | p, q, r N and p = q = r}
www.knowledgegate.in
Q Consider the languages (GATE-2010) (2 Marks)
L1 = {0i 1j | i != j} L2 = {0i 1j | i = j}
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
(B) Every NFA can be converted to an equivalent PDA.
(C) Complement of every context-free language is recursive.
(D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA.
www.knowledgegate.in
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}
www.knowledgegate.in
Q The language L = {0i21i | i≥0} over the alphabet {0,1, 2} is: (GATE-2007) (2 Marks)
a) not recursive.
b) is recursive and is a deterministic CFL.
c) is a regular language.
d) is not a deterministic CFL but a CFL
www.knowledgegate.in
www.knowledgegate.in
Q (GATE-2006) (1 Marks)
www.knowledgegate.in
Q Consider the languages: (GATE-2005) (2 Marks)
L1 = {w wR |w ∈ {0, 1}*}
L3 = {w w | w ∈ (0, 1}*)
www.knowledgegate.in
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,
respectively. Which one of the following is TRUE? (GATE-2005) (1 Marks)
(A) Df ⊂ Nf and Dp ⊂ Np (B) Df ⊂ Nf and Dp = Np
www.knowledgegate.in
www.knowledgegate.in
Q The language {0𝑛 12𝑛 | 1 ≤ n ≤ 106 } is: (GATE – 2005) (1 Marks)
a) Regular
b) Context free but not regular
c) Context free but its complement is not context free
d) Not context free
www.knowledgegate.in
www.knowledgegate.in
Q The language {am bn Cm+n | m, n ≥ 1} is (GATE-2004) (1 Marks)
(A) regular
(B) context-free but not regular
(C) context sensitive but not context free
(D) type-0 but not context sensitive
www.knowledgegate.in
www.knowledgegate.in
Q The language accepted by a Pushdown Automation in which the stack is
limited to 10 items is best described as (GATE-2003) (1 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following language over {a, b, c} is accepted by a deterministic
pushdown automaton? (GATE – 1997) (1 Marks)
a) {w ⊂ 𝑤 𝑅 | w ϵ {a, b) *} b) {𝑤𝑤 𝑅 | w ϵ {a, b, c) *}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following set of languages
𝑳𝟏 = 𝑎 𝑚 𝑏 𝑛 | n = 𝑚 2 𝑳𝟐 = 𝑎 𝑚 𝑏 𝑚 𝑐 𝑚 𝑑 𝑛 | m, n > 0 𝑳𝟑 = 𝑎 𝑚 𝑏 𝑚 𝑐 𝑛 𝑑 𝑛 | m, n > 0
www.knowledgegate.in
Q The languages
1. {0n 1n | n>=1} and 2. { 0n 12n | n >= 1} U {0n 1n | n >= 1} are
www.knowledgegate.in
Q Let M = ({q0, q1}, {0, 1}, (Z0, X), , q0, Z0, ) be a pushdown automata where is
given by
(q0, 1, Z0) = {(q0, XZ0)}
(q1, , Z0) = {(q0, )}
(q0, 1, X) = {(q0, XX)}
(q1, 1, X) = {(q1, )}
(q0, 0, X) = {(q1, X)}
www.knowledgegate.in
Q A PDM behaves like a TM when the number of auxiliary memories it
has, is
a) 0
b) 1 or more
c) 2 or more
d) none of these
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following languages can’t be accepted by a deterministic PDA?
c) L = {W c 𝑊 𝑅 |𝑊 𝑖𝑛 0 + 1 ∗}
d) L = {0𝑛 1𝑛 | n ≥ 0}
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following languages is accepted by a non – deterministic pushdown
automaton (PDA) but NOT by a deterministic PDA?
a) {an bn c n |n ≥ 0} b) {a1 bm c n |l ≠ m or m ≠ n}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following set of languages over one symbol alphabet
L1: set of left linear languages L2: set of right linear languages
www.knowledgegate.in
Q Which of the following is a CFL?
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is not true?
a) The set of languages accepted by deterministic and non-deterministic PDAs are not
equal
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statement must always be true for A and B? Suppose A
and B are two sets of strings from ∑*, such that B ⊆ A
i) If A is finite then, B is finite
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following language is true about the language L = (𝑎 𝑃 |P is a prime)
www.knowledgegate.in
www.knowledgegate.in
Q Identity the language generated by following grammar where S is the
start variable. (GATE-2017) (2 Marks)
S → XY
X → aX | a
Y → aYb | ∈
www.knowledgegate.in
Q Consider the context-free grammars over the alphabet {a, b, c} given below. S
and T are non-terminals. (GATE-2017) (2 Marks)
G1: S → aSb | T, T → cT | ϵ
G2: S → bSa | T, T → cT | ϵ
www.knowledgegate.in
Q Consider the following context-free grammar over the alphabet ∑ = {a, b, c} with S as the start
symbol: (GATE-2017) (2 Marks)
S → abScT | abcT
T → bT | b
Which of the following represents the language generated by the above grammar?
a) {(ab)n(cb)n | n >= 1 }
www.knowledgegate.in
Q Which of the following languages is generated by the given grammar? (GATE-
2016) (2 Marks)
S → aS | bS | ε
www.knowledgegate.in
Q Consider the following context-free grammars:
Which one of the following pairs of languages is generated by G1 and G2, respectively (GATE-2016) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q S -> aSa | bSb | a | b (GATE-2009) (2 Marks)
The language generated by the above grammar over the alphabet {a, b} is the set of
(C) Strings that begin and end with the same symbol
www.knowledgegate.in
Q Consider a CFG with the following productions. (GATE-2008) (2 Marks)
S → AA | B
A → 0A | A0 | 1
B → 0B00 | 1
S is the start symbol, A and B are non-terminals and 0 and 1 are the terminals. The language generated by this
grammar is
(A) {0n 102n | n ≥ 1}
(D) The set of all strings over {0, 1} containing at least two 0’s
www.knowledgegate.in
www.knowledgegate.in
Q Language L1 is defined by the grammar: S1 -> aS1b | ε
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
B → y | z | yB | zB B → y | yS
Which one of the following choices describes the properties satisfied by the strings in these languages?
a) G1: No y appears before any x, G2: Every x is followed by at least one y
www.knowledgegate.in
Q Consider the grammar given below (GATE – 2007) (2 Marks)
S → xB | yA
A → x | x S| y AA
B → y | y S| x BB
www.knowledgegate.in
Q Which one of the following grammars generates the language L = {a i bj | i ≠ j} (GATE-2006) (1 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q In the context-free grammar below, S is the start symbol, a and b are terminals,
and ϵ denotes the empty string (GATE-2006) (1 Marks)
S → aSa | bSb | a | b | ϵ
www.knowledgegate.in
www.knowledgegate.in
Q Let L denotes the language generated by the grammar S → 0S0/00. (GATE-2000)
(1 Marks)
Which of the following is true?
a) L = 0+ b) L is regular but not 0+
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following definitions below generates the same language as L,
where (GATE -1995) (2 Marks)
L = { 𝑥 𝑛 𝑦 𝑛 such that n > = 1}?
a) I only b) I and II
c) II and III d) II only
www.knowledgegate.in
www.knowledgegate.in
Q A CFG G is given with the following productions where S is the start symbol, A is
a non-terminal and a and b are terminals.
S → aS ∣ A
A → aAb ∣ bAa ∣ ϵ
www.knowledgegate.in
Q What is the equivalent CFL for the following CFG?
S → aS / aSbS / ϵ
a) {x|x is a palindrome}
b) {x|x = 𝑎 𝑛 𝑏 𝑛 𝑓𝑜𝑟 𝑛 ≥ 0}
www.knowledgegate.in
Q The grammar S → aaSbb | ab can generate the set
a) {𝑎𝑛 𝑏𝑛 |𝑛 = 1,2,3, … }
d) none of these
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following grammar generates the language L = {𝒂𝒊 𝒃𝒋 | i≠ j}
a) S → AC / CB b) S → as / sb / a / b
C → aCb / a / b
A → aA / ε
B → Bb / ε
c) S → Ac / CB d) S → AC / CB
C → aCb / ε C → aCb / ε
A → aA / ε A → aAa
B → Bb / ε B → bB / b
www.knowledgegate.in
www.knowledgegate.in
Q The following CFG
S → aS | bS | a | b is equivalent to the regular expression
www.knowledgegate.in
Q The set {𝑎𝑛 𝑏𝑛 |𝑛 = 1,2,3 … } can be generated by the CFG
a) S → ab |aSb|ϵ b) S → aaSbb | ab
www.knowledgegate.in
www.knowledgegate.in
Q In the context – free grammar below, S is the start symbol, a and b are terminals, and ε
denotes the empty string.
S → aSAb | ε
A → bA | ε
www.knowledgegate.in
Q The following CFG
S → aB | bA
A → ba | aS | bAA
B → b | bS | aBB
www.knowledgegate.in
Q 𝐿1 has the following grammar 𝐿2 has the following grammar
S → aB / BA S → Sba / a
A → bAA / aS / a
B → b / bS / aBB
Which of the following statement is true about?
𝐿3 = 𝐿1 ∩ 𝐿2 𝑎𝑛𝑑 𝐿4 = 𝐿.1 . 𝐿1 ∗?
www.knowledgegate.in
Q What is the equivalent CFL for the following CFG S → OS 1/ϵ?
a) {X/X is a palindrome}
b) {X/X = 0𝑛 1𝑛 𝑓𝑜𝑟 𝑛 ≥ 0}
www.knowledgegate.in
www.knowledgegate.in
Q If G, = ({S}, {a}, {S → SS}, S), find language generated by G.
a) L(G) = ϕ
b) L(G) = 𝑎 𝑛
c) L(G)= a*
d) L(G)= 𝑎 𝑛 b𝑎 𝑛
www.knowledgegate.in
www.knowledgegate.in
Q Consider a grammar G as follows
S → aA
A → bbA
A→c
L(G) =?
a) L(G) = {abbc}
b) L(G) = {a 𝑏 𝑛 𝑐; n ≥ 0}
c) L(G) = {a 𝑏 2𝑛 𝑐; n > 0}
d) L(G) = {a 𝑏 2𝑛 𝑐; n ≥ 0}
www.knowledgegate.in
www.knowledgegate.in
Decision properties
Following properties are decidable in case a CFL. Here we will use Grammar model
to proof decision properties.
i) Emptiness
ii) Non-emptiness
iii) Finiteness
iv) Infiniteness
v) Membership
www.knowledgegate.in
www.knowledgegate.in
Q consider the following CFG and identify which of the following CFG generate Empty language?
S → aAB / Aa
A→a
S → aAB
A→a/b
S → aAB / aB
A → aBb
B → aA
www.knowledgegate.in
www.knowledgegate.in
Q consider the following CFG and identify which of the following CFG generate Finite
language?
S → SS / AB
A → BC / a
B → CC / b
S → AB
A→B/a
S → AB
A → BC / a
B → CC / b
C → AB
www.knowledgegate.in
www.knowledgegate.in
Q consider the following CFG and check out the membership properties?
S → AB / BB
A → BA / AS / b
B → AA / SB / a
w1 = aba
w2 = abaab
w3 = abababba
www.knowledgegate.in
www.knowledgegate.in
CYK algorithm
• In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is
a parsing algorithm for context-free grammars, named after its inventors, John Cocke, Daniel Younger and Tadao
Kasami. It employs bottom-up parsing and dynamic programming.
• 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
1997).
• The importance of the CYK algorithm stems from its high efficiency in certain situations. Using Big O notation,
the worst case running time of CYK is O (n3 .|G|), Where n is the length of the parsed string and |G| is the size of
the CNF grammar G.
www.knowledgegate.in
www.knowledgegate.in
Following properties are Undecidable in case a CFL
i) Equality
ii) Ambiguity
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following problems is undecidable? (GATE-2014) (1 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following are decidable? (GATE-2008) (2 Marks)
I. Whether the intersection of two regular languages is infinite
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following problems is undecidable? (GATE-2007) (1 Marks)
(A) Membership problem for CFGs (B) Ambiguity problem for CFGs.
(C) Finiteness problem for FSAs. (D) Equivalence problem for FSAs.
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following statements is FALSE? (GATE-2004) (1 Marks)
a) There exist context free languages such that all the context free grammars generating them
age ambiguous.
b) An unambiguous context free grammar always has a unique parse tree for each string of the
language generated by it.
c) Both deterministic and non – deterministic pushdown automata always accept the same set of
languages
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following decision problems? (GATE-2000) (2 Marks)
(P1) Does a given finite state machine accept a given string
(P2) Does a given context free grammar generate an infinite number of stings
www.knowledgegate.in
Q Which of the following is undecidable
a) Equivalence of regular languages
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Emptiness Y Y Y X N N
Non-Emptiness Y Y Y X N N
Finiteness Y Y Y X N N
Infiniteness Y Y Y X N N
Membership Y Y Y X Y N
Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
Y Ywww.knowledgegate.in
Y X Y N
www.knowledgegate.in
Halting
Closure Properties of Deterministic Context Free Languages
• Deterministic Context Free Languages are closed under following operations
• Complement
• Intersection with regular set
• Inverse Homeomorphism
• Deterministic Context Free Languages are not closed under following operations
• Union
• Concatenation
• Kleen closure
• homomorphism
• Substitution
• Reverse operator
• Intersection
www.knowledgegate.in
www.knowledgegate.in
Closure Properties of Context Free Languages
• Context Free Languages are closed under following operations
• Union
• Concatenation
• Kleen Closure
• Substitution
• Homomorphism
• Inverse Homomorphism
• Reverse Operator
• Intersection with regular set
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Union Y N Y Y Y Y
Intersection Y N N Y Y Y
Complement Y Y N Y Y N
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y
Positive Closure Y N Y Y Y Y
Concatenation Y N Y Y Y Y
Intersection with
regular set Y Y Y Y Y Y
Reverse Y Y Y Y Y Y
Subset N N N N N N
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Homomorphism Y N Y N N Y
∈ Free Homomorphism
Y N Y Y Y Y
Inverse Homomorphism Y Y Y Y Y Y
Substitution
Y N Y N N Y
∈ Free Substitution Y N Y Y Y Y
Quotient with regular set Y Y Y N Y Y
www.knowledgegate.in
www.knowledgegate.in
Q For a string w, we define wR to be the reverse of w. For example, if w = 01101 then wR =
10110. Which of the following languages is/are context-free?(GATE 2021) (2 MARKS)
(A){wxwRxR ∣ w,x∈{0,1}*}
(A){wwRxxR ∣ w,x∈{0,1}*}
(A){wxwR ∣ w,x∈{0,1}*}
(A){wxxRwR ∣ w,x∈{0,1}*}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages:
L1 = {ww| w ∈ {a,b}*}
L2 = {anbncm |m,n >= 0}
L3 = {ambncn |m,n >= 0}
Which of the following statements is/are FALSE?(GATE 2022) (2 MARKS)
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages:
L1 = {anwan | w ∈{a,b}* }
L2 ={wxwR | w, x ∈ {a,b}*,|w|,|x|> 0}
Note that wR is the reversal of the string w. Which of the following is/are TRUE? (GATE 2022) (2
MARKS)
www.knowledgegate.in
www.knowledgegate.in
Q Suppose that L1 is a regular language and L2 is a context-free language.
Which one of the following languages is NOT necessarily context-free?
(GATE 2021)
(a) L1 ∩ L2
(b) L1 ⋅ L2
(c) L1 − L2
(d) L1 ∪ L2
www.knowledgegate.in
www.knowledgegate.in
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) L1∩L2'
(B) (L1'∪L2')'
(C) L1∪(L2∪L2')
(D)(L1∩L2)∪(L1∩L2)
www.knowledgegate.in
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)
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}.
II. L1 ∩ L2
a) I only b) II only
c) I and II d) Neither I nor II
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following statements is FALSE? (GATE-2013) (1
Marks)
L1 = {0p 1q 0r ∣ p, q, r ≥ 0} L2 = {0p 1q 0r ∣p, q, r ≥ 0, p ≠ r}
(A) L2 is context-free.
www.knowledgegate.in
Q Let L = 𝐿1 ∩ 𝐿2 , where 𝐿1 and 𝐿2 are languages as defined below: (GATE – 2009) (2 Marks)
𝐿1 = {𝑎𝑚 𝑏𝑚 c 𝑎𝑛 𝑏𝑛 | m, n ≥ 0} 𝐿2 = {𝑎𝑖 𝑏 𝑗 𝑐 𝑘 | I, j, k ≥ 0}
a) Not recursive
b) Regular
www.knowledgegate.in
Q Let L be a context - free language and M a regular language. Then the language L ∩ M is (GATE-
2006) (1 Marks)
www.knowledgegate.in
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}
www.knowledgegate.in
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)
www.knowledgegate.in
Q Which of the following statements is true? (GATE-2001) (1 Marks)
(A) If a language is context free it can always be accepted by a deterministic push-down
automaton
www.knowledgegate.in
Q Consider the following decision problems (GATE-2000) (2 Marks)
(P1) Does a given finite state machine accept a given string
(P2) Does a given context free grammar generate an infinite number of stings
www.knowledgegate.in
Q Let L1 is context free language and L2 is a regular language which of the following
is/are false (GATE – 1999) (1 Marks)
b) L1 ∩ L2 is context free
c) ~ L1 is context free
d) ~ L2 is regular
www.knowledgegate.in
www.knowledgegate.in
Q Context – free language is closed under: (GATE – 1999) (1 Marks)
a) Union, intersection b) Union, Kleene closure
www.knowledgegate.in
www.knowledgegate.in
Q If 𝐿1 and 𝐿2 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) 𝐿1 , 𝐿2 b) 𝐿1 ∩ 𝐿2 c) 𝐿1 ∩ R d) 𝐿1 ∪ 𝐿2
www.knowledgegate.in
www.knowledgegate.in
Q Context – free languages are (GATE – 1992) (1 Marks)
a) Closed under union b) Closed under complementation
www.knowledgegate.in
www.knowledgegate.in
Turing Machine
• 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
computer science.
• Turing machines serve several key purposes:
• General Automaton: Turing machines are the most general form of automaton, capable of simulating any
algorithmic process.
• Type-0 Language Acceptance: They can recognize type-0 languages, which are the most complex in the
Chomsky hierarchy.
• Function Computation: Turing machines can compute any computable function.
• Undecidability & Complexity: They help determine the undecidability of certain languages and are used to
measure both time and space complexity for computational problems.
www.knowledgegate.in
www.knowledgegate.in
Q Which one of the following is false
a) There is unique minimal DFA for every regular language
www.knowledgegate.in
www.knowledgegate.in
• Components of a Turing Machine:
• 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
two-way infinite tape.
• Read-Write Head: The head reads symbols from the tape and can also write over them. After reading or
writing, it moves one cell either to the left or right.
• Finite Control Unit: The control unit governs transitions based on the current state and symbol under the
read-write head. It determines the next action, ultimately leading to the machine’s output.
www.knowledgegate.in
www.knowledgegate.in
FORMAL DEFINITION
A Turing machine M is a 7-tuple, namely (Q, ∑, Γ, δ, q0, b, F), where
• Q is a finite nonempty set of states.
• b ∈ Γ is the blank.
• δ is the transition function mapping : Q ×ℾ -> Q× ℾ × (L/R). It says that, on providing a tape symbol, from a
particular state there will be a transition to another state, with a different or same tape symbol with defining
whether next the machine needs to move in left/ right.
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for L = {ab}?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for L = {a, ab}?
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
REPRESENTATION OF TURING MACHINES
Three representations:
• Instantaneous descriptions using move-relations.
• Transition table, and
• Transition diagram (transition graph).
www.knowledgegate.in
www.knowledgegate.in
LANGUAGE ACCEPTABILITY BY TURING MACHINES
• A string w in ∑* is said to be accepted by a TM(M) if after parsing the string w Turing machine
must halts on final state.
• q0w ⊢* α1pα2 for some p ∊ F and α1, α2 ∊ Γ *.
• M does not accept w if the machine M either halts in a non-accepting state or does not halt
and goes into a loop.
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for L = {an bn | n >= 1}?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for L = {an bn cn| n >= 0}?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for L = {w c w | w ∊ {0, 1}* }?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for addition of two number in unary?
www.knowledgegate.in
www.knowledgegate.in
Q Design a Turing machine for converting unary number into binary
number?
www.knowledgegate.in
www.knowledgegate.in
Q A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The
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
table. Which of the following statements is true about M ?
(A) M does not halt on any string in (0 + 1)+ 0 1 B
q0 q1, 1, R q1, 1, R Halt
(B) M does not halt on any string in (00 + 1)*
q1 q1, 1, R q0, 1, L q0, B, L
(C) M halts on all string ending in a 0
www.knowledgegate.in
www.knowledgegate.in
Q Consider the transition table of a TM given below. Here “b” represents the blank symbol.
Which of the following strings will not accepted?
a) 010101 b) 101010 c) 110011 d) Both a and b
www.knowledgegate.in
www.knowledgegate.in
Q The given Turing machine accepts
a) set of all even palindromes over {0, 1}
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following languages.
L1 = {ap | p is a prime number}
L4 = {an bn | n >= 1}
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is true for the language (GATE-2008) (2 Marks)
(A) It is not accepted by a Turing Machine
www.knowledgegate.in
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?
(A) L is recursively enumerable, but not recursive
(D) L is regular
www.knowledgegate.in
www.knowledgegate.in
Q L1 is a recursively enumerable language over Σ. An algorithm A effectively enumerates its words as w1, w2, w3, …
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)
S1 : L1 is recursive implies L2 is recursive
www.knowledgegate.in
www.knowledgegate.in
• Deterministic and Non-Deterministic Turing Machines:
• 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.
However, non-deterministic Turing machines do not add computational power and can
always be converted into a deterministic Turing machine.
www.knowledgegate.in
www.knowledgegate.in
Versions of Turing Machines:
• 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.
• 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.
• One-Way Infinite Tape (Semi-Infinite Tape): The tape is infinite in only one direction.
• Offline Turing Machine: The input tape is read-only and cannot be modified.
• Jumping Turing Machine: Can make multiple moves in one transition.
• Non-Erasing Turing Machine: Cannot erase or overwrite the input symbols with blanks.
• Always Writing Turing Machine: Must replace every symbol it reads with another symbol.
• Finite Automaton with Queue: Combines a finite automaton with an unbounded queue.
• Turing Machine with 3 States: A simplified Turing machine with only 3 states.
• Multi-Tape TM with Stay Option and 2 States: A variation with multiple tapes and stay options but limited to two states.
• Non-Deterministic TM: Similar to the non-deterministic Turing machine but with a stay option.
• NPDA with Two Stacks: A non-deterministic pushdown automaton with two independent stacks.
www.knowledgegate.in
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)
b) Deterministic push down automata (DPDA) and Non – deterministic push down automata (NPDA)
c) Deterministic single – tape Turing machine and Non – deterministic single tape Turing machine
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is true?
a) PDA with 2 stacks is equivalent to TM
c) Both a and b
d) None of a and b
www.knowledgegate.in
www.knowledgegate.in
Q Consider the Turing machine M defined below 0 1 B
Choose the false statement →Q0 (Q0, 0, R) (Q2, 1, L) (Qf, -, -)
a) The machine loops on 01 Q1 (Q2, 1, L) (Q1, 1, R) (Qf, -, -)
Q2 (Q2, 1, L) (Q2, 0, L) (Qf, -, -)
*Qf --- --- ---
b) The machine does not accept 0000
www.knowledgegate.in
www.knowledgegate.in
Halt in a Turing Machine
• When a Turing machine reaches a state where no further transitions are defined or needed, it
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.
• Non-Final Halt: The machine halts in a non-final state, meaning the input string is rejected.
• After processing an input string, a Turing machine can experience one of three outcomes:
• Final Halt: The machine accepts the string.
• Non-Final Halt: The machine rejects the string.
• Infinite Loop: The machine enters an infinite loop, in which case it is undecidable whether
the string is accepted or rejected.
www.knowledgegate.in
www.knowledgegate.in
Recursively Enumerable Languages
• Recursive Set:
• A language L is a recursive set if it is accepted by a Turing machine in such a way that:
• 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).
• The membership property is clearly defined here—every string is either accepted or rejected.
• Recursively Enumerable Set (REL):
• A language L is recursively enumerable if it is accepted by a Turing machine, where:
• For all w∈L, the machine halts in a final state (accepts).
• For all w∉L, the machine may either halt in a non-final state (reject) or enter an infinite loop.
• 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.
• Some sets are not recognizable, meaning that even the members of the set cannot be identified, as there are
more languages than programs available to recognize them.
www.knowledgegate.in
www.knowledgegate.in
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)
(A) Neither L nor L’ is recursively enumerable (r.e.).
(B) One of L and L’ is r.e. but not recursive; the other is not r.e.
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
www.knowledgegate.in
www.knowledgegate.in
Q If L and L’ are recursively enumerable, then L is (GATE-2008) (1 Marks)
(A) regular
(B) context-free
(C) context-sensitive
(D) recursive
www.knowledgegate.in
www.knowledgegate.in
Q Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive
language. Which one of the following is TRUE? (GATE-2005) (1 Marks)
L1’ → Complement of L1
L2’ → Complement of L2
www.knowledgegate.in
Universal Turing Machine (UTM)
• In computer science, a Universal Turing Machine (UTM) is a Turing machine capable of simulating any
other Turing machine on any input. It does this by reading both the description of the machine to be
simulated and the input for that machine from its own tape.
• Every Turing machine computes a fixed partial computable function from input strings over its
alphabet, behaving like a computer with a specific program.
• The action table of any Turing machine can be encoded into a string. A UTM can then read this
string, which describes the action table, followed by a string that describes the input tape, and
simulate the encoded Turing machine's behavior.
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q For a Turing machine M, ⟨M⟩ denotes an encoding of M. Consider the following two languages.
●L1 = { ⟨M⟩ ∣ M takes more than 2021 steps on all inputs }
●L2 = { ⟨M⟩ ∣ M takes more than 2021 steps on some input }
Which one of the following options is correct? (GATE 2021) (2 MARKS)
www.knowledgegate.in
www.knowledgegate.in
Q Let ⟨M⟩ denote an encoding of an automaton M. Suppose that Σ={0,1}. Which of
the following languages is/are NOT recursive? (GATE 2021)
(a) L = {⟨M⟩ ∣ M is a DFA such that L(M)=∅}
www.knowledgegate.in
www.knowledgegate.in
Q L1 = { <M> | M takes at least 2016 steps on some input},
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)
(A) decidable and recursively enumerable
www.knowledgegate.in
Linear Bounded Automaton (LBA)
• An LBA is a variant of a Turing machine with the following property: The tape
length is finite and bounded, unlike a traditional Turing machine that has an
infinite tape.
www.knowledgegate.in
www.knowledgegate.in
Decision properties
• Following properties are decidable in case a RS.
• Membership
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Emptiness Y Y Y X N N
Non-
Y Y Y X N N
Emptiness
Finiteness Y Y Y X N N
Infiniteness Y Y Y X N N
Membershi
Y Y Y X Y N
p
Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
Halting Y Y Y X Y N
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is/are undecidable? (GATE 2022) (2 MARKS)
(D) Given a Turing machine M, decide if M takes more than 1073 steps on every string.
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes
the language accepted by a machine M.
(I) For an unrestricted grammar G and a string w, whether w ϵ L(G)
(IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language
b) Only II is undecidable
www.knowledgegate.in
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)
I. Given a regular expression R and a string w, is w ∈ L(R)?
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following decision problems are undecidable (GATE-2016) (2
Marks)
www.knowledgegate.in
Q Which of the following is/are undecidable? (GATE-2013) (1 Marks)
1) G is a CFG. Is L(G)=ϕ?
2) G is a CFG. Is L(G)=Σ∗?
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following problems are decidable? (GATE-2012) (2 Marks)
a) Does a given program ever produce an output?
a) 1, 2, 3, 4 b) 1, 2
c) 2, 3, 4 d) 3, 4
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is not decidable? (GATE – 1997) (1 Marks)
a) Given a Turing machine M, a strings s and an integer k, M accepts s within k steps
www.knowledgegate.in
www.knowledgegate.in
Closure Properties of Recursive Set
• Recursive languages are closed under following operations
• Union
• Concatenation
• Intersection
• Reverse
• Complement
• Inverse homomorphism
• Intersection with regular set
• Set Difference
www.knowledgegate.in
www.knowledgegate.in
Closure Properties of Recursive Enumerable Set
• Recursive Enumerable are closed under following operations
• Union
• Concatenation
• Kleen Closure
• Intersection
• Substitution
• Homomorphism
• Inverse Homomorphism
• Intersection with regular set
• Reverse operation
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Union Y N Y Y Y Y
Intersection Y N N Y Y Y
Complement Y Y N Y Y N
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y
Positive
Y N Y Y Y Y
Closure
Concatenation Y N Y Y Y Y
Intersection
with regular Y Y Y Y Y Y
set
Reverse Y Y Y Y Y Y
Subset N N N N N N
www.knowledgegate.in
www.knowledgegate.in
RL DCFL CFL CSL RS RES
Homomorphism Y N Y N N Y
∈ Free
Homomorphism Y N Y Y Y Y
Inverse Y Y Y Y Y Y
Homomorphism
Substitution
Y N Y N N Y
∈ Free Substitution Y N Y Y Y Y
Quotient with Y Y Y N Y Y
regular set
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements is/are TRUE? (GATE 2022) (1 MARKS)
(B) If a language L and its complement L’ are both recursively enumerable, then L must be
recursive.
www.knowledgegate.in
www.knowledgegate.in
Q The set of all recursively enumerable languages is (GATE-2018) (1 Marks)
a) closed under complementation.
d) an uncountable set.
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following types of languages (GATE-2016) (2 Marks)
L1 Regular, L2: Context-free L3: Recursive, L4: Recursively enumerable.
Which of the following is/are TRUE?
I. L3' U L4 is recursively enumerable
II. L2 U L3 is recursive
www.knowledgegate.in
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
3. L1' is context-free
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) (2 Marks)
a) Neither L nor L' is recursively enumerable (r.e.).
b) One of L and L' is r.e. but not recursive; the other is not r.e.
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements is/are FALSE? (GATE-2013) (2 Marks)
1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing
machine.
www.knowledgegate.in
www.knowledgegate.in
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.
www.knowledgegate.in
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
www.knowledgegate.in
www.knowledgegate.in
Q If the strings of a language L can be effectively enumerated in lexicographic (i.e., alphabetic)
order, which of the following statements is true? (GATE-2003) (1 Marks)
(A) L is necessarily finite
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is true? (GATE-2002) (1 Marks)
(A) The complement of a recursive language is recursive.
www.knowledgegate.in
www.knowledgegate.in
a) Not recursive
b) Regular
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Cook-Levin Theorem (Cook's Theorem)
• In computational complexity theory, the Cook-Levin theorem states that the Boolean satisfiability
problem (SAT) is NP-complete. This means:
• SAT is in NP, and any problem in NP can be reduced in polynomial time by a deterministic Turing
machine to SAT.
• An important implication of this theorem is that if a deterministic polynomial-time algorithm exists
for SAT, then every NP problem can be solved in polynomial time. This leads to the famous P vs NP
problem, one of the most important open questions in theoretical computer science.
www.knowledgegate.in
www.knowledgegate.in
Stephen Cook's Contributions:
• 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
(also known as Cook reduction) and NP-completeness. He also proved the existence of NP-complete problems,
showing that SAT is NP-complete.
• This theorem explores whether optimization problems, whose solutions can be efficiently verified, can also be
solved efficiently.
• Cook proposed that some optimization problems (with easily verifiable solutions) cannot be solved by efficient
algorithms, i.e., P ≠ NP. This conjecture has spurred extensive research in computational complexity, enhancing
our understanding of the difficulty of computational problems. However, the conjecture remains unresolved.
• In 1982, Cook received the Turing Award for his groundbreaking contributions to complexity theory.
www.knowledgegate.in
www.knowledgegate.in
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)
(A) W can be recursively enumerable and Z is recursive.
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following statements (GATE-2015) (2 Marks)
1. The complement of every Turning decidable language is Turning decidable
www.knowledgegate.in
www.knowledgegate.in
Q Language L1 is polynomial time reducible to language L 2. 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)
I. If L4 ∈ P, L2 ∈ P
II. If L1 ∈ P or L3 ∈ P, then L2 ∈ P
www.knowledgegate.in
www.knowledgegate.in
Q Consider two decision problems Q 1, Q2 such that Q1 reduces in polynomial time
to 3-SAT and 3-SAT reduces in polynomial time to Q 2. 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
www.knowledgegate.in
www.knowledgegate.in
Q consider the following two problems of graph. (GATE-2015) (2 Marks)
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.
2) Given a graph, find if the graph has a cycle that visits every edge exactly once.
www.knowledgegate.in
www.knowledgegate.in
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.
www.knowledgegate.in
www.knowledgegate.in
Q (GATE-2014) (2 Marks)
www.knowledgegate.in
www.knowledgegate.in
Q Assuming P ≠ NP, which of the following is TRUE? (GATE-2012) (1 Marks)
a) NP-complete = NP
b) NP-complete ∩ P = ∅
c) NP-hard = NP
d) P = NP-complete
www.knowledgegate.in
www.knowledgegate.in
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)
www.knowledgegate.in
www.knowledgegate.in
Q Let πA be a problem that belongs to the class NP. Then which one of the
following is TRUE? (GATE-2009) (1 Marks)
a) There is no polynomial time algorithm for πA
d) πA may be undecidable
www.knowledgegate.in
www.knowledgegate.in
Q For problem X and Y, Y is NP – complete and X reduces to Y in polynomial time.
Which of the following is TRUE? (GATE – 2008) (2 Marks)
a) IF X can be solved in polynomial, time then so can Y
b) X is NP – complete
c) X is NP – hard
www.knowledgegate.in
www.knowledgegate.in
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?
(GATE-2008) (2 Marks)
a) Q solves the subset-sum problem in polynomial time when the input is encoded in unary
b) Q solves the subset-sum problem in polynomial time when the input is encoded in binary
www.knowledgegate.in
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
www.knowledgegate.in
www.knowledgegate.in
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)
a) Both DHAM3 and SHAM3 are NP – hard
www.knowledgegate.in
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
b) R is NP – hard
c) Q is NP – complete
d) Q is NP- hard
www.knowledgegate.in
www.knowledgegate.in
Q Consider three decision problems P 1, 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
www.knowledgegate.in
www.knowledgegate.in
Q Consider the following two problems on undirected graphs: (GATE – 2005) (1
Marks)
𝜶: Given G (V, E) does G have an independent set of size |V| - 4?
b) 𝛼 is NP – complete in and β is in P
www.knowledgegate.in
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)
(A) Π is NP-hard but not NP-complete
(C) Π is NP-complete
www.knowledgegate.in
Q Which of the following is in P?
PATH, HAMPATH, SAT, 3AT
a) SAT b) 3SAT
c) PATH d) HAMPATH
www.knowledgegate.in
www.knowledgegate.in
Q The problem 3-SAT and 2-SAT are
(A) both in P (B) both NP complete
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is false?
a) PATH is a class problem b) Dijkstra’s algorithm is a problem in P
www.knowledgegate.in
www.knowledgegate.in
Q The statement P ⊆ Np is
a) true b) false
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
www.knowledgegate.in
Q If 1 p 2 (1 is polynomially reduces to 2) then consider the statements
S1: if 1 P then 2 P
S2: if 2 P then 1 P
S3: if 1 is un-decidable then 2 is Un- decidable
S4: if 2 is un-decidable then 1 is Un- decidable
a) Only S1 and S2
b) Only S2 and S3
c) Only S3 and S4
d) Only S4 and S1
www.knowledgegate.in
www.knowledgegate.in
Q If there is an NP – complete language L whose complement is in NP, then the
complement of any language in NP is in
a) NP b) P c) Both a and b d) None of these
www.knowledgegate.in
www.knowledgegate.in
Q The Travelling Salesman Problem (TSP) is
a) NP but not NP complete b) NP – complete
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following statements are TRUE?
1. The problem of determining whether there exists a cycle in an undirected graph is in P.
2. The problem of determining whether there exists a cycle in an undirected graph is in NP.
3. If a problem A is NP-Complete, there exists a non-deterministic polynomial time algorithm to
solve A.
(A) 1, 2 and 3 (B) 1 and 2 only
www.knowledgegate.in
www.knowledgegate.in
Q Which of the following is true about NP-Complete and NP-Hard problems.
(A) If we want to prove that a problem X is NP-Hard, we take a known NP-Hard
problem Y and reduce Y to X
(B) The first problem that was proved as NP-complete was the circuit satisfiability
problem.
(C) NP-complete is a subset of NP Hard
(D) All of the above
(E) None of the above
www.knowledgegate.in
www.knowledgegate.in
A) 1, 2 and 3 B) 1 and 2 only
C) 3 and 2 only D) 1 and 3 only
www.knowledgegate.in
www.knowledgegate.in