0% found this document useful (0 votes)
34 views42 pages

TCS Solved Question Paper

Uploaded by

Omkar Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views42 pages

TCS Solved Question Paper

Uploaded by

Omkar Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

TCS Solved Question paper 2022 April

Q1) attempt any 8 for each 1 marks

a) If A = {} Find the value of |A|.


b) List all the proper suffixes of the string "0123".
c) Define Useless symbol.
d) Give formal definition of Turning Machine.
e) Define left linear grammar.
f) State True or False. DFA do not have multiple final states.
g) Name the type of language accepted by Pushdown Automata.
h) Write the tuples of LBA.
i) State true or false. Pumping lemma is used to show that language is not context tree.
j) Write smallest possible string accepted by the following regular expression. a(a+b)*ab

Answer :

a) If A = {} Find the value of |A|.

● |A| = 1. The cardinality (size) of a set containing only the empty string is 1.

b) List all the proper suffixes of the string "0123".

● Proper suffixes are substrings that start from a position other than the beginning of the
string.
○ 123
○ 23
○ 3

c) Define Useless symbol.

● A symbol in a grammar is considered useless if it cannot be part of any derivation of a


terminal string. In other words, it's a symbol that doesn't contribute to the language
generated by the grammar.

d) Give formal definition of Turing Machine.

A Turing Machine (TM) is a mathematical model of computation that consists of the following
components:

● Tape: An infinite tape divided into cells, each capable of holding a single symbol from a
finite alphabet.
● Head: A read/write head that can move left or right along the tape, one cell at a time.
● States: A finite set of states that the TM can be in.
● Transition Function: A function that determines the next state, the symbol to write on
the tape, and the direction of the head movement based on the current state and the
symbol read from the tape.
● Start State: The initial state of the TM.
● Accept State(s): A set of states that, if the TM enters one of them, it halts and accepts
the input.
● Reject State(s): A set of states that, if the TM enters one of them, it halts and rejects the
input.

e) Define left linear grammar.

A left-linear grammar is a formal grammar where all production rules are of the form:

● A → aB
● A→a

where A and B are variables, and a is a terminal symbol or the empty string (ε).

f) State True or False. DFA do not have multiple final states.

● False. A DFA can have multiple final states. Each final state represents a possible
accepting configuration of the automaton.

g) Name the type of language accepted by Pushdown Automata.

● Context-free languages.

h) Write the tuples of LBA.

A Linear Bounded Automaton (LBA) is a tuple M = (Q, Σ, Γ, δ, q0, B, F), where:

● Q is a finite set of states.


● Σ is a finite input alphabet.
● Γ is a finite tape alphabet (Γ ⊇ Σ).
● δ is the transition function: δ: Q × Γ → Q × Γ × {L, R}.
● q0 ∈ Q is the start state.
● B ∈ Γ is the blank symbol.
● F ⊆ Q is the set of final states.

i) State true or false. Pumping lemma is used to show that language is not context-free.

● True. The pumping lemma is a technique used to prove that a language is not
context-free by demonstrating that it violates a certain property inherent to context-free
languages.

*j) Write smallest possible string accepted by the following regular expression. a(a+b)ab
● The smallest string that matches the regular expression is "aab".

Q2) attempt any 4 for each 2 marks

a) Explain types of grammar.


b) Construct FA for regular expression. (1+0)*0
c) Differentiate between CNF and GNF (any two points).
e) Define types of Turing Machine.

Answer :

a) Types of Grammar in Theoretical Computer Science

Chomsky Hierarchy categorizes grammars into four types based on the complexity of their
production rules:

1. Type 0 (Unrestricted Grammar):

○ No restrictions on production rules.


○ Recognizable by Turing Machines.
○ Generates recursively enumerable languages.
2. Type 1 (Context-Sensitive Grammar):

○ Production rules are of the form: αAβ → αγβ, where α, β, γ are strings of
symbols, and A is a non-terminal.
○ Recognizable by Linear Bounded Automata.
○ Generates context-sensitive languages.
3. Type 2 (Context-Free Grammar):

○ Production rules are of the form: A → α, where A is a non-terminal and α is a


string of terminals and non-terminals.
○ Recognizable by Pushdown Automata.
○ Generates context-free languages.
4. Type 3 (Regular Grammar):

○ Production rules are of the form: A → aB or A → a, where A and B are


non-terminals and a is a terminal.
○ Recognizable by Finite Automata.
○ Generates regular languages.

b) Construct FA for regular expression (1+0)0


c) Differentiate between CNF and GNF (any two points)

● Chomsky Normal Form (CNF):


○ All production rules are of the form A → BC or A → a, where A, B, C are
non-terminals and a is a terminal.
○ Useful for parsing algorithms and theoretical analysis.
● Greibach Normal Form (GNF):
○ All production rules are of the form A → aα, where A is a non-terminal, a is a
terminal, and α is a (possibly empty) string of non-terminals.
○ Useful for proving properties of context-free languages and designing parsing
algorithms.

d) Define Types of Turing Machine

1. Deterministic Turing Machine (DTM):

○ For a given input symbol and current state, there is exactly one possible
transition.
2. Non-deterministic Turing Machine (NTM):

○ For a given input symbol and current state, there may be multiple possible
transitions.
3. Multi-tape Turing Machine:

○ Uses multiple tapes to perform computations.


4. Multi-head Turing Machine:

○ Uses multiple heads on a single tape to read and write.


5. Oracle Turing Machine:

○ A theoretical machine that has access to an oracle, which can solve any
decidable problem in a single step

Q3) attempt any 2 for each 4 marks

a) Construct a DFA for a language L1L2 L1={All strings starting with 'a'} L2={All strings not
having 'ab' as substring}
b) Construct the following CFG intNormal Form (CNF) S–>aSa | bSb S–>a |b| aa | bb
c) Design TM for language, L={WCWR|W is in (0+1)*}

Answer :

a) DFA for L1 ∩ L2

To construct the DFA for the intersection of L1 and L2, we can combine the DFAs for each
language.

DFA for L1:


DFA for L2:

DFA for L1 ∩ L2:

The DFA for the intersection will have the same states as the product of the two individual
DFAs. A state in the product DFA is a pair of states, one from each individual DFA. The
transition function of the product DFA will be defined such that it simulates the transitions of both
individual DFAs simultaneously. The final states of the product DFA will be the pairs of states
where both individual states are final.

b) Converting CFG to CNF

The given CFG is already in CNF. All production rules are of the form A -> BC or A -> a, where
A, B, C are non-terminals and a is a terminal.

