All questions of Theory of Computation for Computer Science Engineering (CSE) Exam

Identify the language generated by the following grammar, where S is the start variable.
S → XY
X → aX | a
Y → aYb | ϵ
  • a)
    {ambn | m ≥ n, n > 0}
  • b)
    {ambn | m ≥ n, n ≥ 0}
  • c)
    {ambn | m > n, n ≥ 0}
  • d)
    {ambn | m > n, n > 0}
Correct answer is option 'C'. Can you explain this answer?

Eesha Bhat answered
Grammar:
S → XY
X → aX | a
Y → aYb | ϵ
Explanation:
X generates at least one a. Generates a string of type {a, aa, aaa, aaaa……}
ambn, if n = 0 and m = 0 ∴ string = ϵ which cannot be generated from the given grammar and hence option 2 is incorrect.
Y generates an equal number of a and b { ϵ, ab, aabb, ……} with a comes before b.
Since at least one a is generated by X and an equal number of a’s and b’s generated by Y ∴ m> n and hence option 1 is incorrect
The smallest length string generated by Y is ϵ. In ambn, n ≥ 0 and hence option 4 is incorrect.
{ a, aab, aaabb,………….} which is equivalent to :
L = {ambn | m > n, n ≥ 0}

If an Infinite language is passed to Machine M, the subsidiary which gives a finite solution to the infinite input tape is ______________
  • a)
    Compiler
  • b)
    Interpreter
  • c)
    Loader and Linkers
  • d)
    None of the mentioned
Correct answer is option 'A'. Can you explain this answer?

Akshay Singh answered
Answer:

Introduction:
In the field of computer science, an infinite language refers to a set of strings that can be generated by a Turing machine or any other computational model. When an infinite language is passed as input to a machine M, there can be different approaches to handle this input and provide a finite solution.

Compiler:
A compiler is a software tool that translates high-level programming languages into machine code or bytecode. It takes the entire program as input, performs lexical analysis, syntax analysis, semantic analysis, and code generation to produce an executable file or an intermediate representation. However, a compiler is not suitable for handling infinite languages because it processes the entire program at once and requires a finite input.

Interpreter:
An interpreter is a software tool that directly executes the instructions of a high-level programming language without the need for explicit compilation. It takes one statement at a time, analyzes it, and performs the corresponding operations. While interpreters can handle infinite languages, they do not provide a finite solution to the infinite input tape. Instead, they execute the instructions indefinitely until interrupted.

Loader and Linkers:
Loaders and linkers are responsible for loading executable programs into memory and resolving references between different modules or libraries. They do not have the capability to handle infinite languages or provide a finite solution to an infinite input tape.

Conclusion:
Based on the given options, the correct answer is option A - Compiler. While compilers are designed to handle finite programs and produce executable code, they are not suitable for handling infinite languages. Therefore, none of the mentioned options are appropriate for providing a finite solution to an infinite input tape.

Which of the following is not an example of finite state machine system?
  • a)
    Control Mechanism of an elevator
  • b)
    Combinational Locks
  • c)
    Traffic Lights
  • d)
    Digital Watches
Correct answer is option 'D'. Can you explain this answer?

Sudhir Patel answered
Proper and sequential combination of events leads the machines to work in hand which includes The elevator, Combinational Locks, Traffic Lights, vending machine, etc. Other applications of Finite machine state system are Communication Protocol Design, Artificial Intelligence Research, A Turnstile, etc.

Which of the following is sufficient to convert an arbitrary Context Free Grammar (CFG) to an LL(1) grammar?
  • a)
    Ambiguity
  • b)
    Left Recursion
  • c)
    Left Factoring
  • d)
    None of the above
Correct answer is option 'D'. Can you explain this answer?

Sudhir Patel answered
LL(1) Grammar: The first 'L' refers to scanning of input from Left to Right, the second 'L' refers to producing the Leftmost Derivation and the (1) stands for using only 1 lookahead input symbol at each step to make parsing action decisions. Hence, a context-free grammar G = (VT, VN, S, P) whose parsing table has no multiple entries is said to be LL(1) Grammar.
LL(1) Conflicts:
  • Checking whether a grammar is ambiguous or not is undecidable.
  • A grammar can be LL(1) only if it is not ambiguous, not left recursive and it must not contain left factoring and vice-versa is not necessary.
  • Any regular language can be LL(1) is true statement since we can write regular grammar which follows the above conflict.
