Top Banner Ad
BCS402 · 2024-2522 Questions

Theory of Automata and Formal Languages — 2024-25

Section A

2 Marks Each · 7 questions
Q1a2MUnit 1 — Alphabet
Core Concept

Define the term “Alphabet” in the context of automata theory.

An alphabet is a finite, nonempty set of symbols used to form the strings of a language. It is usually denoted by the Greek letter sigma. Examples are the binary alphabet zero and one, or the set of lower case letters. Every string is a finite sequence of symbols from this alphabet.

Key Points

  • Finite set of symbols
  • Denoted by sigma
  • Strings are sequences of symbols
Q1b2MUnit 1 — Equivalence of DFA and NFA
Core Concept

Differentiate between DFA and NFA.

A DFA has exactly one next state for each state and input symbol, so each input string follows a single path. An NFA may have several next states or epsilon moves and accepts if any path ends in a final state. Both recognize exactly the regular languages.

Key Points

  • DFA one path per string
  • NFA many possible paths
  • Same language power
Q1c2MUnit 2 — Regular Expressions
Predicted

Write the regular expression for the language containing strings over {0,1} ending with 01.

Answer: Strings over {0,1} ending with 01 have an arbitrary prefix followed by the fixed suffix 01.

  1. The arbitrary prefix is any string in (0+1)*.
  2. Append the mandatory suffix 01.
  3. Examples accepted: 01, 001, 101, 1101; rejected: 10, 11, 0. Result: Regular expression = *(0+1)01 (equivalently (0 U 1)*01).

Key Points

  • Arbitrary prefix (0+1)*
  • Mandatory suffix 01
  • Regex = (0+1)*01
Q1d2MUnit 3 — Derivation Trees and Ambiguity
Survival ModePredicted

What is the ambiguity in Context-Free Grammars (CFGs)?

A context free grammar is ambiguous if some string in its language has more than one distinct leftmost derivation, equivalently more than one distinct parse tree. Ambiguity is a property of the grammar, not necessarily of the language, because another unambiguous grammar may generate the same language.

Key Points

  • More than one leftmost derivation
  • More than one parse tree
  • Property of the grammar
Q1e2MUnit 3 — Programming problems based on the properties of CFGs
Survival ModePredictedRepeated

Construct a CFG for the language L={anbn∣n≥0}L = \{a^n b^n \mid n \ge 0\}.

Answer: Ambiguity means a string has two different leftmost derivations (two parse trees). CFG for L =

{anbn∣n>=0}\{a^n b^n | n >= 0\}

: S -> a S b | epsilon.

  1. Base: S => epsilon generates n = 0.
  2. Recursive step: S => a S b; if S derives a^
{n}\{n\}

b^

{n}\{n\}

, then a S b derives a^

{n+1}\{n+1\}

b^

{n+1}\{n+1\}

. 3. Derivation of aabb: S => a S b => aa S bb => aa epsilon bb => aabb. 4. This grammar is unambiguous: each string a^n b^n has exactly one leftmost derivation.

Generating structured strings. A context free grammar is a formal system for generating a language, defined by a set of nonterminals, a set of terminals, a start symbol and a set of productions whose left side is a single nonterminal. It is more powerful than a finite automaton because a nonterminal can be replaced by a string containing nested occurrences of the same nonterminal, giving unbounded counting. For the language consisting of equal numbers of a and b with all a before all b, the grammar has a rule that wraps a production with a on the left and b on the right, together with a rule that terminates the recursion with the empty string. This generates every string by nesting the same number of a and b around the empty string. Ambiguity arises when a string has more than one distinct leftmost derivation, equivalently more than one distinct parse tree. For grammars generating expressions or repeated concatenation, ambiguity often comes from a rule that allows the same string to be split in different ways. Demonstrating ambiguity means exhibiting one string and two different derivation trees for it, not merely stating that the grammar looks ambiguous. When constructing grammars for languages such as strings where the number of zeros differs from the number of ones, split into two cases, one where zeros are more numerous and one where ones are more numerous, and generate each case with a nested construction that guarantees a positive difference. A complete answer gives the productions, explains the role of each nonterminal, derives a sample string and either proves unambiguity by arguing that each string has a unique decomposition or proves ambiguity by showing two parse trees for one string. Mentioning that context free grammars generate exactly the languages accepted by pushdown automata connects the two models.

Result: Ambiguity is multiple parse trees; the grammar S -> aSb | epsilon cleanly generates a^n b^n (n >= 0).

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Ambiguity = multiple parse trees
  • Grammar S -> aSb | epsilon
  • Example derivation of aabb
Q1f2MUnit 3 — Derivation Trees and Ambiguity
Predicted

Find whether the following grammar is ambiguous or not: S→S∗S∣S+S∣aS \to S*S \mid S+S \mid a.

Answer: Grammar G: S -> aSb | epsilon. Its language is

{anbn∣n>=0}\{a^n b^n | n >= 0\}

.

  1. For a given string a^n b^n there is only one possible first production: if n > 0 use S -> aSb, if n = 0 use S -> epsilon.
  2. Recursively, at each step the choice is again forced by the remaining length. Thus the leftmost derivation is unique.
  3. The parse tree is a single chain: root S, child a S b, then a a S b b, ... ending in epsilon.
  4. Compare with E -> E+E | id where id+id+id has two trees; here no such alternative exists.

