Top Banner Ad
BCS402 · 2025-2622 Questions

Theory of Automata and Formal Languages — 2025-26

Section A

2 Marks Each · 7 questions
Q1a2MUnit 1 — Deterministic Finite Automaton (DFA)- Definition
Survival ModePredictedRepeated

Define Deterministic Finite Automata (DFA).

A DFA is a five tuple with a finite set of states, an input alphabet, a transition function giving exactly one next state per state and symbol, a start state and a set of final states. It accepts a string when the unique state reached after reading the string is final.

Key Points

  • Five tuple definition
  • Exactly one transition per symbol
  • Accepts if last state is final
Q1b2MUnit 1 — Acceptability of a String and Language
Core Concept

Design a DFA to accept all strings with "abb" as substring over alphabet {a, b}.

Use four states representing how much of the substring abb has been matched so far: none, a, ab, and abb. The abb state is final and absorbing. From each state a mismatching symbol returns to the longest suffix that is still a prefix of abb.

Key Points

  • Four progress states
  • Final state abb is absorbing
  • Mismatch backs off to prefix
Q1c2MUnit 2 — Regular Expressions
Core Concept

Find the shortest string not in the language of the regular expression a∗(ba)∗a^*(ba)^*.

The expression a star followed by any number of groups ba generates strings that are either empty or end in a, and any b must be followed by an a. The single symbol b cannot be generated, and it is shorter than any other excluded string, so b is the shortest string not in the language.

Key Points

  • Every b is followed by a
  • Strings end in a or are empty
  • Shortest excluded string is b
Q1d2MUnit 2 — Pigeonhole Principle
Core Concept

State the Pigeonhole Principle.

The pigeonhole principle states that if more items are placed into fewer containers than there are items, then at least one container holds more than one item. For automata, reading a string longer than the number of states forces some state to repeat, which is the basis of the pumping lemma.

Key Points

  • More items than containers
  • Some container has two items
  • Basis of pumping lemma
Q1e2MUnit 3 — Simplification of CFG
Core Concept

Explain the difference between non-generating and unreachable symbols.

A non generating symbol cannot derive any string of terminals. An unreachable symbol cannot be reached from the start symbol by any sequence of productions. Non generating symbols are found bottom up from terminals; unreachable symbols are found top down from the start symbol, and both are removed when simplifying a grammar.

Key Points

  • Non generating derives no terminals
  • Unreachable not reached from start
  • Removed in different directions
Q1f2MUnit 4 — A Language Accepted by NPDA
Core Concept

Define acceptance by final state and acceptance by empty stack in a PDA.

Acceptance by final state means the PDA accepts when the entire input has been consumed and the machine is in a final state, regardless of stack contents. Acceptance by empty stack means it accepts when the stack is empty after reading the input, regardless of the state. The two modes define the same class of languages.

Key Points

  • Final state mode
  • Empty stack mode
  • Equivalent acceptance power
Q1g2MUnit 5 — Linear Bounded Automata
Core Concept

What is a Linear Bounded Automaton (LBA)?

A linear bounded automaton is a Turing machine restricted to the cells occupied by its input, with end markers. It accepts exactly the context sensitive languages. Because the tape is bounded, only finitely many configurations exist for a given input, so membership is decidable.

Key Points

  • Tape bounded by input length
  • Accepts context sensitive languages
  • Finitely many configurations

Section B

7 Marks Each · 5 questions
Q2a7MUnit 1 — Acceptability of a String and Language
Core Concept

Design a DFA which accepts set of strings such that every string containing "00" as substring but not "000" as a substring.

Answer: Track runs of consecutive zeros while forbidding length 3 and remembering whether 00 has occurred. States: q0 = no 00 yet, no pending zero; q1 = one trailing zero; q2 = 00 seen (final, trailing run length 2); q3 = dead state (000 occurred).

State 0 1
q0 q1 q0
q1 q2 q0
q2 (final) q3 q2
q3 (dead) q3 q3
  1. A third consecutive 0 from q2 goes to dead q3.
  2. After q2, reading 1 stays in q2 since 00 has already occurred; a later isolated zero is allowed.