Since a grammar is LL(1) only if it does not contain left recursion, ambiguity and left factoring, hence, to convert an arbitrary CFG to LL(1), all the three should be eliminated

The complement of a language will only be defined when and only when the __________ over the language is defined.
  • a)
    String
  • b)
    Word
  • c)
    Alphabet
  • d)
    Grammar
Correct answer is option 'C'. Can you explain this answer?

Yash Verma answered
Definition
The complement of a language refers to all the strings that are not part of the original language. In other words, it consists of all the strings that do not satisfy the criteria or rules defined by the language.

Language
A language is a set of strings that are formed using symbols from an alphabet. The alphabet is a finite set of symbols or characters. For example, {0, 1} is an alphabet containing two symbols 0 and 1.

Complement of a Language
To define the complement of a language, we need to consider the entire set of possible strings that can be formed using symbols from the alphabet. Since the complement includes all the strings that are not part of the original language, the set of possible strings must be well-defined.

Alphabet
The complement of a language can only be defined when and only when the alphabet over the language is defined. The alphabet provides the set of symbols or characters that can be used to form strings in the language.

Explanation
The alphabet defines the symbols or characters that can be used to construct strings in a language. Without a well-defined alphabet, it is not possible to determine the set of possible strings and therefore the complement of a language cannot be defined.

For example, consider a language defined over the alphabet {0, 1, 2}. The language may consist of all strings containing only the symbols 0 and 1. The complement of this language would then contain all strings that do not satisfy this criterion, i.e., strings containing symbols other than 0 and 1.

However, if the alphabet over the language is not defined or is not well-defined, it becomes impossible to determine the set of possible strings and hence the complement of the language cannot be defined.

Therefore, the complement of a language will only be defined when and only when the alphabet over the language is defined. The alphabet provides the basis for constructing strings and determining the set of possible strings in a language, which is essential for defining its complement.

Which of the following languages accept pumping lemma?
  • a)
    Regular Languages
  • b)
    Context Free Languages
  • c)
    Recursive Languages
  • d)
    Recursively Enumerable Languages
Correct answer is option 'D'. Can you explain this answer?

Explanation:
The Pumping Lemma is a theorem in formal language theory that provides a necessary condition for a language to be considered regular. It is used to prove that certain languages are not regular.

Regular Languages:
Regular languages are the languages that can be recognized by a finite automaton or expressed by a regular expression. They are closed under union, concatenation, and Kleene star operations. The Pumping Lemma can be used to prove that certain languages are not regular by showing that they do not satisfy the conditions of the lemma.

Context-Free Languages:
Context-free languages are a more general class of languages than regular languages. They can be recognized by a pushdown automaton and expressed by a context-free grammar. However, the Pumping Lemma does not apply to context-free languages. Instead, the pumping lemma for context-free languages is used to prove that certain languages are not context-free.

Recursive Languages:
Recursive languages, also known as decidable languages, are languages for which there exists a Turing machine that halts and accepts every string in the language and halts and rejects every string not in the language. The Pumping Lemma is not applicable to recursive languages because the Pumping Lemma is used to prove that certain languages are not regular, and recursive languages are a superset of regular languages.

Recursively Enumerable Languages:
Recursively enumerable languages, also known as recursively enumerable sets, are languages for which there exists a Turing machine that halts and accepts every string in the language, but may either halt and reject or loop indefinitely on strings not in the language. The Pumping Lemma is not applicable to recursively enumerable languages because the Pumping Lemma is used to prove that certain languages are not regular, and recursively enumerable languages are a superset of regular languages.

Therefore, the correct option is D) Recursively Enumerable Languages.

The major difference between Mealy and Moore machine is about:
  • a)
    Output Variations
  • b)
    Input Variations
  • c)
    All of the mentioned
  • d)
    None of the mentioned
Correct answer is option 'A'. Can you explain this answer?

Nisha Gupta answered
Introduction:
Mealy and Moore machines are two types of finite state machines that are used in digital systems to model sequential logic. They differ in their output variations, which is the major difference between the two.

Mealy Machine:
- A Mealy machine is a type of finite state machine where the outputs depend on both the current state and the inputs.
- The output of a Mealy machine is associated with the transitions between states, rather than just the states themselves.
- The output of a Mealy machine changes immediately after a transition occurs, based on the current state and the input that caused the transition.
- The output is not stored in the states, but rather in the transitions between states.