Generating structured strings. A context free grammar is a formal system for generating a language, defined by a set of nonterminals, a set of terminals, a start symbol and a set of productions whose left side is a single nonterminal. It is more powerful than a finite automaton because a nonterminal can be replaced by a string containing nested occurrences of the same nonterminal, giving unbounded counting. For the language consisting of equal numbers of a and b with all a before all b, the grammar has a rule that wraps a production with a on the left and b on the right, together with a rule that terminates the recursion with the empty string. This generates every string by nesting the same number of a and b around the empty string. Ambiguity arises when a string has more than one distinct leftmost derivation, equivalently more than one distinct parse tree. For grammars generating expressions or repeated concatenation, ambiguity often comes from a rule that allows the same string to be split in different ways. Demonstrating ambiguity means exhibiting one string and two different derivation trees for it, not merely stating that the grammar looks ambiguous. When constructing grammars for languages such as strings where the number of zeros differs from the number of ones, split into two cases, one where zeros are more numerous and one where ones are more numerous, and generate each case with a nested construction that guarantees a positive difference. A complete answer gives the productions, explains the role of each nonterminal, derives a sample string and either proves unambiguity by arguing that each string has a unique decomposition or proves ambiguity by showing two parse trees for one string. Mentioning that context free grammars generate exactly the languages accepted by pushdown automata connects the two models.

Result: G is unambiguous - every string in its language has exactly one derivation tree.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.
Two parse trees for ab Tree 1Tree 2 Sa S ba ab b SS Sab ab S to aSb to ε gives aab b; S to SS shows another split, so ambiguity must be checked on one fixed string

Key Points

  • Language {a^n b^n}
  • Next production forced by remaining length
  • Unique parse tree -> unambiguous
Q1g2MUnit 5 — Techniques for Turing Machine Construction
Survival ModePredictedRepeated

Design a Turing Machine to accept the language L={anbn∣n≥1}L = \{a^n b^n \mid n \ge 1\}.

Answer: L =

{0{2n}∣n>=0}\{0^\{2n\} | n >= 0\}

= even-length strings of zeros (including epsilon). TM design (one tape):

  1. Start at leftmost cell. If the cell is blank, accept (epsilon case).
  2. Read a 0, mark it X, move right to the next 0 and mark it X.
  3. Return to the leftmost unmarked 0 and repeat.
  4. If after marking a pair the next cell is blank, accept; if a single unmarked 0 remains before blank, reject. Transitions: delta(q0,X)=(q0,X,R); delta(q0,0)=(q1,X,R) marks the first zero of a pair; delta(q1,0)=(q2,X,L) marks the second; delta(q2,X)=(q2,X,L) and delta(q2,B)=(q0,B,R) return to the left end; delta(q0,B)=(qf,B,R) accepts when all zeros are paired; delta(q1,B)=(qr,B,R) rejects an unpaired zero.

A Turing machine as a general computer. A Turing machine consists of an infinite tape divided into cells, a read write head, a finite control unit and a set of transition rules that specify, for the current state and scanned symbol, the symbol to write, the direction to move and the next state. It accepts a language when starting with the input on the tape in the initial state it eventually enters an accepting halt state, and it rejects if it halts in a non accepting state. Designing a machine for a language such as strings with an even number of zeros means scanning left to right, marking every second zero and checking at the end that no unmarked zero remains, or equivalently moving between two states that toggle on each zero and accepting only in the start state. For a language such as a to the power two n followed by b to the power n, the machine crosses off two a symbols for every one b, checks that both are exhausted together, and rejects otherwise. Instantaneous descriptions record the tape contents, the current state and the head position in a compact notation, and writing the sequence of descriptions for a specific input demonstrates the computation step by step. A Turing machine can also compute functions, for example doubling a unary number by replacing each original mark with two marks, or adding one by appending a mark at the end of the unary string. A complete answer gives the high level algorithm, the transition rules, a sequence of instantaneous descriptions for the requested string and a correctness argument that all and only strings in the language are accepted. Mentioning that the machine can move both ways along the tape is what gives it more power than a pushdown automaton.

Result: The TM accepts exactly even numbers of 0's; 0000 accepted, 000 rejected, epsilon accepted.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Mark zeros in pairs with X
  • Accept on blank after complete pair
  • Reject when one unpaired zero remains

Section B

7 Marks Each · 5 questions
Q2a7MUnit 1 — Equivalence of DFA and NFA
Core Concept

Prove that for every NFA, there exists an equivalent DFA. Show construction using subset method for the given NFA: States = {q_0, q_1}, Input = {0,1}, Start = q_0, Final = {q_1}, Transitions: δ(q0,0)={q0,q1},δ(q0,1)={q0},δ(q1,1)={q1}\delta(q_0, 0) = \{q_0, q_1\}, \delta(q_0, 1) = \{q_0\}, \delta(q_1, 1) = \{q_1\}.

Answer: Theorem: for every NFA N there is a DFA D with L(D) = L(N). Construction: D-states are subsets of N-states; D-start = epsilon-closure(

{q0}\{q0\}

); for subset S, D-delta(S,a) = epsilon-closure( union delta_N(q,a) for q in S ); D-final subsets contain a final state of N. Given NFA: states

{q0,q1}\{q0,q1\}

, start q0, final

{q1}\{q1\}

; delta(q0,0)=

{q0,q1}\{q0,q1\}

, delta(q0,1)=

{q0}\{q0\}

, delta(q1,1)=

{q1}\{q1\}

, delta(q1,0)=empty.

DFA state 0 1
{q0}\{q0\}

|

{q0,q1}\{q0,q1\}

|

{q0}\{q0\}

| |

{q0,q1}\{q0,q1\}

(final) |

{q0,q1}\{q0,q1\}

|

{q0,q1}\{q0,q1\}

| The run of D on w tracks exactly the set of states N could be in after w, so acceptance agrees.