Why determinism matters. A deterministic finite automaton is the simplest machine model for recognizing a regular language. Formally it is a five tuple consisting of a finite set of states, a finite input alphabet, a transition function that assigns exactly one next state to every state and every input symbol, a distinguished start state and a set of accepting states. Determinism means that for a given state and input symbol the next state is unique; there is no choice and no epsilon move. The machine reads the input string one symbol at a time, starting in the initial state, and moves according to the transition function. After the last symbol is read the string is accepted if the current state belongs to the set of final states and rejected otherwise. This single run of the machine makes a DFA very easy to implement in software or hardware as a table lookup. A DFA can be drawn as a state diagram with circles for states, an arrow for the start state, double circles for accepting states and labelled arrows for transitions, and it can equally be given as a transition table. When constructing a DFA for a property such as divisibility, the states encode the remainder of the number read so far, and the transition on the next digit updates that remainder. When constructing a DFA for a substring property, the states encode how much of the required pattern has already been matched, and a failure transition backs off to the longest suffix that is still a prefix of the pattern. Because the number of states is finite, only regular languages can be recognized. A complete answer states the formal definition, draws or tabulates the transitions, explains what each state represents, and walks through at least one accepted and one rejected string to verify the construction. Mentioning that the automaton has no memory beyond its current state explains both its power and its limitation.

Result: The DFA accepts strings containing 00 but never 000.

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

  • Count trailing zeros up to 2
  • q2 final means 00 seen without 000
  • Third zero -> dead state
Q2b7MUnit 2 — Pumping Lemma
Survival ModePredictedRepeated

Using the pumping lemma, show that L={anb2n∣n≥1}L = \{a^n b^{2n} \mid n \ge 1\} is not a regular language.

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
Q2c7MUnit 3 — Simplification of CFG
Core Concept

Remove ε\varepsilon-productions from the given grammar: S→AB∣BCS \to AB \mid BC; A→aA∣εA \to aA \mid \varepsilon; B→bB∣εB \to bB \mid \varepsilon; C→cC \to c.

Answer: Find nullable variables, add productions for their omission, then delete epsilon rules. Grammar: S -> AB | BC; A -> aA | epsilon; B -> bB | epsilon; C -> c.

  1. Nullable variables: A and B (and S because S -> AB with A,B nullable).
  2. Replace A -> aA by A -> aA | a and remove A -> epsilon; replace B -> bB by B -> bB | b and remove B -> epsilon.
  3. Expand S -> AB: A B, A (B omitted), B (A omitted), epsilon (both omitted). Since S -> epsilon must be removed (start nullable, epsilon-free requirement), drop it unless epsilon is in the language. Expand S -> BC: B C and C (B omitted).
  4. Final epsilon-free grammar: S -> AB | A | B | BC | C; A -> aA | a; B -> bB | b; C -> c.

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: All epsilon productions are removed while preserving all non-empty strings of L.

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

  • Nullable variables A and B
  • Expand S->AB and S->BC over nullable combinations
  • Final grammar S->AB|A|B|BC|C; A->aA|a; B->bB|b
Q2d7MUnit 4 — Pushdown Automata for Context Free Languages
Core Concept

Construct PDA that accepts L={anb2n∣n≥1}L = \{a^n b^{2n} \mid n \ge 1\}.

Answer: Use a PDA that pushes two markers for every a and pops one marker per b.

  1. Stack alphabet
{a,Z0}\{a, Z0\}

. Start in q0 with Z0. 2. On reading a in q0: push two a's (delta(q0,a,Z0)=(q0,aaZ0); delta(q0,a,a)=(q0,aaa)). 3. On the first b, pop one marker and switch to q1: delta(q0,b,a)=(q1,epsilon). 4. In q1, each b pops one a: delta(q1,b,a)=(q1,epsilon). 5. Accept by empty stack/final state q2 when Z0 is exposed after all b's: delta(q1,epsilon,Z0)=(q2,epsilon). Example: abb is accepted - one a pushes two markers and the two b's pop both. Input ab leaves one marker and is rejected; aaabbbbb (3 a's and 6 b's) is accepted.

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 PDA accepts L =

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