c) Turing Machine for L = {WCWR | W ∈ {0, 1}*}

Here's a high-level description of a Turing Machine to recognize the language L:

1. Initial State:

○ Scan the tape from left to right until the first '1' is encountered.
○ Mark the position of the first '1' with a special symbol (e.g., 'X').
2. Matching Phase:

○Move the tape head one position to the right.


○Compare the symbol under the head with the symbol to the right of the marked
position.
○ If they match, continue to the next symbol.
○ If they don't match, reject the input.
3. Reversing Phase:

○Once the end of the input is reached, move the tape head back to the marked
position.
○ Move the tape head one position to the right.
○ Compare the symbol under the head with the symbol to the left of the marked
position.
○ If they match, continue to the next symbol.
○ If they don't match, reject the input.
4. Acceptance:

○ If the tape head reaches the end of the input without any mismatches, accept the
input.

Formal Definition of the Turing Machine:

M = (Q, Σ, Γ, δ, q0, B, F)

● Q = {q0, q1, q2, q3, q4, q5, q6}


● Σ = {0, 1}
● Γ = {0, 1, X, B}
● δ = ... (transition function, defined based on the above description)
● q0 = initial state
● B = blank symbol
● F = {q6} (final state)

The detailed transition function can be defined based on the steps described above. The Turing
Machine will systematically scan the tape, mark the middle, and compare the symbols on either
side to ensure the palindrome property

Q4) attempt any 2 for each 4 marks

a) Construct a PDA for the language L={a n bn cn |n>=0}.


b) Construct a Moore machine for the language L over = {0,1} which outputs '*' if the string
contains '11' in it and outputs '#' otherwise.
c) Compare DFA and NFA

Answer :

a) PDA for L = {a^n b^n c^n | n >= 0}

A PDA can recognize this language by pushing 'a' symbols onto the stack for each 'a' input, then
popping one 'a' for each 'b' input, and finally popping one 'c' for each 'c' input. If the stack is
empty at the end of the input, the string is accepted.

Formal Definition:

M = (Q, Σ, Γ, δ, q0, Z, F)

● Q = {q0, q1, q2, q3}


● Σ = {a, b, c}
● Γ = {a, Z}
● δ = { (q0, a, Z) -> (q1, aZ), (q1, a, a) -> (q1, aa), (q1, b, a) -> (q2, ε), (q2, b, a) -> (q2, ε),
(q2, c, a) -> (q3, ε), (q3, c, a) -> (q3, ε), (q3, ε, Z) -> (q3, ε) }
● q0 = initial state
● Z = stack symbol
● F = {q3} (final state)

b) Moore Machine for L = {strings containing '11'}

A Moore machine can recognize this language by keeping track of the last two input symbols. If
the last two symbols were both '1', the machine outputs '*'. Otherwise, it outputs '#'.

Formal Definition:

M = (Q, Σ, O, δ, q0, λ)

● Q = {q0, q1, q2}


● Σ = {0, 1}
● O = {'#', '*'}
● δ = { (q0, 0) -> (q0, '#'), (q0, 1) -> (q1, '#'), (q1, 0) -> (q0, '#'), (q1, 1) -> (q2, ''), (q2, 0) ->
(q0, '#'), (q2, 1) -> (q2, '') }
● q0 = initial state
● λ = output function (defined by the transition function)

c) Comparison of DFA and NFA

Feature DFA NFA

Each state has exactly one transition A state can have multiple transitions for a
Determinism for each input symbol. single input symbol.

More expressive power but can be harder to


Complexity Simpler to implement and analyze. implement and analyze.

A string is accepted if the DFA reaches


a final state after processing the entire A string is accepted if there exists at least one
Acceptance string. computation path that leads to a final state.

Every DFA can be converted to an


equivalent NFA, but not every NFA can Every NFA can be converted to an equivalent
Equivalence be converted to an equivalent DFA. DFA using the powerset construction.

Commonly used in lexical analysis and Often used as an intermediate step in compiler
Practical Use text processing. design and theoretical computer science.

Q5) attempt any 1 for 3 marks

a) Construct a Mealy machine over alphabet {0, 1} which toggles its input.
b) Show that L={0n 1n | n>=1} is not regular.

Answer :

a) Mealy Machine for Input Toggling


A Mealy machine is a finite state machine that produces an output based on the current state
and the current input. For the given problem, we can design a Mealy machine with two states:
one for the initial state and one for the toggled state.

Formal Definition:

M = (Q, Σ, O, δ, q0)

● Q = {q0, q1}
● Σ = {0, 1}
● O = {0, 1}
● δ = { (q0, 0) -> (q1, 1), (q0, 1) -> (q1, 0), (q1, 0) -> (q0, 1), (q1, 1) -> (q0, 0) }
● q0 = initial state

Explanation:

● State q0: If the input is 0, the machine transitions to state q1 and outputs 1. If the input
is 1, the machine transitions to state q1 and outputs 0.
● State q1: If the input is 0, the machine transitions to state q0 and outputs 1. If the input
is 1, the machine transitions to state q0 and outputs 0.

This Mealy machine effectively toggles the input bit at each step.

b) Proving L = {0^n 1^n | n >= 1} is Not Regular

We can use the Pumping Lemma to prove that L is not a regular language.

Pumping Lemma:

If L is a regular language, there exists a pumping length p such that any string s ∈ L with |s| ≥ p
can be written as s = xyz, where:

1. |xy| ≤ p
2. |y| ≥ 1
3. For all i ≥ 0, xy^iz ∈ L

Proof by Contradiction:

Assume L is regular. Let p be the pumping length. Consider the string s = 0^p 1^p ∈ L.

According to the Pumping Lemma, we can write s = xyz, where |xy| ≤ p and |y| ≥ 1.

Since |xy| ≤ p, y must consist only of 0s. Let y = 0^k, where k ≥ 1.

Now, consider the string xy^2z = 0^(p+k) 1^p. This string is not in L because the number of 0s
and 1s is not equal. This contradicts the Pumping Lemma, so our assumption that L is regular
must be false. Therefore, L is not a regular language
TCS Solved Question paper 2022 October

Q1) attempt any 8 for each 1 marks

a) Define Unit production of grammar.