Moore Machine:
- A Moore machine is another type of finite state machine where the outputs only depend on the current state.
- The output of a Moore machine is associated with the states themselves, rather than the transitions between states.
- The output of a Moore machine remains constant throughout the duration of a state and only changes when a transition occurs.
- The output is stored in the states and is not directly affected by the inputs.

Comparison:
Output Variations:
- The major difference between Mealy and Moore machines is the way they handle output variations.
- In a Mealy machine, the outputs can change immediately after a transition occurs, as they are associated with the transitions themselves.
- In a Moore machine, the outputs remain constant throughout the duration of a state, only changing when a transition occurs.
- Mealy machines have more flexibility in terms of generating outputs, as they can produce different outputs for the same input sequence depending on the current state.
- Moore machines, on the other hand, have more predictable outputs as they are solely determined by the current state.

Conclusion:
The major difference between Mealy and Moore machines is the way they handle output variations. Mealy machines generate outputs based on both the current state and the inputs, while Moore machines generate outputs solely based on the current state. Mealy machines provide more flexibility in terms of output generation, while Moore machines offer more predictable outputs.

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?
  • a)
    3
  • b)
    5
  • c)
    9
  • d)
    24
Correct answer is option 'D'. Can you explain this answer?

Samarth Ghosh answered
Your safety, it is important to be cautious and aware of your surroundings at all times. Here are some safety tips to keep in mind:

1. Stay alert: Pay attention to your surroundings and avoid distractions like using your phone or wearing headphones.

2. Trust your instincts: If a situation or person feels unsafe, trust your gut and find a way to remove yourself from the situation.

3. Plan your routes: When walking or traveling, try to stick to well-lit and busy areas. Avoid dark or isolated areas, especially at night.

4. Let someone know your plans: If you are going out alone, let a trusted friend or family member know where you are going and when you expect to return.

5. Travel in groups: Whenever possible, travel with others, especially at night or in unfamiliar areas.

6. Be cautious with strangers: Avoid sharing personal information or getting into a car with someone you don't know.

7. Keep valuables hidden: Keep your phone, wallet, and other valuables out of sight to avoid attracting attention.

8. Carry a personal safety device: Consider carrying a personal safety device such as a whistle or pepper spray, if legal in your area.

9. Stay in well-known accommodations: When traveling, choose reputable hotels or accommodations in safe areas.

10. Know emergency numbers: Familiarize yourself with local emergency numbers and have them readily available.

Remember, these tips are general guidelines, and it's always a good idea to research the specific safety precautions and recommendations for the area you will be in.

A regular language over an alphabet ∑ is one that cannot be obtained from the basic languages using the operation
  • a)
    Union
  • b)
    Concatenation
  • c)
    Kleene*
  • d)
    All of the mentioned
Correct answer is option 'D'. Can you explain this answer?

Raksha Mishra answered
An alphabet is a set of symbols or characters that are used to form words or strings in a language. A regular language is a type of formal language that can be described and recognized by a regular expression, a deterministic finite automaton (DFA), a non-deterministic finite automaton (NFA), or a regular grammar.

In the context of regular languages, an alphabet refers to the set of symbols or characters that can be used to form words in the language. For example, if we consider the alphabet {0, 1}, then a regular language over this alphabet could be the set of all binary strings that start with a 0 and end with a 1 (e.g., "0101", "0011101", etc.).

Regular languages can be defined using regular expressions, which are patterns that describe the structure of the language. For example, the regular expression "0(0+1)*1" represents the regular language mentioned earlier.

Regular languages can also be recognized by deterministic finite automata (DFA) or non-deterministic finite automata (NFA). These are abstract machines that can read input symbols and transition between states based on the current symbol and the current state. If a DFA or NFA can reach an accepting state after reading an input string, then the string belongs to the regular language.

Overall, a regular language over an alphabet refers to a set of words or strings that can be described and recognized using regular expressions, deterministic finite automata, non-deterministic finite automata, or regular grammars.

Which of the given are correct?
  • a)
    Moore machine has 6-tuples
  • b)
    Mealy machine has 6-tuples
  • c)
    Both Mealy and Moore has 6-tuples
  • d)
    None of the mentioned
Correct answer is option 'C'. Can you explain this answer?

Preethi Basu answered
Introduction:
In the field of computer science, finite state machines (FSMs) are widely used for modeling and analyzing systems. Two common types of FSMs are Mealy machines and Moore machines. Both Mealy and Moore machines have 6-tuples, which define their behavior and structure.

Mealy Machines:
A Mealy machine is a type of finite state machine where the outputs are determined by both the current state and the input. The 6-tuple representation of a Mealy machine consists of the following components:

1. Set of states: This defines the possible states that the machine can be in.
2. Set of input symbols: This represents the valid input symbols that the machine can receive.
3. Set of output symbols: This represents the valid output symbols that the machine can produce.
4. Transition function: This describes how the machine transitions from one state to another based on the current state and the input symbol.
5. Output function: This defines the output produced by the machine for each state and input symbol combination.
6. Initial state: This specifies the initial state of the machine.

Moore Machines:
A Moore machine is another type of finite state machine where the outputs are determined solely by the current state. The 6-tuple representation of a Moore machine includes the following components:

1. Set of states: This defines the possible states that the machine can be in.
2. Set of input symbols: This represents the valid input symbols that the machine can receive.
3. Set of output symbols: This represents the valid output symbols that the machine can produce.
4. Transition function: This describes how the machine transitions from one state to another based on the current state and the input symbol.
5. Output function: This defines the output produced by the machine for each state.
6. Initial state: This specifies the initial state of the machine.

Both Mealy and Moore Machines have 6-tuples:
Both Mealy and Moore machines have a 6-tuple representation because they share the same components, except for the output function. The output function in Mealy machines depends on both the current state and the input symbol, while in Moore machines, it depends only on the current state.

Therefore, it is correct to say that both Mealy and Moore machines have 6-tuples. The 6-tuple representation is essential for defining the behavior and structure of these machines, allowing for their analysis, simulation, and implementation in various applications.

Consider the language L = {an |n ≥ 0} ∪ {anbn| n ≥ 0} and the following statements.
I. L is deterministic context-free.
II. L is context-free but not deterministic context-free.
III. L is not LL(k) for any k.
Which of the above statements is/are TRUE?
  • a)
    I only
  • b)
    II only
  • c)
    I and III only
  • d)
    III only
Correct answer is option 'C'. Can you explain this answer?

Sudhir Patel answered
Concept:
Union of a Regular language and a Deterministic Context Free Language (DCFL) is a DCFL.
Explanation:
Statement I: TRUE.
L = {an |n ≥ 0} ∪ {anbn| n ≥ 0}
{an |n ≥ 0} is a regular language and {anbn| n ≥ 0} is a DCFL and hence, there Union would be a DCFL.
Statement II: FALSE.
L is DCFL then it is CFL too.
Statement III: TRUE
L cannot be LL(k) for any number of look-ahead. LL(k) cannot conclusively distinguish that whether the string to be parsed is from aor from anbn. Both have a common prefix.

A DFA cannot be represented in the following format
  • a)
    Transition graph
  • b)
    Transition Table
  • c)
    C code
  • d)
    None of the mentioned
Correct answer is option 'D'. Can you explain this answer?

Prerna Joshi answered
Explanation:

DFA Representation:
- A DFA (Deterministic Finite Automaton) can be represented in two main forms: Transition Graph and Transition Table.
- Transition Graph: A DFA can be represented using a graph where nodes represent states and edges represent transitions between states based on input symbols.
- Transition Table: A DFA can also be represented using a table that shows the transitions from one state to another based on input symbols.

Given Format:
- The given options in the question are Transition Graph, Transition Table, and C code.
- It is mentioned that a DFA cannot be represented in the given format, which is incorrect.

Correct Answer:
- The correct answer is "None of the mentioned."
- A DFA can be represented in the form of a Transition Graph, Transition Table, and even in C code.
- Transition Graph and Transition Table are commonly used representations of a DFA, while C code can also be used to implement a DFA.

Conclusion:
- In conclusion, a DFA can be represented in various formats such as Transition Graph, Transition Table, and C code, making the statement in the question incorrect.

For a give Moore Machine, Given Input=’101010’, thus the output would be of length:
  • a)
    |Input|+1
  • b)
    |Input|
  • c)
    |Input-1|
  • d)
    Cannot be predicted
Correct answer is option 'A'. Can you explain this answer?

I'm sorry, I cannot provide an answer without more information. A Moore Machine requires a transition diagram or table and an input sequence in order to determine the output sequence. Please provide more details.

Moore Machine is an application of:
  • a)
    Finite automata without input
  • b)
    Finite automata with output
  • c)
    Non Finite automata with output
  • d)
    None of the mentioned
Correct answer is option 'B'. Can you explain this answer?

Nisha Gupta answered
Moore Machine is an application of finite automata with output.