by pushing two symbols per a and popping one per b.

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 two stack symbols per a
  • Pop one per b after switching state
  • Accept when stack bottom exposed
Q2e7MUnit 5 — Post’s Correspondance Problem
Core Concept

Define the Post Correspondence Problem (PCP). Why is it considered undecidable?

Answer: The Post Correspondence Problem: given two lists of strings A = (a1,...,ak) and B = (b1,...,bk) over an alphabet, decide whether there is a non-empty sequence of indices i1,...,im with ai1a_{i1}...aima_{im} = bi1b_{i1}...bimb_{im}.

  1. Each pair is a domino with top string ai and bottom string bi.
  2. The problem asks for a chain of dominoes (repetitions allowed) whose top and bottom concatenations match.
  3. It is undecidable: PCP can encode the halting problem; given a TM, construct dominoes so that a solution exists iff the TM halts on a given input. Since the halting problem is undecidable, no algorithm can decide PCP.

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 asks for equal top/bottom concatenations and is undecidable by reduction from the halting problem.

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 pairs (top,bottom)
  • Find nonempty index sequence with equal concatenations
  • Undecidable via halting-problem reduction

Section C

7 Marks Each · 10 questions
Q3a7MUnit 1 — Non Deterministic Finite Automaton (NFA)
Core Concept

Define Non-Deterministic Finite Automata. Design an NFA to accept strings over {0, 1} containing the substring 1101.

Answer: An NFA is M = (Q, Sigma, delta, q0, F) where delta : Q x Sigma -> 2^Q may give several states; epsilon transitions are allowed. A string is accepted if there exists some run ending in F. To accept strings containing substring 1101, build states that track progress through the pattern plus a self-loop at the final state. States: q0 (no match yet), q1 (suffix 1), q2 (suffix 11), q3 (suffix 110), q4 (found 1101, final). Transitions:

State 0 1
q0
{q0}\{q0\}

|

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

| | q1 |

{q0}\{q0\}

|

{q1,q2}\{q1,q2\}

| | q2 |

{q2,q3}\{q2,q3\}

|

{q2}\{q2\}

| | q3 |

{q0}\{q0\}

|

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

| | q4 (final) |

{q4}\{q4\}

|

{q4}\{q4\}

|

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 NFA accepts a string iff 1101 appears as a substring; non-determinism allows restarting the match at any position.

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

  • NFA delta returns a set of states
  • States track progress toward 1101
  • Final state loops to absorb continuation
Q3b7MUnit 1 — Finite Automata with output- Moore Machine
Core Concept

Define the Moore machine. Design a Moore machine to generate 1's complement of given binary numbers.

Answer: A Moore machine is a finite-state machine with output determined only by the current state: M = (Q, Sigma, Delta, delta, q0, lambda) where lambda : Q -> Output maps every state to an output symbol. To generate the 1's complement of a binary input, output the complement of the last bit read; use an initial state with output epsilon/last complement. States: q0 (start, output epsilon or 1), q1 (last input 0, output 1), q2 (last input 1, output 0). Transitions and outputs:

State input 0 -> next (output) input 1 -> next (output)
q0 q1 (1) q2 (0)
q1 q1 (1) q2 (0)
q2 q1 (1) q2 (0)
Example input 1011 emits outputs 0,1,0,0 -> 0100, the complement.

Output determined by the current state. A Moore machine is a finite state machine with output in which the output symbol is determined solely by the current state, not directly by the input or by the transition. Formally it has a finite set of states, an input alphabet, an output alphabet, a transition function, an output function from states to output symbols and an initial state. Because the output depends only on the state, the output changes only at state transitions and is stable while the machine remains in a state. This makes Moore machines particularly suitable for synchronous sequential circuits where outputs are registered. The related Mealy machine assigns output to transitions, so the output can depend on the current input as well as the state and can change within a state. The two models are equivalent in power: any Moore machine can be converted to a Mealy machine by labelling each transition with the output of the destination state, and any Mealy machine can be converted to a Moore machine by splitting states according to the associated outputs, sometimes with an extra initial state to produce the correct first output. To build a Moore machine that generates the one's complement of a binary input string, use two states, one that outputs one and one that outputs zero. The start state outputs one, because the complement of zero is one. Reading a zero moves to the state that outputs one, and reading a one moves to the state that outputs zero, so the output produced after each input bit is the complement of that bit, with the initial output ignored. A complete answer defines the machine, draws the state table or diagram, explains the complement construction and traces a sample input. Mentioning the distinction from Mealy output timing shows understanding of why the model is organised this way.