Why every NFA has an equivalent DFA. A nondeterministic finite automaton differs from a deterministic one in that a transition may lead to several possible states for the same symbol, and epsilon moves may be taken without consuming input. A string is accepted if at least one of the possible paths ends in a final state. Despite this apparent extra power, NFAs and DFAs accept exactly the same class of languages, namely the regular languages. The proof is the subset construction. Given an NFA, we construct a DFA whose states are subsets of the NFA state set. The start state of the DFA is the epsilon closure of the NFA start state, meaning that state together with every state reachable by epsilon moves. For each subset and each input symbol, the DFA moves to the union of the epsilon closures of all NFA states reachable by that symbol from any member of the subset. A DFA state is accepting if it contains at least one accepting state of the NFA. This construction is correct because after reading any prefix the current DFA subset contains exactly those NFA states that could be reached after reading that prefix along some path, so at the end it contains a final state exactly when some path accepts. The number of DFA states can be as large as two to the power of the number of NFA states, which shows the potential cost of removing nondeterminism. A good answer gives the subset construction formula, computes the reachable subsets step by step for the given NFA, lists the resulting transition table and states which subsets are final. Explaining what the epsilon closure contributes and why containment of a final state is the acceptance condition makes the proof complete rather than a mechanical table.

Result: The subset construction yields an equivalent DFA, proving equivalence of DFA and NFA.

L={0,1}∗L = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Subset construction with epsilon-closure
  • Worked table for q0,q1 NFA
  • Proof: D tracks all possible N states
Q2b7MUnit 2 — Algebraic Method Using Arden’s Theorem
Predicted

Prove using Arden’s Theorem the regular expression for the following transition diagram: States: A (start), B (final), Transitions: A --a--> A, A --b--> B, B --a--> B.

Answer: Given A start, B final; A-a->A, A-b->B, B-a->B (no b from B).

  1. Write equations for paths reaching each state: A = A a + epsilon (start state reached by epsilon or by a from A); B = A b + B a.
  2. From A = A a + epsilon, apply Arden with P = a, Q = epsilon: A = epsilon a* = a*.
  3. B = a* b + B a. Apply Arden with P = a, Q = a* b: B = a* b a*.

Solving equations for regular languages. Arden's theorem provides an algebraic method for deriving the regular expression accepted by a finite automaton. It states that if X and A and B are languages and X equals A union X B, and A does not contain the empty string, then X equals A B star, and this solution is unique. The theorem turns the transition equations of an automaton into a system of equations whose unknowns are the languages accepted from each state. For every state we write an equation saying that the language of that state is the union of the terminal symbols that lead directly to a final state and the languages reached after each outgoing transition prefixed by the corresponding symbol. Substituting and applying Arden's rule repeatedly eliminates variables until the expression for the start state contains only terminals and regular expression operators. For a machine with state A looping on a and moving on b to final state B, and B looping on a, the equations are A equals a A union b B and B equals a B union epsilon. Arden's theorem gives B equals a star, and substituting gives A equals a star b a star, which is exactly the set of strings with one b followed by any number of a symbols. For a machine whose final state is reached on a from every position, the language a star b a star follows directly from the same pattern. A good answer states the theorem with its condition, writes one equation per state, solves them step by step with clear substitution and simplifies the final expression using standard identities. Showing that the final expression is a regular expression built with union, concatenation and star demonstrates the closure of regular languages under these operations.

Result: Regular expression = a b a** - strings with a single b and any number of a's before and after it. The proof follows directly from Arden's theorem.

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.
A B a b a Arden: B = aB + e gives a star; A = aA + bB gives a star b a star

Key Points

  • State equations A=Aa+e, B=Ab+Ba
  • Arden solves A=a*, B=aba
  • Regex = aba
Q2c7MUnit 3 — Conversion of FA into CFG and Regular grammar into FA
Core Concept

Convert the following regular grammar to a Finite Automaton: S→aA∣bBS \to aA \mid bB, A→aS∣aA \to aS \mid a, B→bS∣bB \to bS \mid b.

Answer: A right-linear grammar A -> aB | a corresponds to a transition A --a--> B and a final state for productions A -> a. Grammar: S -> aA | bB; A -> aS | a; B -> bS | b.

  1. States: S (start), A, B, plus a final sink F.
  2. Transitions: S-a->A, S-b->B; A-a->S; A-a->F (from A -> a); B-b->S; B-b->F (from B -> b).
  3. Equivalent compact FA using final states A and B directly: since A -> a means 'a leads to acceptance', add a new final state F and the two epsilon-free transitions A-a->F, B-b->F. | State | a | b | |---|---|---| | S | A | B | | A | S,F | - | | B | - | S,F | | F (final) | F | F |

Translating between automata and grammars. A finite automaton and a right linear grammar describe exactly the same class of languages. To convert a finite automaton into an equivalent right linear grammar, create one nonterminal for each state and make the start symbol correspond to the start state. For every transition from state P to state Q on symbol a, add the production P goes to a Q. For every accepting state Q, add the production Q goes to the empty string. A string is then derived exactly when the corresponding path of transitions ends in an accepting state, so derivation and acceptance coincide. To convert a right linear grammar into an automaton, create a state for each nonterminal plus a new accepting state, and add a transition labelled a from the state for P to the state for Q for each production P goes to a Q, together with a transition to the accepting state for each production P goes to a. The same construction works for left linear grammars with the roles of start and end reversed, or by reversing the resulting automaton. Regular grammars are classified as right linear when every production has at most one nonterminal at the right end and left linear when it is at the left end. A grammar with mixed forms can still be regular if it can be rewritten into one of these forms. A complete answer states the conversion rules, applies them to every production of the given grammar, lists the resulting transitions or productions and traces a sample string through both representations to confirm equivalence. Mentioning why the empty production is added only for accepting states makes the correspondence precise.

Result: The finite automaton with states S,A,B,F and the table above accepts exactly the regular grammar's language.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Right-linear rule A->aB becomes transition
  • Terminal-only rules lead to final state
  • Table for S,A,B,F
Q2d7MUnit 4 — Pushdown Automata for Context Free Languages
Predicted

Design a PDA that accepts the language L={wwR∣w∈{a,b}∗}L = \{ww^R \mid w \in \{a, b\}^*\}.

Answer: For L =

{wwR∣win{a,b}∗}\{ w w^R | w in \{a,b\}* \}

, push the first half and pop it while reading the reversed second half; the middle is guessed nondeterministically.

  1. In q0, for each input symbol x in
{a,b}\{a,b\}