Finite automata are mathematical models that can be used to represent and analyze systems that have a finite number of states and transitions between those states. These systems can be used to solve various computational problems. Moore Machine is a specific type of finite automata that has an output function associated with each state.

Finite Automata with Output
Finite automata with output, also known as Moore Machines, are a type of computational model that extend the basic concept of finite automata by adding an output function. In a Moore Machine, the output is associated with each state, rather than each transition.

Working of Moore Machine
A Moore Machine consists of a set of states, a set of inputs, a set of outputs, and a set of transitions. The machine starts in a particular state, and based on the input received, it transitions to a new state. The output is determined by the current state.

The output function in a Moore Machine is defined as a mapping from states to outputs. When the machine transitions from one state to another, it produces an output based on the current state. The output is not affected by the input itself, only by the current state.

Application of Moore Machine
Moore Machines have various applications in computer science and engineering. Some of the common applications include:

1. Sequence Recognition: Moore Machines can be used to recognize and process sequences of inputs. They are often used in pattern recognition, language processing, and string matching algorithms.

2. Control Systems: Moore Machines can be used to model and control systems that have a finite number of states. They are commonly used in control systems to monitor and control the behavior of complex systems.

3. Digital Circuits: Moore Machines can be used to design and analyze digital circuits. They are used to model the behavior of sequential circuits, such as counters, flip-flops, and registers.

4. Communication Protocols: Moore Machines can be used to model and analyze communication protocols. They can be used to ensure reliable and efficient communication between different components of a system.

In conclusion, Moore Machines are an application of finite automata with output. They are used to model and analyze systems that have a finite number of states and transitions, and produce an output based on the current state. They have various applications in computer science and engineering, including sequence recognition, control systems, digital circuits, and communication protocols.

Consider the following statements.
I. If L1 ∪ L2 is regular, then both L1 and L2 must be regular.
II. The class of regular languages is closed under infinite union.
Which of the above statements is/are TRUE?
  • a)
    I only
  • b)
    II only
  • c)
    Both I and II
  • d)
    Neither I nor II
Correct answer is option 'D'. Can you explain this answer?

Sudhir Patel answered
Statement I: FALSE
If L1 ∪ L2 is regular, then neither L1 nor L2 needs necessarily be regular.
Example:
Assume L1= {an bn, n ≥ 0} over the alphabet {a, b} and L2 be the complement of L1.
Neither Lnor L2 is regular (both are DCFL) but L1 ∪ L2= {an bn} ∪ {an bn}c = (a + b)is regular.
Statement II: FALSE. The infinite Union of regular languages is not regular.
Example:
Given alphabet {a, b}.
L1= {ε}
L2= {ab}
L3= {aabb}
L4= {aaabbb}
:
:
L = L1 ∪ L2 ∪ L∪ L4 …
Each of the above are regular but their infinite Union gives L1= {an bn, n ≥ 0} which is not regular but DCFL.
Note:
DCFL → Deterministic context free language

Language L1 is defined by the grammar: S1 → aS1b|ϵ
Language L2 is defined by the grammar: S2 → abS2
Consider the following statements:
P: L1 is regular
Q: L2 is regular
Which one of the following is TRUE?
  • a)
    Both P and Q are true
  • b)
    P is true and Q is false
  • c)
    P is false and Q is true
  • d)
    Both P and Q are false
Correct answer is option 'C'. Can you explain this answer?

Sudhir Patel answered
Suppose grammar G1:
S1 → aS1b|ϵ
It generates language in which number of a’s are equal to number of b’s and all a’s are followed by b’s
L1 = { abn | n ≥ 0}.
It is deterministic context free language. Extra memory is required for this. So, it can’t be accepted by finite state automata. L1 is not a regular language.
Now, another grammar let G2: S2 → abS2
This grammar also generates language in which number of a’s are equal to number of b’s. But it generates language L2 = { (ab)n | n ≥ 0 }
Regular expression for this = (ab)*
It doesn’t require any extra memory to remember the last string. It can be accepted by finite state automata. So, L2 is regular.

Chapter doubts & questions for Theory of Computation - GATE Computer Science Engineering(CSE) 2026 Mock Test Series 2026 is part of Computer Science Engineering (CSE) exam preparation. The chapters have been prepared according to the Computer Science Engineering (CSE) exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Computer Science Engineering (CSE) 2026 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of Theory of Computation - GATE Computer Science Engineering(CSE) 2026 Mock Test Series in English & Hindi are available as part of Computer Science Engineering (CSE) exam. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.

Top Courses Computer Science Engineering (CSE)