b) Construct Melay machine which toggles its input.
c) Explain proper Suffix and Prefix of a string with one example.
d) Give formal definition of Push down Automata.
e) Define left linear and right linear grammar.
f) State True or False. Finite Automata has an infinite number of states.
g) Name the types of normal forms of grammar.
h) Write the tuples of LBA.
i) State true or false. Pumping lemma is used to show that language is not context tree.
j) Write smallest possible string accepted by the following regular expression. 10 + (0 + 11)0*1

Answer :

a) A unit production in a grammar is a production rule of the form A -> B, where A and B are
both non-terminal symbols.

b) A Mealy machine can be constructed with two states: one for the initial state and one for the
toggled state. The machine outputs the opposite of the input at each state transition.

c) A proper suffix of a string is a substring that starts from a position other than the beginning of
the string. For example, "xyz" is a proper suffix of "abcxyz". A proper prefix is a substring that
ends before the end of the string. For example, "ab" is a proper prefix of "abc".

d) A Pushdown Automaton (PDA) is a tuple M = (Q, Σ, Γ, δ, q0, Z, F), where Q is a finite set of
states, Σ is a finite input alphabet, Γ is a finite stack alphabet, δ is the transition function, q0 is
the initial state, Z is the initial stack symbol, and F is the set of final states.

e) A left linear grammar has production rules of the form A -> aB or A -> a. A right linear
grammar has production rules of the form A -> Ba or A -> a.

f) False. Finite Automata have a finite number of states.

g) Chomsky Normal Form (CNF) and Greibach Normal Form (GNF) are the two main types of
normal forms.

h) A Linear Bounded Automaton (LBA) is a tuple M = (Q, Σ, Γ, δ, q0, B, F), where Q is a finite
set of states, Σ is a finite input alphabet, Γ is a finite tape alphabet, δ is the transition function,
q0 is the start state, B is the blank symbol, and F is the set of final states.

i) True. The Pumping Lemma is used to prove that a language is not context-free.

j) The smallest possible string accepted by the regular expression 10 + (0 + 11)0*1 is "10".
Q2) attempt any 4 for each 2 marks

a) Explain types of grammar.


b) Construct FA for regular expression. (01+10)*+11
c) Differentiate between FA and PDA (any two points).
d) Write down the -closure of each state from the following FA.

e) Define types of Turing Machine.

Answer :

a) Types of Grammar

Chomsky Hierarchy categorizes grammars into four types based on the complexity of their
production rules:

1. Type 0 (Unrestricted Grammar):

○ No restrictions on production rules.


○ Recognizable by Turing Machines.
○ Generates recursively enumerable languages.
2. Type 1 (Context-Sensitive Grammar):

○ Production rules are of the form: αAβ → αγβ, where α, β, γ are strings of
symbols, and A is a non-terminal.
○ Recognizable by Linear Bounded Automata.
○ Generates context-sensitive languages.
3. Type 2 (Context-Free Grammar):

○ Production rules are of the form: A → α, where A is a non-terminal and α is a


string of terminals and non-terminals.
○ Recognizable by Pushdown Automata.
○ Generates context-free languages.
4. Type 3 (Regular Grammar):

○ Production rules are of the form: A → aB or A → a, where A and B are


non-terminals and a is a terminal.
○ Recognizable by Finite Automata.
○ Generates regular languages.

b) *Constructing FA for regular expression (01+10)+11


c) Difference between FA and PDA

Feature Finite Automata (FA) Pushdown Automata (PDA)

Memory No additional memory Uses a stack as additional memory

Language
Recognition Recognizes regular languages Recognizes context-free languages

Transition Depends only on the current state Depends on the current state, input
Function and input symbol symbol, and top stack symbol

Q3) attempt any 2 for each 4 marks

a) Construct a DFA for a language L1L2 L1= { All strings starting with ‘a’} L2= { All strings not
having ‘ab’ as substring}
b) Construct the following CFG into Normal Form (CNF) S-> ABA A-> aA | B-> bB |
c) Design TM for language, L {WCWR|W is in (0+1)*}

Answer :

a) DFA for L1 ∩ L2

To construct the DFA for the intersection of L1 and L2, we can combine the DFAs for each
language.

DFA for L1:


DFA for L2:

DFA for L1 ∩ L2:


The DFA for the intersection will have the same states as the product of the two individual
DFAs. A state in the product DFA is a pair of states, one from each individual DFA. The
transition function of the product DFA will be defined such that it simulates the transitions of both
individual DFAs simultaneously. The final states of the product DFA will be the pairs of states
where both individual states are final

b) Converting CFG to CNF

Step 1: Eliminate ε-productions:

S -> ABA | A | B | ε A -> aA | ε B -> bB | ε

Step 2: Eliminate unit productions:

S -> ABA | aA | bB | a | b A -> aA | a B -> bB | b

Step 3: Introduce new variables for long right-hand sides:

S -> AC | AD | a | b A -> aA | a B -> bB | b C -> AB D -> BA

Now, the grammar is in CNF.

c) Turing Machine for L = {WCWR | W ∈ {0, 1}*}

Here's a high-level description of a Turing Machine to recognize the language L:

1. Initial State:

○ Scan the tape from left to right until the first '1' is encountered.
○ Mark the position of the first '1' with a special symbol (e.g., 'X').
2. Matching Phase:

○Move the tape head one position to the right.


○Compare the symbol under the head with the symbol to the right of the marked
position.
○ If they match, continue to the next symbol.
○ If they don't match, reject the input.
3. Reversing Phase:

○ Once the end of the input is reached, move the tape head back to the marked
position.
○ Move the tape head one position to the right.
○ Compare the symbol under the head with the symbol to the left of the marked
position.
○ If they match, continue to the next symbol.
○ If they don't match, reject the input.
4. Acceptance:

○ If the tape head reaches the end of the input without any mismatches, accept the
input.

Formal Definition of the Turing Machine:

M = (Q, Σ, Γ, δ, q0, B, F)

● Q = {q0, q1, q2, q3, q4, q5, q6}


● Σ = {0, 1}
● Γ = {0, 1, X, B}
● δ = ... (transition function, defined based on the above description)
● q0 = initial state
● B = blank symbol
● F = {q6} (final state)

The detailed transition function can be defined based on the steps described above. The Turing
Machine will systematically scan the tape, mark the middle, and compare the symbols on either
side to ensure the palindrome property.

Q4) attempt any 2 for each 4 marks

a) Construct a PDA for the language L = {0 n 1 m 2 n+m | n,m>=1}


b) Construct a Moore machine for the language L over = {0, 1 } which outputs ‘*’ if the string
contains ‘11’ in it and outputs ‘#’ otherwise.
c) Compare DFA and NFA