, push x: delta(q0,x,Z)=(q0,xZ), delta(q0,x,x)=(q0,xx). 2. Guess the midpoint by an epsilon transition to q1: delta(q0,epsilon,Z)=(q1,Z) and delta(q0,epsilon,x)=(q1,x). 3. In q1, reading x must match and pop the top: delta(q1,a,a)=(q1,epsilon), delta(q1,b,b)=(q1,epsilon). 4. Accept when stack bottom Z0 is reached: delta(q1,epsilon,Z0)=(qf,epsilon). 5. For empty w, epsilon is accepted directly.

A stack gives the machine a memory. A pushdown automaton is a finite automaton equipped with a stack, which allows it to count and to match nested structures that a finite automaton cannot handle. Formally it has states, an input alphabet, a stack alphabet, transitions, a start state, a start stack symbol and a set of final states. Each transition consumes an input symbol or the empty string, pops the top stack symbol and pushes a string of stack symbols. The automaton accepts a context free language either by reaching a final state after reading the whole input or by emptying the stack. To recognize strings of the form w followed by the reverse of w, the machine pushes each symbol of the first half onto the stack without consuming anything in the nondeterministic version, or guesses the middle, and then for each symbol of the second half pops the stack and checks that the popped symbol matches the input. If the stack returns to the bottom symbol exactly when the input ends, the string is a palindrome and is accepted. For a language with twice as many b as a, push two stack symbols for each a and pop one for each b, accepting if the stack is empty and the input is exhausted. For the language with equal numbers of a, b and c, a single stack is not enough, which is why a two stack machine is needed. A complete answer describes the stack operations for each phase, gives the transition functions with stack symbols clearly defined, explains the nondeterministic guess where required and traces one accepted and one rejected string. Mentioning that the stack provides only last in first out access explains both the power and the limitation of the model.

Result: The NPDA accepts exactly even-length palindromes of the form w w^R; non-determinism guesses the midpoint.

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Push first half onto stack
  • Epsilon transition guesses midpoint
  • Pop and match reverse half; accept at Z0
Q2e7MUnit 5 — Turing Machine as Computer of Integer Functions
Core Concept

Design a Turing Machine to compute the function f(n)=n+1f(n) = n + 1 where nn is a unary number (e.g., n=3→“111”n=3 \to \text{“111”}).

Answer: Input n is represented as n unary 1's; the machine must output n+1 1's.

  1. Start at the leftmost 1 (or blank for n=0) in state q0.
  2. Scan right over all 1's until the first blank: delta(q0,1)=(q0,1,R); delta(q0,B)=(q1,1,R) writes one extra 1.
  3. In q1 move left to the start of the tape and halt in the accepting state: delta(q1,1)=(q1,1,L); delta(q1,B)=(qf,B,R). Example: n=3, tape '111' -> scan to blank -> write 1 -> '1111' -> accept.

A Turing machine as a general computer. A Turing machine consists of an infinite tape divided into cells, a read write head, a finite control unit and a set of transition rules that specify, for the current state and scanned symbol, the symbol to write, the direction to move and the next state. It accepts a language when starting with the input on the tape in the initial state it eventually enters an accepting halt state, and it rejects if it halts in a non accepting state. Designing a machine for a language such as strings with an even number of zeros means scanning left to right, marking every second zero and checking at the end that no unmarked zero remains, or equivalently moving between two states that toggle on each zero and accepting only in the start state. For a language such as a to the power two n followed by b to the power n, the machine crosses off two a symbols for every one b, checks that both are exhausted together, and rejects otherwise. Instantaneous descriptions record the tape contents, the current state and the head position in a compact notation, and writing the sequence of descriptions for a specific input demonstrates the computation step by step. A Turing machine can also compute functions, for example doubling a unary number by replacing each original mark with two marks, or adding one by appending a mark at the end of the unary string. A complete answer gives the high level algorithm, the transition rules, a sequence of instantaneous descriptions for the requested string and a correctness argument that all and only strings in the language are accepted. Mentioning that the machine can move both ways along the tape is what gives it more power than a pushdown automaton.

Result: The TM computes f(n) = n + 1 in unary by appending one 1 to the input string.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Unary representation n = 1^n
  • Scan to first blank and write 1
  • Example 111 -> 1111

Section C

7 Marks Each · 10 questions
Q3a7MUnit 1 — Equivalence of DFA and NFA
Survival ModePredictedRepeated

Construct a DFA corresponding to the given NFA.

Answer: Subset construction converts an NFA (Q, Sigma, delta, q0, F) into a DFA whose states are subsets of Q.

  1. Start state of DFA = epsilon-closure(
{q0}\{q0\}

). 2. For each subset S and symbol a, DFA transition = epsilon-closure( union of delta(q,a) for q in S ). 3. A DFA state is accepting if it contains any NFA final state. Worked example (NFA q0 start, q1 final; delta(q0,0)=

{q0,q1}\{q0,q1\}

, delta(q0,1)=

{q0}\{q0\}

, delta(q1,1)=

{q1}\{q1\}

):

DFA state 0 1
{q0}\{q0\}

|

{q0,q1}\{q0,q1\}

|

{q0}\{q0\}

| |

{q0,q1}\{q0,q1\}

(final) |

{q0,q1}\{q0,q1\}

|

{q0,q1}\{q0,q1\}

| | empty | empty | empty |