Result: The Moore machine outputs one complement bit per input bit, delayed by one transition because output depends on the state.

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

  • Moore output depends only on state
  • State encodes last input bit
  • Input 1011 -> output 0100
Q4a7MUnit 2 — Regular Expressions
Core Concept

Write the regular expression for the languages: (i) Accepting all the strings containing any number of 0's and 1's over the set Σ={0,1}\Sigma = \{0, 1\}. (ii) Accepting all the strings starting with 10101 over alphabet {0, 1}.

Answer: (i) Any number of 0's and 1's over Sigma =

{0,1}\{0,1\}

: (0+1)* (this includes epsilon and all binary strings). (ii) Strings starting with 10101: the fixed prefix 10101 followed by any binary suffix: 10101(0+1)*. Examples: (i) epsilon, 0, 101, 010; (ii) 10101, 101010, 1010111.

Describing languages with patterns. A regular expression is a compact notation for describing a regular language using the operations of union, concatenation and Kleene star over symbols of the alphabet. The symbol star means zero or more repetitions, union means either alternative and concatenation means one followed by the other. Every regular expression corresponds to some finite automaton and every finite automaton can be converted into a regular expression, which is why the two descriptions have exactly the same expressive power. To write an expression for all binary strings we use the base alphabet and apply star to the union of the two symbols. To write an expression for strings beginning with a fixed prefix, we concatenate that prefix with the expression for all possible continuations. To require two consecutive zeros or two consecutive ones anywhere we combine the two subexpressions with union and allow arbitrary prefixes and suffixes through star terms. When a question asks for the shortest string not generated by an expression, enumerate strings in increasing length and test membership, using the structure of the expression to rule out whole families at once. For example, an expression built entirely from terms ending in a cannot generate a string beginning with b, so the single symbol b is immediately a candidate. Regular expressions also obey algebraic identities such as associativity, commutativity of union and distributivity, which are used to simplify expressions. A good answer writes the expression, explains what each subexpression contributes, and checks a few sample strings for membership and non membership. Mentioning that the Kleene star includes the empty string prevents a common mistake in reasoning about shortest excluded strings.

Result: The required expressions are (0+1)* and 10101(0+1)*.