Answer :

a) PDA for L = {0^n 1^m 2^(n+m) | n, m >= 1}

A PDA can recognize this language by pushing '0' symbols onto the stack for each '0' input, then
pushing '1' symbols for each '1' input. After reading all '1's, it pops a '0' and a '1' for each '2'
input. If the stack is empty at the end of the input, the string is accepted.

Formal Definition:

M = (Q, Σ, Γ, δ, q0, Z, F)

● Q = {q0, q1, q2, q3}


● Σ = {0, 1, 2}
● Γ = {0, 1, Z}
● δ = { (q0, 0, Z) -> (q1, 0Z), (q1, 0, 0) -> (q1, 00), (q1, 1, 0) -> (q2, 1), (q2, 1, 1) -> (q2,
11), (q2, 2, 1) -> (q3, ε), (q3, 2, 0) -> (q3, ε), (q3, ε, Z) -> (q3, ε) }
● q0 = initial state
● Z = stack symbol
● F = {q3} (final state)

b) Moore Machine for L = {strings containing '11'}

A Moore machine can recognize this language by keeping track of the last two input symbols. If
the last two symbols were both '1', the machine outputs '*'. Otherwise, it outputs '#'.

Formal Definition:

M = (Q, Σ, O, δ, q0, λ)

● Q = {q0, q1, q2}


● Σ = {0, 1}
● O = {'#', '*'}
● δ = { (q0, 0) -> (q0, '#'), (q0, 1) -> (q1, '#'), (q1, 0) -> (q0, '#'), (q1, 1) -> (q2, ''), (q2, 0) ->
(q0, '#'), (q2, 1) -> (q2, '') }
● q0 = initial state
● λ = output function (defined by the transition function)

c) Comparison of DFA and NFA

Feature Finite Automata (FA) Pushdown Automata (PDA)


Uses a stack as additional
Memory No additional memory memory

Language Recognizes regular Recognizes context-free


Recognition languages languages

Depends only on the Depends on the current state,


Transition current state and input input symbol, and top stack
Function symbol symbol

Q5) attempt any 1 for 3 marks

a) Construct a Mealy machine to convert each occurrence of substring 101 by 100 over
alphabet {0,1}.
b) Show that L = {0n 1n | n>=1} is not regular.

Answer :
a) Mealy Machine to Convert 101 to 100

To convert 101 to 100, we can design a Mealy machine with four states:

1. q0: Initial state, waiting for the first 1.


2. q1: Reached after seeing the first 1.
3. q2: Reached after seeing 10.
4. q3: Reached after seeing 101.

Formal Definition:

M = (Q, Σ, O, δ, q0)

● Q = {q0, q1, q2, q3}


● Σ = {0, 1}
● O = {0, 1}
● δ = { (q0, 0) -> (q0, 0), (q0, 1) -> (q1, 1), (q1, 0) -> (q2, 0), (q1, 1) -> (q0, 1), (q2, 0) ->
(q3, 0), (q2, 1) -> (q1, 1), (q3, 0) -> (q0, 0), (q3, 1) -> (q1, 1) }
● q0 = initial state

Explanation:

● State q0: If the input is 0, the machine stays in q0 and outputs 0. If the input is 1, it
transitions to q1 and outputs 1.
● State q1: If the input is 0, it transitions to q2 and outputs 0. If the input is 1, it goes back
to q0 and outputs 1.
● State q2: If the input is 0, it transitions to q3 and outputs 0 (converting 101 to 100). If the
input is 1, it goes back to q1 and outputs 1.
● State q3: If the input is 0 or 1, it goes back to q0 and outputs the same input.

b) Proving L = {0^n 1^n | n >= 1} is Not Regular

We can use the Pumping Lemma to prove that L is not a regular language.

Pumping Lemma:

If L is a regular language, there exists a pumping length p such that any string s ∈ L with |s| ≥ p
can be written as s = xyz, where:

1. |xy| ≤ p
2. |y| ≥ 1
3. For all i ≥ 0, xy^iz ∈ L

Proof by Contradiction:

Assume L is regular. Let p be the pumping length. Consider the string s = 0^p 1^p ∈ L.
According to the Pumping Lemma, we can write s = xyz, where |xy| ≤ p and |y| ≥ 1.

Since |xy| ≤ p, y must consist only of 0s. Let y = 0^k, where k ≥ 1.

Now, consider the string xy^2z = 0^(p+k) 1^p. This string is not in L because the number of 0s
and 1s is not equal.

This contradicts the Pumping Lemma, so our assumption that L is regular must be false.
Therefore, L is not a regular language.
TCS Solved Question paper 2023 April

Q1) attempt any 8 for each 1 marks

a) Write output function λ of Moore and Mealy machines.


b) List all the proper prefixes of the string “ABCD’.
c) Define Nullable symbol.
d) Give formal definition of Pushdown Automata.
e) Define right linear grammar.
f) State True or False. DFA do not have multiple final states.
g) Name the type of language accepted by Turing Machine.
h) Write the tuples of LBA.
i) State true or false. Pumping lemma is used to show that language is not context tree.
j) Write smallest possible string accepted by the following regular expression. l0+(0+l 1)0*1

Answer :

a) Output Function

Moore Machine:

● The output function, λ, maps the current state to an output symbol.


● λ : Q → Σₒ Where:
○ Q is the set of states
○ Σₒ is the output alphabet

Mealy Machine:

● The output function, λ, maps the current state and the input symbol to an output symbol.
● λ : Q × Σᵢ → Σₒ Where:
○ Q is the set of states
○ Σᵢ is the input alphabet
○ Σₒ is the output alphabet

b) Proper Prefixes of "ABCD"

● "", "A", "AB", "ABC"

c) Nullable Symbol

A nullable symbol in a grammar is a non-terminal symbol that can derive the empty string (ε).

d) Formal Definition of Pushdown Automata

A Pushdown Automaton (PDA) is a 7-tuple (Q, Σ, Γ, δ, q₀, Z₀, F), where:


● Q is a finite set of states
● Σ is a finite input alphabet
● Γ is a finite stack alphabet
● δ is the transition function: δ : Q × (Σ ∪ {ε}) × Γ → 2^(Q × Γ*)

● q₀ ∈ Q is the initial state
● Z₀ ∈ Γ is the initial stack symbol
● F ⊆ Q is the set of final states

e) Right Linear Grammar

A right-linear grammar is a formal grammar where all production rules are of the form:

● A → aB or A → a where:
○ A and B are non-terminal symbols
○ a is a terminal symbol or ε (the empty string)

f) True. DFAs do not have multiple final states. A DFA accepts a string if and only if it reaches a
single final state after processing the entire string.

g) Recursively Enumerable Languages. Turing Machines can recognize recursively


enumerable languages, which include all computable languages.

h) Tuples of LBA

A Linear Bounded Automaton (LBA) is a 7-tuple (Q, Σ, Γ, δ, q₀, Z₀, F), where:

● Q is a finite set of states


● Σ is a finite input alphabet
● Γ is a finite tape alphabet (Γ ⊇ Σ)
● δ is the transition function: δ : Q × Γ → 2^(Q × Γ × {L, R})
● q₀ ∈ Q is the initial state
● Z₀ ∈ Γ is the blank symbol
● F ⊆ Q is the set of final states

i) False. The pumping lemma is used to show that a language is not regular, not context-free.

j) Smallest Possible String

The smallest possible string accepted by the regular expression l0+(0+l 1)0*1 is "l01".

Q2) attempt any 4 for each 2 marks

a) Explain Reduction with the help of example.


b) Construct FA for regular expression. (0l+l0)*+ 11
c) Differentiate between DFA and NFA.
d) Write down the ∈-closure of each state from the following FA

e) Define types of Turing Machine.

Answer :

a) Reduction

Reduction is a technique used in formal language theory to simplify a grammar by eliminating


redundant or unnecessary productions. It involves applying a series of reduction rules to the
grammar until no further reductions are possible.

Example:

Consider the following grammar:

S -> AB | a
A -> Aa | b
B -> Bb | c

We can reduce this grammar by eliminating the redundant production A -> Aa:

S -> AB | a
A -> b
B -> Bb | c

*b) Constructing FA for Regular Expression (0l+l0)+ 11

Step 1: Construct NFA

1. Create states:

○ q0: Initial state


○ q1: Intermediate state
○ q2: Final state
2. Add transitions:
○ q0 -> q1 on input 0 or 1
○ q1 -> q0 on input 0 or 1
○ q0 -> q2 on input 1
○ q2 -> q2 on input 1

Step 2: Convert NFA to DFA (using subset construction)

1. Initial state: {q0}


2. Epsilon closure of {q0}: {q0}
3. Transition on 0: {q0, q1}
4. Epsilon closure of {q0, q1}: {q0, q1}
5. Transition on 1: {q0, q2}
6. Epsilon closure of {q0, q2}: {q0, q2}

DFA:

States: {q0}, {q0, q1}, {q0, q2}


Initial state: {q0}
Final state: {q0, q2}
Transitions:
{q0} --0--> {q0, q1}
{q0} --1--> {q0, q2}
{q0, q1} --0--> {q0, q1}
{q0, q1} --1--> {q0, q2}
{q0, q2} --0--> {q0, q1}
{q0, q2} --1--> {q0, q2}

c) DFA vs NFA

Feature DFA NFA

Definition Deterministic Finite Automaton Non-deterministic Finite Automaton

Transition For each state and input symbol, there is For each state and input symbol, there can
Function exactly one transition. be zero, one, or multiple transitions.
A string is accepted if and only if there is a A string is accepted if there is at least one
unique path from the initial state to a final path from the initial state to a final state that
Acceptance state that corresponds to the string. corresponds to the string.

More powerful but can be more complex to


Complexity Simpler to implement and analyze. analyze.

Often used as an intermediate step in the


Used for lexical analysis in compilers and design of more complex automata, such as
Practical Use text processing tools. pushdown automata.

d) Epsilon Closure

Epsilon closure of a state is the set of states that can be reached from that state using only
epsilon transitions.

Step-by-Step Calculation

1. Epsilon Closure(q0):

● Start at q0.
● Follow epsilon transitions from q0: We can reach q1 and q2.
● So, Epsilon Closure(q0) = {q0, q1, q2}

2. Epsilon Closure(q1):

● Start at q1.
● Follow epsilon transitions from q1: We can reach q2.
● So, Epsilon Closure(q1) = {q1, q2}

3. Epsilon Closure(q2):

● Start at q2.
● There are no epsilon transitions from q2.
● So, Epsilon Closure(q2) = {q2}

Summary:

● Epsilon Closure(q0) = {q0, q1, q2}


● Epsilon Closure(q1) = {q1, q2}
● Epsilon Closure(q2) = {q2}
There are primarily two types of Turing Machines based on their acceptance criteria:

e) 1. Accepting Turing Machine:

● It accepts an input string if it reaches a final state after processing the entire input.
● The machine halts in an accepting state.

2. Rejecting Turing Machine:

● It rejects an input string if it halts in a non-final state after processing the entire input.
● The machine halts in a non-accepting state.

Additionally, based on the number of tapes:

1. Single-Tape Turing Machine:

● It has a single tape for both input and work.

2. Multi-Tape Turing Machine:

● It has multiple tapes, each with its own head.


● This allows for more complex computations and simulations of other computational
models.

It's important to note that while multi-tape Turing Machines can be more powerful in terms of
computational efficiency, they are equivalent in terms of computational power to single-tape
Turing Machines. Any computation that can be performed by a multi-tape Turing Machine can
also be performed by a single-tape Turing Machine, albeit potentially less efficiently.

Q3) attempt any 2 for each 4 marks

a) Construct a DFA for a language over Σ = {0,1 } L1∩L2 L1 = { All strings starting with ‘0’} L2 = {
All strings not having ‘01’ as substring}
b) Construct the following CFG int Normal Form (CNF) S-> aSa | bSb | a | b| aa | bb
c) Construct TM which accepts the language that start with 0 and ends with 1.

Answer :

a) DFA for L1 ∩ L2

Understanding L1 and L2:

● L1: All strings starting with '0'.


● L2: All strings without the substring '01'.
Constructing the DFA:

To construct the DFA for L1 ∩ L2, we need to combine the conditions of both languages:

1. Initial state: The initial state must be reachable only by reading a '0'.
2. Accepting states: The DFA should accept any string that starts with '0' and doesn't
have the substring '01'.

Here's the DFA:

0
-->q0----->q1
^ | |
| | |
| v v
| q2-----q3
1

Explanation:

● q0: Initial state. Only reachable by reading '0'.


● q1: Accepting state. Reached after reading '0' and any number of '1's.
● q2: Non-accepting state. Reached if '01' is encountered.
● q3: Non-accepting state. Reached if '1' is encountered after '0'.

b) Converting CFG to CNF