Why every NFA has an equivalent DFA. A nondeterministic finite automaton differs from a deterministic one in that a transition may lead to several possible states for the same symbol, and epsilon moves may be taken without consuming input. A string is accepted if at least one of the possible paths ends in a final state. Despite this apparent extra power, NFAs and DFAs accept exactly the same class of languages, namely the regular languages. The proof is the subset construction. Given an NFA, we construct a DFA whose states are subsets of the NFA state set. The start state of the DFA is the epsilon closure of the NFA start state, meaning that state together with every state reachable by epsilon moves. For each subset and each input symbol, the DFA moves to the union of the epsilon closures of all NFA states reachable by that symbol from any member of the subset. A DFA state is accepting if it contains at least one accepting state of the NFA. This construction is correct because after reading any prefix the current DFA subset contains exactly those NFA states that could be reached after reading that prefix along some path, so at the end it contains a final state exactly when some path accepts. The number of DFA states can be as large as two to the power of the number of NFA states, which shows the potential cost of removing nondeterminism. A good answer gives the subset construction formula, computes the reachable subsets step by step for the given NFA, lists the resulting transition table and states which subsets are final. Explaining what the epsilon closure contributes and why containment of a final state is the acceptance condition makes the proof complete rather than a mechanical table.

Result: Each reachable subset becomes a deterministic state; the construction proves NFAs and DFAs are equivalent.

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.
Subset construction for the given NFA q0 q0,q1 q1 empty 0 leads to q0,q1, 1 leads to q0; epsilon closure included in every state

Key Points

  • DFA states = subsets of NFA states
  • Use epsilon-closure on every move
  • Accepting subsets contain an NFA final state
Q3b7MUnit 1 — Minimization of Finite Automata
Survival ModePredictedRepeated

Express the minimum state automata equivalent to the DFA described in the given figure.

q0 q1 q2 q3 q4 q5 q6 a b a b a a a b b b a b a b

Figure details: The DFA consists of seven states: q0, q1, q2, q3, q4, q5, and q6. State q0 is the start state (indicated by an incoming arrow). State q2 is the only final state (indicated by a double circle). The transitions are as follows: from q0, input 'a' goes to q1 and input 'b' goes to q2; from q1, input 'a' goes to q2 and input 'b' goes to q3; from q2, input 'a' goes to q4 and input 'b' goes to q6 (via a long bottom arc); from q3, input 'a' goes to q4 and input 'b' goes to q5; from q4, input 'a' goes to q3 and input 'b' goes to q6; from q5, input 'a' goes to q5 (self-loop) and input 'b' goes to q6; from q6, input 'a' goes to q5 and input 'b' goes to q6 (self-loop).

Answer: Minimisation uses partition refinement (Myhill-Nerode).

  1. Partition states into final F and non-final Q-F.
  2. Repeatedly split a block if two of its states go to different blocks for some input symbol.
  3. Stop when no block splits; merge each block into one state. Example: DFA states A,B,C,D,E,F with E,F final and transitions A-0->B,A-1->C; B-0->A,B-1->D; C-0->B,C-1->E; D-0->C,D-1->F; E,F loop on 0/1 within finals. Initial P0 =
{A,B,C,D}\{A,B,C,D\}

,

{E,F}\{E,F\}

. On 1: C goes to final E while A,B,D go to non-final C,D/F? D goes to final F, so split again: after refinement

{A,B}\{A,B\}

,

{C,D}\{C,D\}

,

{E,F}\{E,F\}

; C and D remain distinguishable by further 0/1 checks, giving final classes

{A,B}\{A,B\}

,

{C}\{C\}

,

{D}\{D\}

,

{E,F}\{E,F\}

. 4. Draw a state for each class; transition from a class is the class containing the original transition.

Merging states that behave alike. Minimization of a finite automaton produces the smallest DFA equivalent to a given one by merging states that cannot be distinguished by any input string. Two states are equivalent if for every possible continuation string either both lead to acceptance or both lead to rejection. The algorithm starts by partitioning all states into two groups, the non final states and the final states, because a final and a non final state are always distinguishable by the empty string. It then repeatedly refines each group by checking whether its members go to different groups on some symbol. If two states in the same current group go to different groups for a particular input symbol, they are split into separate groups. The process stops when no group can be split further, which is guaranteed because the number of groups is finite and never decreases. At that point every state in a group is equivalent to every other state in the group, and one representative per group gives the minimal automaton. Unreachable states should be removed first because they can never affect acceptance and can distort the partition. The resulting machine has the smallest possible number of states and is unique up to renaming of states. A complete answer lists the initial partition, shows each refinement step with the distinguishing symbol, gives the final groups and draws or tabulates the minimized machine. Explaining why the final and non final states must be separated initially and why the refinement terminates demonstrates understanding of the underlying equivalence relation rather than mechanical application of the procedure.

Result: The minimal DFA has one state per equivalence class of indistinguishable states; unreachable states are removed first.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Start with final vs non-final partition
  • Split by differing transition blocks
  • Merge indistinguishable states
Q4a7MUnit 2 — Pumping Lemma
Survival ModePredictedRepeated

Using Pumping Lemma, show that the language L={anbncn∣n≥0}L = \{a^n b^n c^n \mid n \ge 0\} is not regular.

Answer: Suppose L =

{anb{2n}∣n>=1}\{a^n b^\{2n\} | n >= 1\}

is regular with pumping length p. Choose w = a^p b^

{2p}\{2p\}

, so |w| = 3p >= p.

  1. By the pumping lemma, w = xyz with |xy| <= p, |y| > 0 and xy^i z in L for all i >= 0.
  2. Since |xy| <= p, both x and y consist only of a's. Write x = a^j, y = a^k with k > 0, z = a^
{p−j−k}\{p-j-k\}

b^

{2p}\{2p\}

. 3. Pump down: i = 0 gives xz = a^

{p−k}\{p-k\}

b^

{2p}\{2p\}

. For membership we would need 2(p-k) = 2p, i.e., k = 0, contradicting k > 0. 4. Hence xy^0 z is not in L, a contradiction.