O(nlog⁡n)O(n \log 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

  • All strings = (0+1)*
  • Fixed prefix 10101 then arbitrary suffix
  • Regexes: (0+1)* and 10101(0+1)*
Q4b7MUnit 2 — Algebraic Method Using Arden’s Theorem
Survival ModePredictedRepeated

Construct regular expression for given DFA using Arden's theorem.

Answer: Arden's theorem: if A = A P + Q and P does not contain epsilon, then A = Q P* is the unique solution. Take the DFA with q0 start, q1 final, transitions q0-0->q0, q0-1->q1, q1-0->q1, q1-1->q0 (strings with odd number of 1s).

  1. Equations: q0 = q0 0 + q1 1 + epsilon; q1 = q0 1 + q1 0.
  2. Solve q1 first: q1 = q0 1 0* by Arden.
  3. Substitute: q0 = q0 0 + q0 1 0* 1 + epsilon = q0 (0 + 1 0* 1) + epsilon.
  4. By Arden, q0 = (0 + 1 0* 1), the set of strings with an even number of 1s. Since q1 is the accepting state, L = q0 1 0.

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 of the DFA = (0 + 1 0 1) 1 0*** (all binary strings with an odd number of 1s).

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.
DFA for Arden solution A B a b a A = aA + bB, B = aB + epsilon, so A = a star b a star

Key Points

  • Arden: A = AP + Q -> A = QP*
  • Equations q0 = q00+q11+e, q1=q01+q10
  • Accepting state gives regex (0+10*1)10, odd number of 1s
Q5a7MUnit 3 — Greibach Normal Form (GNF)
Core Concept

Define Greibach Normal Form (GNF). Convert the following CFG into GNF: S→CDS \to CD, C→DS∣dC \to DS \mid d, D→SC∣cD \to SC \mid c.

Answer: Greibach Normal Form: every production has the form A -> a alpha, where a is a terminal and alpha is a (possibly empty) string of variables. Given S -> CD, C -> DS | d, D -> SC | c.

  1. Substitute until left recursion appears: S -> CD -> DSD | dD -> (SC | c)SD | dD -> S C S D | c S D | d D, i.e., S -> S(C S D) | c S D | d D.
  2. Eliminate left recursion: S -> c S D | d D | c S D S' | d D S'; S' -> C S D | C S D S'.
  3. Replace trailing variable strings by fresh variables. For example S -> c A1 | d A2 | c A3 | d A4, where A1 -> S D, A2 -> D, A3 -> S D S', A4 -> D S'. Substitute C -> D S | d and D -> S C | c into S', then use the terminal-leading forms of S again.
  4. Every production now has the form A -> a alpha, where a is a terminal and alpha is a string of variables; this is Greibach Normal Form.

Starting every production with a terminal. Greibach normal form is a form of context free grammar in which every production begins with a terminal symbol, followed by zero or more nonterminals. Every context free grammar that does not generate the empty string can be converted into an equivalent grammar in this form. The conversion first puts the grammar into Chomsky normal form, then orders the nonterminals and rewrites productions so that any right side beginning with a lower numbered nonterminal is replaced by the expansions of that nonterminal. This back substitution eventually leaves only right sides beginning with terminals. When a production begins with the same nonterminal that appears on the left, left recursion must be removed first by introducing a new nonterminal that generates the necessary tails. The resulting grammar has the useful property that each derivation step consumes exactly one terminal, so a string of length n is derived in exactly n steps. This property is used in proofs about pushdown automata construction, because a grammar in Greibach normal form can be converted directly into a pushdown automaton that simulates the derivation. A complete answer defines the form, explains the conversion steps and applies them to the given productions, showing the substitution and stating the final set of productions. Mentioning that the form cannot generate the empty string except for a trivial special case is an important boundary condition, and checking that every final production starts with a terminal is a quick correctness check on the answer.

Result: The grammar is converted to GNF by substitution, left-recursion removal and introduction of fresh variables so that every production starts with a terminal.

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

  • GNF form A -> a alpha
  • Eliminate left recursion after substitution
  • Introduce fresh variables for terminal-leading RHS
Q5b7MUnit 3 — Programming problems based on the properties of CFGs
Survival ModePredictedRepeated

What is ambiguity in a CFG? 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
Q6a7MUnit 4 — Two stack Pushdown Automata
Core Concept

Design Two Stack Pushdown Automata for the given language: L={anbncn∣n≥1}L = \{a^n b^n c^n \mid n \ge 1\}.

Answer: Use two stacks to count three equal blocks.

  1. Read a^n: push one marker X on stack 1 for each a.
  2. Read b^n: for each b, pop one X from stack 1 and push one marker Y on stack 2. If stack 1 empties early or b's remain, reject.
  3. Read c^n: for each c, pop one Y from stack 2. Accept if stack 2 is empty exactly at end of input.
  4. Transitions are deterministic for the correct order: q0 (reading a, push X), q1 (reading b, pop X/push Y), q2 (reading c, pop Y), qf when both stacks show bottom.

Two stacks are enough to simulate a tape. A pushdown automaton with two stacks is equivalent in computational power to a Turing machine. With one stack the machine can only access the most recently written symbol, but with two stacks it can simulate a tape by keeping the portion of the tape to the left of the head on one stack and the portion to the right, in reverse order, on the other. Moving the head one cell to the right corresponds to popping the symbol from the right stack and pushing it onto the left stack; moving left does the reverse. Reading and writing is done by replacing the top symbol of the right stack. This simulation shows why a single stack accepts only context free languages while two stacks accept every recursively enumerable language. To accept strings with equal numbers of a, b and c, one stack can count the excess of a over b while the other holds the a symbols for later comparison with c, or more simply one stack counts a symbols and the other counts b symbols and both are checked against the c count. The machine pushes on a, pops one stack on b and the other on c, accepting when both stacks return to their bottom markers together. A complete answer describes the tape simulation, explains what each stack stores for the specific language, lists the transition rules and traces a short accepted string. Mentioning that this equivalence is the reason two stack automata are not studied as a separate language class, because they are as powerful as Turing machines, shows understanding of the broader picture.

Result: The two-stack PDA accepts L =

{anbncn∣n>=1}\{a^n b^n c^n | n >= 1\}

; a single-stack PDA cannot because it cannot count three independent equal counts.

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

  • Stack 1 counts a's
  • Stack 2 counts matched b's
  • c's pop stack 2; one-stack PDA insufficient
Q6b7MUnit 4 — Deterministic Pushdown Automata(DPDA) and Deterministic Context free Languages(DCFL)
Core Concept

Why are NPDAs considered more powerful than DPDAs? Provide an example of a language accepted by NPDA but not by DPDA.

Answer: An NPDA may have several possible moves for the same (state, input, stack top) and accepts if some computation path accepts; a DPDA has at most one move for each configuration and accepts only by that unique path.

  1. NPDAs accept all context-free languages; DPDAs accept only deterministic CFLs, a proper subset.
  2. DPDA (with final-state acceptance) is closed under complement; NPDA is not.
  3. Example: L =
{wwR∣win{a,b}∗}\{ww^R | w in \{a,b\}*\}

requires guessing the midpoint (an epsilon transition competing with reading a symbol), so it is accepted by an NPDA but by no DPDA. The language

{anbn}\{a^n b^n\}

is deterministic and accepted by a DPDA.

When the next move is forced. A deterministic pushdown automaton has at most one possible move for any combination of state, input symbol and stack top, whereas a nondeterministic pushdown automaton may have several. This means a DPDA cannot guess where the middle of a palindrome occurs, so the language of even length palindromes is accepted by an NPDA but not by any DPDA. The languages accepted by DPDAs form the proper subset of context free languages called deterministic context free languages. These languages are important in programming language parsing because they can be recognized by efficient deterministic algorithms. For the language with equal numbers of a then b, a DPDA works because the transition is determined by the input symbol and stack top: read a and push, read b and pop, and accept when the stack returns to the bottom marker at the end of input. The first b unambiguously marks the switch from pushing to popping, so no guess is needed. An NPDA is more powerful precisely because it can choose among several transitions or guess a midpoint. A good answer gives the formal distinction, explains why determinism forbids guessing a boundary, gives the DPDA transitions for the equal count language and traces a sample string, and gives a concrete language such as palindromes that separates the two classes. Mentioning that deterministic context free languages are closed under complement while general context free languages are not adds a meaningful theoretical difference beyond the definition.

Result: NPDAs are strictly more powerful because non-determinism permits guessing (e.g., the middle of a palindrome), which a DPDA cannot do.

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

  • NPDA: multiple moves/accept if some path succeeds
  • DPDA: unique move per configuration
  • Example ww^R needs midpoint guessing
Q7a7MUnit 5 — Universal Turing machine
Core Concept

What is a Universal Turing Machine (UTM)? How does it simulate other Turing Machines?

Answer: A Universal Turing Machine (UTM) is a TM U that takes as input an encoded description of any TM M and an input w, and simulates M's computation on w.

  1. Encode M's states, alphabet, transitions and w on U's tape using a fixed coding (e.g., binary strings or delimited symbols).
  2. U keeps track of M's current state and head position using extra tape tracks/markers.
  3. For each step of M, U reads the encoded transition for (current state, scanned symbol), updates the simulated tape symbol, state and head position, then repeats.
  4. U halts and accepts/rejects exactly when M does.

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: A UTM can execute any algorithm; this formalises the stored-program computer and underlies the Church-Turing thesis.

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

  • UTM simulates any encoded TM
  • Tape holds machine description + input
  • Halts with same answer as simulated TM
Q7b7MUnit 5 — Techniques for Turing Machine Construction
Survival ModePredictedRepeated

Design a Turing machine that accepts L={02n∣n≥0}L = \{0^{2n} \mid n \ge 0\}.

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