Given CFG:

S -> aSa | bSb | a | b | aa | bb

CNF Conversion:

1. Eliminate ε-productions: There are no ε-productions.

2. Eliminate unit productions: There are no unit productions.

Convert to Chomsky Normal Form:

S -> AB | CD | E | F | G | H
A -> aS
B -> a
C -> bS
D -> b
E -> aa
F -> bb
G -> a
H -> b

3.

c) Turing Machine for Language Starting with 0 and Ending with 1

Here's a simple Turing Machine to accept the language:

Q = {q0, q1, q2, q3} // States


Σ = {0, 1} // Input alphabet
Γ = {0, 1, B} // Tape alphabet
δ = transition function (defined below)
q0 = initial state
B = blank symbol
F = {q3} // Final state

Transition Function δ:

δ(q0, 0) = (q1, 0, R) // Move right if first symbol is 0


δ(q0, 1) = (q3, 1, R) // Reject if first symbol is 1
δ(q1, 0) = (q1, 0, R) // Keep moving right if 0
δ(q1, 1) = (q2, 1, R) // Move to q2 if 1 is encountered after 0
δ(q2, 1) = (q2, 1, R) // Keep moving right if 1
δ(q2, B) = (q3, B, S) // Accept if end of tape is reached after 1

Explanation:

1. Initial state (q0): If the first symbol is '0', move to state q1. If the first symbol is '1', reject.
2. State q1: Keep moving right while reading '0'. If '1' is encountered, move to state q2.
3. State q2: Keep moving right while reading '1'. If the end of the tape is reached, accept.
4. State q3: Reject state.

Q4) attempt any 2 for each 4 marks

a) Construct a PDA for the language L = {an bn |n>=1}


b) Construct a Mealy machine for the language L over Σ = {0, 1} which outputs ‘A’ if it has
substring ‘101’. it outputs ‘B’ if it has substring ‘110’, otherwise it outputs ‘C’.
c) Write a short note on Chomsky’s hierarchy.
Answer :

a) PDA for L = {anbn | n >= 1}

A PDA for this language can be constructed as follows:

Q = {q0, q1, q2} // States


Σ = {a, b} // Input alphabet
Γ = {A} // Stack alphabet
δ = transition function (defined below)
q0 = initial state
Z0 = A // Initial stack symbol
F = {q2} // Final state

Transition Function δ:

δ(q0, a, A) = {(q0, AA)} // Push A onto the stack


δ(q0, a, B) = ∅ // Error state
δ(q0, b, A) = ∅ // Error state
δ(q1, a, A) = ∅ // Error state
δ(q1, b, A) = {(q1, ε)} // Pop A from the stack
δ(q1, b, B) = ∅ // Error state
δ(q0, ε, A) = {(q1, ε)} // Transition to q1 without reading input

Explanation:

1. Initial state (q0): Push 'A' onto the stack for each 'a' read.
2. State q1: Pop 'A' from the stack for each 'b' read.
3. Final state (q2): Reached after all 'a's and 'b's are matched.

b) Mealy Machine for the Given Language

Q = {q0, q1, q2, q3} // States


Σ = {0, 1} // Input alphabet
Σo = {A, B, C} // Output alphabet
δ = transition function (defined below)
q0 = initial state

Transition Function δ:

δ(q0, 0) = (q0, C)
δ(q0, 1) = (q1, C)
δ(q1, 0) = (q2, A)
δ(q1, 1) = (q3, C)
δ(q2, 0) = (q0, C)
δ(q2, 1) = (q1, B)
δ(q3, 0) = (q0, C)
δ(q3, 1) = (q3, C)

Explanation:

● The machine starts in state q0.


● It transitions to different states based on the input and outputs the corresponding
symbol.
● If '101' is encountered, the machine outputs 'A'.
● If '110' is encountered, the machine outputs 'B'.
● Otherwise, it outputs 'C'.

c) Chomsky's Hierarchy

Chomsky's hierarchy is a classification of formal grammars and languages based on their


generative power. It consists of four types of grammars, from the most restrictive to the most
expressive:

1. Type 3 (Regular Grammars):


○ Generate regular languages.
○ Production rules are of the form A -> aB or A -> a, where A and B are
non-terminal symbols and a is a terminal symbol or ε.
2. Type 2 (Context-Free Grammars):
○ Generate context-free languages.
○ Production rules are of the form A -> α, where A is a non-terminal symbol and α
is a string of terminals and non-terminals.
3. Type 1 (Context-Sensitive Grammars):
○ Generate context-sensitive languages.
○ Production rules are of the form αAβ -> αγβ, where A is a non-terminal symbol
and α, β, and γ are strings of terminals and non-terminals.
4. Type 0 (Unrestricted Grammars):
○ Generate recursively enumerable languages.
○ There are no restrictions on the form of production rules.

This hierarchy provides a framework for understanding the complexity of formal languages and
the computational power required to recognize and generate them.
Q5) attempt any 1 for 3 marks

a) Construct a Moore machine over alphabet {0,1} to get l’s compliment of a given binary string.
b) Show that L = {0n 1n | n>=1} is not regular

Answer :

a) Moore Machine for 1's Complement

Understanding the Problem:

● We need a Moore machine that outputs the 1's complement of the input binary string.
● In a Moore machine, the output is solely determined by the current state.

Designing the Moore Machine:

We can design a Moore machine with two states:

● q0: Initial state, output 0.


● q1: State after reading '1', output 1.

Transition Function:

State Input Next State Output


q0 0 q0 1
q0 1 q1 0
q1 0 q1 1
q1 1 q0 0

Explanation:

● Initial State (q0): If the input is '0', the output is '1' and the machine stays in state q0. If
the input is '1', the output is '0' and the machine transitions to state q1.
● State q1: If the input is '0', the output is '1' and the machine stays in state q1. If the input
is '1', the output is '0' and the machine transitions back to state q0.

This Moore machine will output the 1's complement of the input binary string.

b) Proving L = {0^n 1^n | n >= 1} is Not Regular

We can use the Pumping Lemma to prove that L is not regular.


Pumping Lemma: If L is regular, there exists a pumping length p such that any string s in L with
|s| ≥ p can be written as s = xyz, where:

1. |xy| ≤ p
2. |y| ≥ 1
3. For all i ≥ 0, xy^iz ∈ L

Proof by Contradiction:

Assume L is regular. Let p be the pumping length. Consider the string s = 0^p 1^p.

According to the Pumping Lemma, we can write s = xyz, where |xy| ≤ p and |y| ≥ 1.