A necessary condition for regularity. The pumping lemma for regular languages is a powerful tool for proving that a language is not regular. It states that if a language is regular then there exists a pumping length p such that every string in the language whose length is at least p can be written as three parts xyz, with y nonempty and the length of xy at most p, and the string x y repeated i times z belongs to the language for every nonnegative integer i. The lemma holds because a machine with p states must repeat a state while reading the first p symbols of any sufficiently long string, and the loop between the two visits can be traversed zero, one or many times. To prove that a language is not regular, assume the contrary and let p be the pumping length, choose a convenient string in the language longer than p, show that for every possible split satisfying the length bound the pumped string falls outside the language, and conclude a contradiction. For the language consisting of a to the power n followed by b to the power two n, choose the string with n equal to p. Because the first part of the decomposition lies entirely within the a block, pumping adds extra a symbols without adding b symbols, destroying the required ratio of one to two. The language is therefore not regular. It is important to handle all legal decompositions, not just one, and to note that the pumping lemma is necessary but not sufficient: satisfying it does not prove regularity. A complete answer states the lemma precisely, explains the pigeonhole reason behind it, carries out the contradiction argument for the chosen string and draws the correct conclusion. Mentioning that the equal count language with a and b is the classic counterexample reinforces the method.

Result: L is not regular.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Choose w = a^p b^{2p}
  • |xy|<=p forces y to be all a's
  • Pumping changes a-count but not b-count -> contradiction
Q4b7MUnit 2 — Algebraic Method Using Arden’s Theorem
Predicted

Prove that (a+b)∗a(a+b)∗(a+b)^*a(a+b)^* is a regular language using Arden’s Theorem.

Answer: Construct a DFA for the language (strings containing at least one a). States: q0 = no a seen yet, q1 = at least one a seen (final). Transitions: q0-a->q1, q0-b->q0, q1-a->q1, q1-b->q1. Equations: q0 = q0 b + epsilon; q1 = q0 a + q1 a + q1 b = q0 a + q1(a+b).

  1. From q0 = q0 b + epsilon, Arden gives q0 = b*.
  2. q1 = b* a + q1(a+b); Arden gives q1 = b* a (a+b)*.
  3. The language of the DFA (and hence of the expression) is b* a (a+b)* = (a+b)* a (a+b)* (both describe strings containing at least one a).

Solving equations for regular languages. Arden's theorem provides an algebraic method for deriving the regular expression accepted by a finite automaton. It states that if X and A and B are languages and X equals A union X B, and A does not contain the empty string, then X equals A B star, and this solution is unique. The theorem turns the transition equations of an automaton into a system of equations whose unknowns are the languages accepted from each state. For every state we write an equation saying that the language of that state is the union of the terminal symbols that lead directly to a final state and the languages reached after each outgoing transition prefixed by the corresponding symbol. Substituting and applying Arden's rule repeatedly eliminates variables until the expression for the start state contains only terminals and regular expression operators. For a machine with state A looping on a and moving on b to final state B, and B looping on a, the equations are A equals a A union b B and B equals a B union epsilon. Arden's theorem gives B equals a star, and substituting gives A equals a star b a star, which is exactly the set of strings with one b followed by any number of a symbols. For a machine whose final state is reached on a from every position, the language a star b a star follows directly from the same pattern. A good answer states the theorem with its condition, writes one equation per state, solves them step by step with clear substitution and simplifies the final expression using standard identities. Showing that the final expression is a regular expression built with union, concatenation and star demonstrates the closure of regular languages under these operations.

Result: (a+b)* a (a+b)* is regular because it is the language of this DFA, obtained and expressed by Arden's theorem.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • DFA distinguishes 'no a yet' vs 'a seen'
  • Equations solved by Arden give ba(a+b)
  • Equal to (a+b)a(a+b), hence regular
Q5a7MUnit 3 — Normal Forms- Chomsky Normal Form(CNF)
Core Concept

Convert the following CFG into Chomsky Normal Form (CNF): S→aSB∣εS \to aSB \mid \varepsilon, B→bB \to b.

Answer: Grammar: S -> aSB | epsilon, B -> b.

  1. Eliminate epsilon from S: S -> aSB | epsilon means S can generate (a S B)^k epsilon. Adding non-epsilon productions: S -> aSB | aB (when inner S is epsilon).
  2. Eliminate unit production S -> aB? aB has terminal a followed by variable B: already CNF-friendly as A1 B if we replace terminal a by variable A1.
  3. Introduce A -> a and rewrite: S -> A S B | A B | epsilon; B -> b is terminal-only, replace by B -> C with C -> b? CNF allows A -> a, so B -> b is already valid.
  4. Final CNF: S -> A S B is not CNF (three symbols). Introduce X -> S B, then S -> A X | A B | epsilon; X -> S B; A -> a; B -> b.

Putting a grammar into standard form. Chomsky normal form is a standard form for context free grammars in which every production is either a nonterminal going to two nonterminals or a nonterminal going to a single terminal. The empty string is allowed only through a special start symbol if the original language contains it. Conversion proceeds in a fixed sequence. First a new start symbol is introduced that points to the old start, so that the start symbol never appears on a right side. Second, epsilon productions are eliminated using the nullable set and by adding all combinations with nullable nonterminals removed. Third, all unit productions are removed by replacing each chain with the direct non unit productions of its target. Fourth, every production mixing terminals and nonterminals on a long right side is rewritten by introducing a fresh nonterminal for each terminal, with a production from that nonterminal to the terminal. Finally, every right side with more than two nonterminals is broken into pairs by introducing additional fresh nonterminals. Each step preserves the generated language, so the final grammar is equivalent to the original. Chomsky normal form is important because it makes parse trees binary, which simplifies parsing algorithms such as the dynamic programming algorithm for membership and gives a clean proof that every context free language can be parsed in polynomial time. A complete answer carries out each step explicitly on the given grammar, lists the intermediate production sets and states the final grammar, checking that no production violates the allowed forms. Noting that the height of a parse tree for a string of length n is then at most n is a useful observation about why the form is valuable.

Result: CNF grammar: S -> A X | A B | epsilon, X -> S B, A -> a, B -> b (epsilon allowed only for the start symbol because epsilon belongs to L).

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Remove epsilon by adding shortened productions
  • Replace terminals with variables
  • Introduce X -> SB to get binary productions
Q5b7MUnit 3 — Derivation Trees and Ambiguity
Predicted

Prove using derivation trees whether the grammar S→aSb∣εS \to aSb \mid \varepsilon is ambiguous or not. Explain ambiguity.

Answer: Grammar G: S -> aSb | epsilon. Its language is

{anbn∣n>=0}\{a^n b^n | n >= 0\}

.

  1. For a given string a^n b^n there is only one possible first production: if n > 0 use S -> aSb, if n = 0 use S -> epsilon.
  2. Recursively, at each step the choice is again forced by the remaining length. Thus the leftmost derivation is unique.
  3. The parse tree is a single chain: root S, child a S b, then a a S b b, ... ending in epsilon.
  4. Compare with E -> E+E | id where id+id+id has two trees; here no such alternative exists.

Generating structured strings. A context free grammar is a formal system for generating a language, defined by a set of nonterminals, a set of terminals, a start symbol and a set of productions whose left side is a single nonterminal. It is more powerful than a finite automaton because a nonterminal can be replaced by a string containing nested occurrences of the same nonterminal, giving unbounded counting. For the language consisting of equal numbers of a and b with all a before all b, the grammar has a rule that wraps a production with a on the left and b on the right, together with a rule that terminates the recursion with the empty string. This generates every string by nesting the same number of a and b around the empty string. Ambiguity arises when a string has more than one distinct leftmost derivation, equivalently more than one distinct parse tree. For grammars generating expressions or repeated concatenation, ambiguity often comes from a rule that allows the same string to be split in different ways. Demonstrating ambiguity means exhibiting one string and two different derivation trees for it, not merely stating that the grammar looks ambiguous. When constructing grammars for languages such as strings where the number of zeros differs from the number of ones, split into two cases, one where zeros are more numerous and one where ones are more numerous, and generate each case with a nested construction that guarantees a positive difference. A complete answer gives the productions, explains the role of each nonterminal, derives a sample string and either proves unambiguity by arguing that each string has a unique decomposition or proves ambiguity by showing two parse trees for one string. Mentioning that context free grammars generate exactly the languages accepted by pushdown automata connects the two models.

Result: G is unambiguous - every string in its language has exactly one derivation tree.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.
Two parse trees for ab Tree 1Tree 2 Sa S ba ab b SS Sab ab S to aSb to ε gives aab b; S to SS shows another split, so ambiguity must be checked on one fixed string

Key Points

  • Language {a^n b^n}
  • Next production forced by remaining length
  • Unique parse tree -> unambiguous
Q6a7MUnit 3 — Simplification of CFG
Survival Mode

Simplify the following CFG: S→AbaCS \to AbaC, A→BCA \to BC, B→b∣εB \to b \mid \varepsilon, C→D∣εC \to D \mid \varepsilon, D→dD \to d.

Answer: Grammar: S -> AbaC, A -> BC, B -> b | epsilon, C -> D | epsilon, D -> d.

  1. Nullable: B, C (and A and S through them).
  2. Remove epsilon from B: B -> b; remove epsilon from C: C -> D. Since C is nullable, wherever C occurs add the alternative without C.
  3. A -> BC gives A -> B C | B | C; with B -> b and C -> D: A -> bD | b | D.
  4. S -> AbaC gives S -> AbaD | Aba (C omitted). Substituting A -> bD | b | D and D -> d gives S -> bDbaD | bbad | DbaD | bDba | bba | Dba | ba | bad, with D -> d.
  5. There is no recursion, so expand D -> d and enumerate all eight terminal strings.

Cleaning a grammar before use. Simplifying a context free grammar means transforming it into an equivalent grammar that has no useless symbols, no epsilon productions where they are not needed and no unit productions. Useless symbols are of two kinds. A symbol is non generating if it cannot derive any string of terminals. A symbol is unreachable if it cannot be reached from the start symbol by any sequence of productions. Removing non generating symbols proceeds bottom up by finding terminals and nonterminals that derive terminal strings, while removing unreachable symbols proceeds top down from the start symbol. The two removals must be done in the right order because removing a non generating symbol can make another symbol unreachable. Epsilon productions are removed by computing the set of nullable nonterminals and then adding productions for every combination in which a nullable nonterminal on the right side is either kept or deleted, taking care not to produce the empty production unless the language contains the empty string. Unit productions of the form A goes to B are removed by replacing each with the non unit productions of B, working upwards through the unit chain. The simplified grammar generates exactly the same language but is shorter and ready for conversion to normal form. A complete answer applies each step in order, lists the sets of generating and reachable symbols, shows the nullable set, writes the productions after epsilon removal and those after unit removal, and states the final grammar. Explaining why the order of the steps matters shows understanding rather than mechanical rewriting.

Result: A simplified epsilon-free equivalent grammar is S -> bdba | bba | dba | ba | bdbad | bbad | dbad | bad.

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Nullable B and C
  • Expand A -> BC into B, C and BC cases
  • Eight terminal strings listed; no epsilon rules
Q6b7MUnit 4 — Pushdown Automata for Context Free Languages
Predicted

Design a PDA to accept palindromes over {a,b}\{a, b\}.

Answer: PDA for palindromes over

{a,b}\{a,b\}

using the stack to compare first and last symbols.

  1. In q0, push each input symbol: delta(q0,a,Z)=(q0,aZ), delta(q0,b,Z)=(q0,bZ), delta(q0,a,a)=(q0,aa), delta(q0,b,b)=(q0,bb).
  2. Nondeterministically guess the centre and go to q1 with epsilon moves (also handle odd length by staying in q1 with the middle symbol unmatched via an epsilon self-loop).
  3. In q1, read a and pop a, or read b and pop b: delta(q1,a,a)=(q1,epsilon), delta(q1,b,b)=(q1,epsilon).
  4. Accept by empty stack or final state when Z0 is exposed: delta(q1,epsilon,Z0)=(qf,epsilon).
  5. Handles even palindromes (abba) and odd ones (abcba would need c handling; over
{a,b}\{a,b\}

example aba).