Since |xy| ≤ p, y must consist only of 0s.

Now, let's pump y twice: xy^2z. This string will have more 0s than 1s, and thus, it does not
belong to L.

This contradicts the Pumping Lemma, and therefore, our assumption that L is regular must be
false.

Hence, L = {0^n 1^n | n >= 1} is not a regular language.


TCS Solved Question paper 2023 October

Q1) attempt any 8 for each 1 marks

a) Write the smallest possible string accepted by regular expression. 01 (0 + 1) 01*.


b) State True or False. PDA accepts only non-regular sets.
c) Define ambiguous grammar.
d) What are the types of grammar in Chomsky hierarchy?
e) What is Reduction?
f) State True or False. String consists of only Non-Terminal symbol.
g) Define non-deterministic Turing machine.
h) If A = {} find the value of | A |.
i) Write down the -closure of each state from the following FA.

j) State two differences between NFA and DFA.

Answer :

a) Smallest possible string accepted by regular expression 01(0+1)01*

The smallest possible string is 0101.

b) State True or False. PDA accepts only non-regular sets.

False. While PDAs can accept some non-regular languages, they can also accept regular
languages.

c) ambiguous grammar.

An ambiguous grammar is a context-free grammar that generates a string in multiple ways, i.e.,
there are two or more distinct parse trees for the same string.

d) types of grammar in Chomsky hierarchy

1. Type 0 (Unrestricted Grammar): Most general type of grammar, generating recursively


enumerable languages.
2. Type 1 (Context-Sensitive Grammar): Generates context-sensitive languages.
3. Type 2 (Context-Free Grammar): Generates context-free languages.
4. Type 3 (Regular Grammar): Generates regular languages.

e) What is Reduction?
Reduction is a technique used in formal language theory to simplify a grammar by eliminating
redundant or unnecessary productions.

f) State True or False. String consists of only Non-Terminal symbol.

False. A string in a formal language consists of only terminal symbols.

g) non-deterministic Turing machine.

A non-deterministic Turing machine is a Turing machine that has multiple possible transitions for
a given state and input symbol. This allows it to explore multiple computation paths
simultaneously.

h) If A = {} find the value of | A |.

The cardinality of the empty set is 0, so |A| = 0.

i)

The epsilon closure of a state is the set of all states that can be reached from that state by
following zero or more epsilon transitions.

Epsilon Closures for the given FA:

Epsilon Closure(A) = {A, B, C}

Epsilon Closure(B) = {B, C}

Epsilon Closure(C) = {C}

Q2) attempt any 4 for each 2 marks

a) Explain two methods for defining language. Accepted by PDA.


b) Explain types of regular grammar.
c) Construct FA for regular expression ((1+0)* + 100)*.
d) Differentiate between Moore and Melay Machine.
e) State two differences between TM and LBA.

Answer :

a) Two Methods for Defining Languages Accepted by PDA

1. Direct Definition:

○ Explicitly define the language by specifying the set of strings that the PDA
accepts. For example, the language L = {a^n b^n | n >= 0} can be directly defined
as the set of all strings with an equal number of 'a's followed by an equal number
of 'b's.
2. Grammar Definition:

○ Use a context-free grammar to generate the language. The PDA can then be
constructed to recognize the strings generated by the grammar. For example, the
grammar S -> aSb | ε generates the language L = {a^n b^n | n >= 0}.

b) Types of Regular Grammar

Regular grammars are categorized into two types:

1. Right-Linear Grammar:

○ Production rules are of the form A -> aB or A -> a, where A and B are
non-terminal symbols and a is a terminal symbol.
○ Examples:
■ S -> 0A | 1B
■ A -> 0A | 1B | ε
■ B -> 0B | 1B | ε
2. Left-Linear Grammar:

○ Production rules are of the form A -> Ba or A -> a, where A and B are
non-terminal symbols and a is a terminal symbol.
○ Examples:
■ S -> A0 | B1
■ A -> A0 | A1 | ε
■ B -> B0 | B1 | ε

c) Constructing FA for Regular Expression ((1+0) + 100)**

Step 1: Construct NFA

1. Create states:

○ q0: Initial state


○ q1: Intermediate state
○ q2: Final state
2. Add transitions:

○ q0 -> q1 on input 0 or 1
○ q1 -> q1 on input 0 or 1
○ q1 -> q2 on input 0
○ q2 -> q0 on input 0
Step 2: Convert NFA to DFA (using subset construction)

DFA:

States: {q0}, {q1}, {q0, q1}


Initial state: {q0}
Final state: {q0, q1}
Transitions:
{q0} --0--> {q0, q1}
{q0} --1--> {q1}
{q1} --0--> {q0, q1}
{q1} --1--> {q1}
{q0, q1} --0--> {q0, q1}
{q0, q1} --1--> {q1}

d) Moore and Mealy Machines

Moore Machine:

● Output is solely determined by the current state.


● Output function: λ : Q -> Σₒ (Q is the set of states, Σₒ is the output alphabet)

Mealy Machine:

● Output is determined by both the current state and the input symbol.
● Output function: λ : Q × Σᵢ -> Σₒ (Q is the set of states, Σᵢ is the input alphabet, Σₒ is the
output alphabet)

e) Two Differences between TM and LBA

1. Tape Length:

○ TM has an infinite tape.


○ LBA has a tape whose length is linearly bounded by the input string length.
2. Computational Power:

○ TM is Turing-complete, meaning it can compute any computable function.


○ LBA is less powerful than a TM and cannot compute all computable functions.
Q3) attempt any 2 for each 4 marks

a) Construct DFA for language which contains all string with exactly 2 consecutive 1's any
where.
b) Convert the following CFG into CNF S XYX X aX/ Y bY/
c) Design TM for language L = {a m b n / n m and m 1}

Answer :

a) DFA for language with exactly 2 consecutive 1's

Here's the DFA:

0 1
q0 ----> q0
^| |
|| |
|v v
q1 ----> q2 ----> q3
1 0/1

Explanation:

● q0: Initial state.


● q1: Reached after seeing the first '1'.
● q2: Reached after seeing two consecutive '1's.
● q3: A non-accepting state reached if three consecutive '1's are encountered.

b) Converting CFG to CNF

Given CFG:

S -> XYX
X -> aX | ε
Y -> bY | ε

CNF Conversion:

Step 1: Eliminate ε-productions:

S -> XYX | XY | YX | X | Y
X -> aX | a
Y -> bY | b
Step 2: Eliminate unit productions:

S -> aXY | aX | bXY | bY | a | b


X -> aX | a
Y -> bY | b

Step 3: Convert to CNF:

S -> AX | AY | BX | BY | a | b
A -> a
B -> b
X -> aX | a
Y -> bY | b

c) TM for language L = {a^m b^n / n >= m and m >= 1}

Turing Machine:

Q = {q0, q1, q2, q3} // States


Σ = {a, b} // Input alphabet
Γ = {a, b, B} // Tape alphabet
δ = transition function (defined below)
q0 = initial state
B = blank symbol
F = {q3} // Final state

Transition Function δ:

δ(q0, a) = (q1, B, R) // Replace first 'a' with B and move right


δ(q1, a) = (q1, B, R) // Replace subsequent 'a's with B and move right
δ(q1, b) = (q2, b, R) // Move to q2 after all 'a's are processed
δ(q2, b) = (q2, B, R) // Replace 'b's with B and move right
δ(q2, B) = (q3, B, S) // Accept if all 'b's are processed

Explanation:

1. q0: Initial state. Replaces the first 'a' with a blank symbol and moves right.
2. q1: Replaces subsequent 'a's with blanks and moves right.
3. q2: Moves right over 'b's, replacing them with blanks.
4. q3: Accepts the input if all 'b's are processed.
5.
Q4) attempt any 2 for each 4 marks

a) Construct a PDA for the language {w / na (w) = nb (w)} number of a's is equal to number of
b's.
b) Construct Moore machine which outputs even or odd according to number of a's encounted is
even or odd.
c) Construct equivalent DFA for the following NFA.

Answer :

a) PDA for {w | na(w) = nb(w)}

Idea: Push an 'A' onto the stack for each 'a' encountered in the input. Pop an 'A' for each 'b'. If
the stack is empty at the end of the input, the string is accepted.

PDA:

Q = {q0, q1, q2} // States


Σ = {a, b} // Input alphabet
Γ = {A} // Stack alphabet
δ = transition function (defined below)
q0 = initial state
Z0 = A // Initial stack symbol
F = {q2} // Final state

Transition Function δ:

δ(q0, a, A) = {(q0, AA)} // Push A onto the stack for 'a'


δ(q0, b, A) = ∅ // Error if 'b' before 'a'
δ(q0, ε, A) = {(q1, ε)} // Transition to q1 without reading input
δ(q1, a, A) = ∅ // Error if 'a' after all 'b's
δ(q1, b, A) = {(q1, ε)} // Pop A from the stack for 'b'
δ(q1, ε, A) = {(q2, ε)} // Accept if stack is empty

b) Moore Machine for Even/Odd Count of 'a's

Idea: Use two states to track whether the number of 'a's seen so far is even or odd.
Moore Machine:

Q = {q0, q1} // States


Σ = {a, b} // Input alphabet
Σo = {even, odd} // Output alphabet
δ = transition function (defined below)
λ = output function (defined below)
q0 = initial state

Transition Function δ:

δ(q0, a) = q1
δ(q0, b) = q0
δ(q1, a) = q0
δ(q1, b) = q1

Output Function λ:

λ(q0) = even
λ(q1) = odd

c)

To construct an equivalent DFA from the given NFA, we will use the subset construction method.
This method involves creating DFA states that represent subsets of NFA states.

Here's how we can construct the DFA:

1. Initial State:

● The initial state of the DFA will be the epsilon closure of the initial state of the NFA.
● In this case, the epsilon closure of q0 is {q0, q1, q2, q3, q4, q5, q6, q7}.

2. Transition Function:

● For each DFA state (a subset of NFA states) and each input symbol, we determine the
set of NFA states that can be reached from the current DFA state by following the
corresponding transitions in the NFA.

3. Final States:

● A DFA state is a final state if it contains at least one final state of the NFA. In this case,
states containing q7 will be final.

Building the DFA:


States: {
{q0, q1, q2, q3, q4, q5, q6, q7},
{q1, q2, q3, q4, q5, q6, q7},
{q2, q3, q4, q5, q6, q7},
{q3, q4, q5, q6, q7},
{q4, q5, q6, q7},
{q5, q6, q7},
{q6, q7},
{q7}
}

Transitions:

{q0, q1, q2, q3, q4, q5, q6, q7} --a--> {q1, q2, q3, q4, q5, q6, q7}
{q0, q1, q2, q3, q4, q5, q6, q7} --b--> {q6, q7}
{q1, q2, q3, q4, q5, q6, q7} --a--> {q1, q2, q3, q4, q5, q6, q7}
{q1, q2, q3, q4, q5, q6, q7} --b--> {q6, q7}
... (similarly for other states)

Final States:

{q6, q7}, {q7}

By following these steps and constructing the DFA, we can now process input strings
deterministically and accept the same language as the original NFA.

Q5) attempt any 1 for 3 marks

a) Show that L = {On 1n On} is not regular.


b) Eliminate ε-production for grammar & also find nullable variable. S AB A SA/BB/bB B b/aA/ε

Answer :

a) Proving L = {0^n 1^n 0^n | n ≥ 1} is Not Regular

We can use the Pumping Lemma to prove that L is not regular.

Pumping Lemma: If L is regular, there exists a pumping length p such that any string s in L with
|s| ≥ p can be written as s = xyz, where:

1. |xy| ≤ p
2. |y| ≥ 1
3. For all i ≥ 0, xy^iz ∈ L

Proof by Contradiction:

Assume L is regular. Let p be the pumping length. Consider the string s = 0^p 1^p 0^p.

According to the Pumping Lemma, we can write s = xyz, where |xy| ≤ p and |y| ≥ 1.

Since |xy| ≤ p, y must consist only of 0s.

Now, let's pump y twice: xy^2z. This string will have more 0s in the first part than in the last part,
and thus, it does not belong to L.

This contradicts the Pumping Lemma, and therefore, our assumption that L is regular must be
false.

Hence, L = {0^n 1^n 0^n | n ≥ 1} is not a regular language.

b) Eliminating ε-productions and Finding Nullable Variables

Nullable Variables: A variable A is nullable if it can derive ε. In this grammar, B is nullable.

Eliminating ε-productions:

1. Find nullable variables: B is nullable.


2. Eliminate ε-productions:
○ Replace B with ε in all productions where B appears.
○ Remove the production B -> ε.

New Grammar:

S -> AB | A | B
A -> SA | BB | bB | aA | a
B -> b | aA

You might also like