A stack gives the machine a memory. A pushdown automaton is a finite automaton equipped with a stack, which allows it to count and to match nested structures that a finite automaton cannot handle. Formally it has states, an input alphabet, a stack alphabet, transitions, a start state, a start stack symbol and a set of final states. Each transition consumes an input symbol or the empty string, pops the top stack symbol and pushes a string of stack symbols. The automaton accepts a context free language either by reaching a final state after reading the whole input or by emptying the stack. To recognize strings of the form w followed by the reverse of w, the machine pushes each symbol of the first half onto the stack without consuming anything in the nondeterministic version, or guesses the middle, and then for each symbol of the second half pops the stack and checks that the popped symbol matches the input. If the stack returns to the bottom symbol exactly when the input ends, the string is a palindrome and is accepted. For a language with twice as many b as a, push two stack symbols for each a and pop one for each b, accepting if the stack is empty and the input is exhausted. For the language with equal numbers of a, b and c, a single stack is not enough, which is why a two stack machine is needed. A complete answer describes the stack operations for each phase, gives the transition functions with stack symbols clearly defined, explains the nondeterministic guess where required and traces one accepted and one rejected string. Mentioning that the stack provides only last in first out access explains both the power and the limitation of the model.

Result: The NPDA accepts all palindromes over

{a,b}\{a,b\}

by pushing symbols and popping them in reverse order.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Push first half; guess centre
  • Pop matching symbols in second half
  • Accept at bottom of stack
Q7a7MUnit 5 — Universal Turing machine
Core Concept

Explain the concept of Universal Turing Machine. Construct a Turing Machine that computes f(n)=2nf(n) = 2n for unary input.

Answer: A Universal Turing Machine simulates any TM by reading its encoded transition table. To compute f(n) = 2n in unary (input 1^n, output 1^

{2n}\{2n\}

):

  1. TM for f: scan the input and replace each 1 with two 1's. Use markers: mark leftmost unprocessed 1 as X, append two 1's at the right end, return to next unprocessed 1; when none remain, erase all X's.
  2. Example: 111 -> X11 11 -> XX1 1111 -> XXX 111111 -> erase X's -> 111111 (six 1s = 2 x 3).
  3. A UTM given the encoding of this doubling TM and input 111 would step through exactly those configurations.

One machine that runs all others. A universal Turing machine is a single Turing machine that can simulate any other Turing machine on any input. The trick is to encode the description of the simulated machine, including its states, tape alphabet and transition table, as a string on the tape, and then to encode its input after that description. The universal machine reads the encoded transition rules, keeps track of the simulated machine's current state and head position by marking symbols on its own tape, and for each step looks up the appropriate transition and updates the simulated tape and state accordingly. Because the description and the input are both finite strings, the universal machine can store them on a single tape and carry out the simulation step by step. This concept is the theoretical foundation of the stored program computer: a fixed machine can perform any computation that can be described, just by changing the program it reads. To compute a simple function such as doubling a unary number, the machine scans the input, replaces each mark with two marks at the output end and erases the original, then halts when no unprocessed mark remains. A complete answer explains the encoding of machine descriptions and inputs, describes how the universal machine steps through a simulation, gives the transitions for any concrete function requested and argues that the simulation is faithful. Mentioning that the existence of a universal machine leads directly to the halting problem and to the idea of undecidability shows the wider significance of the construction.

Result: The UTM simulates the doubling machine, whose output for n unary 1's is 2n unary 1's.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • UTM reads encoded TM + input
  • Doubling TM marks and replaces each 1 by 11
  • Input 111 -> output 111111
Q7b7MUnit 5 — Post’s Correspondance Problem
Survival Mode

Discuss Post’s Correspondence Problem (PCP) with an example showing undecidability.

Answer: PCP: given domino pairs (u1,v1),...,(uk,vk), find a non-empty sequence i1...im with ui1u_{i1}...uimu_{im} = vi1v_{i1}...vimv_{im}. Example illustrating undecidability via reduction: take a TM M and construct dominoes so that a solution chain corresponds to a valid halting computation of M: dominoes copy tape contents, one specialised pair starts the chain with the initial configuration, and accepting-state pairs allow the final match. If M halts, a chain can be formed; if not, no chain exists. Since the Halting Problem is undecidable, an algorithm deciding PCP would decide halting - contradiction.

Matching strings on two lists. The Post correspondence problem asks whether, given two finite lists of nonempty strings over the same alphabet, there exists a sequence of indices such that concatenating the top strings in that order gives exactly the same result as concatenating the bottom strings in the same order. Each pair is like a domino with a top and a bottom word, and the task is to lay out a nonempty sequence of dominoes so that the top and bottom lines match. The problem is undecidable, meaning no algorithm can correctly decide yes or no for every instance. The proof reduces the halting problem to an instance of the correspondence problem: encode the computation of a Turing machine as a sequence of dominoes that can line up only if the machine halts, so any decision procedure for the problem would decide the halting problem, which is impossible. To show a matching instance, exhibit an explicit sequence of indices and display the two concatenated strings to confirm they are identical. To show non matching, one can sometimes argue by length or by first and last symbols, but the general absence of such a simple test is exactly why the problem is undecidable. A good answer defines the problem formally, gives a small instance with two or three pairs and a solution sequence, explains the domino analogy and outlines the reduction that proves undecidability. Mentioning that the problem is decidable for a restricted alphabet of one symbol but undecidable for alphabets of at least two symbols adds a useful boundary condition.

Result: PCP is undecidable; the reduction from the halting problem shows no general decision procedure exists.

S={0,1}∗S = \{0, 1\}^*
Tip from Examiner: State the formal definition, show the construction or derivation step by step, and verify the result on a short sample string.

Key Points

  • Domino chain equality problem
  • Reduction encodes TM computation into dominoes
  • No algorithm exists (undecidable)