Top Banner Ad
BCS402 · 2023-2422 Questions

Theory of Automata and Formal Languages — 2023-24

Section A

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

Give the mathematical definition of DFA. Differentiate between NFA and DFA.

A DFA has states, alphabet, one transition per symbol, start state and final states. An NFA may have several transitions on a symbol and epsilon moves. Both accept the same regular languages, but the NFA is often smaller to design while the DFA is easier to implement.

Key Points

  • DFA has unique transitions
  • NFA allows multiple choices
  • Both accept regular languages
Q1b2MUnit 1 — Deterministic Finite Automaton (DFA)- Definition
Survival ModePredictedRepeated

Construct Deterministic Finite Automata (DFA) to accept string that always ends with 101101 over alphabet Σ={0,1}\Sigma = \{0, 1\}.

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
Q1c2MUnit 2 — Regular Expressions
Survival Mode

Give regular expressions that represent the language (L), which has all binary strings having two consecutive 00s and two consecutive 11s over the alphabet Σ={0,1}\Sigma = \{0, 1\}.

A regular expression for binary strings containing both 00 and 11 is the union of the two patterns with arbitrary prefixes and suffixes: (0+1)*00(0+1)11(0+1) plus (0+1)*11(0+1)00(0+1). The two terms cover whichever block occurs first.

Key Points

  • Contains 00 and 11
  • Union covers either order
  • Star allows arbitrary surroundings
Q1d2MUnit 3 — Languages
Core Concept

Compute the Language generated by the given CFG G=({S},{a,b},P,S)\text{CFG } G = (\{S\}, \{a, b\}, P, S) where PP is defined by: S→SS,S→ab,S→ba,S→εS \to SS, S \to ab, S \to ba, S \to \varepsilon

The grammar generates all nonempty strings made by concatenating ab and ba, together with the empty string, because S can produce the empty string and any number of copies of ab or ba. Thus the language consists of the empty string and every nonempty even length string over a and b formed from these two blocks.

Key Points

  • Includes empty string
  • Concatenations of ab and ba
  • All generated strings have even length
Q1e2MUnit 3 — Derivations
Core Concept

Let GG be the grammar S→0B∣1AS \to 0B \mid 1A A→0∣0S∣1AAA \to 0 \mid 0S \mid 1AA B→1∣1S∣0BBB \to 1 \mid 1S \mid 0BB Determine the leftmost derivation for the string 0011010100110101.

S⇒0B⇒00BB⇒001SB⇒0011AB⇒00110SB⇒001101AB⇒0011010B⇒00110101S \Rightarrow 0B \Rightarrow 00BB \Rightarrow 001SB \Rightarrow 0011AB \Rightarrow 00110SB \Rightarrow 001101AB \Rightarrow 0011010B \Rightarrow 00110101. At each step replace the leftmost nonterminal: first choose 0BB, then 1S, then 1A, then 0S, then 1A, then 0, and finally replace the remaining B by 1. The sentential forms are called leftmost because only the leftmost variable is expanded every time.

Key Points

  • Leftmost nonterminal expanded at every step
  • Uses 0BB to start with two zeros
  • Ends at 00110101
  • Sentential forms shown in sequence
Q1f2MUnit 4 — Two stack Pushdown Automata
Survival ModePredicted

Explain the concept of two stack PDA. Give an example of a language that is accepted by two stack PDA but not accepted by normal one stack PDA.

A two stack PDA has two independent stacks and is equivalent in power to a Turing machine: one stack stores the tape to the left of the head and the other stores the tape to the right. It accepts languages such as strings with equal numbers of a, b and c that a one stack PDA cannot handle.

Key Points

  • Two independent stacks
  • Equivalent to Turing machine
  • Accepts a^n b^n c^n
Q1g2MUnit 5 — Modifications of Turing Machine
Survival ModePredicted

Explain Multi Tape Turing Machine.

A multi tape Turing machine has several tapes, each with its own read write head, and in one step can read, write and move on all tapes. It is equivalent in power to a single tape machine, since one tape with tracks can simulate several, but it solves many problems faster.

Key Points

  • Several tapes and heads
  • One step operates on all tapes
  • Equivalent but faster

Section B

7 Marks Each · 5 questions
Q2a7MUnit 1 — Deterministic Finite Automaton (DFA)- Definition
Core Concept

Construct a Finite automata (DFA) which accepts all binary numbers whose decimal equivalent is divisible by 4 over Σ={0,1}\Sigma = \{0, 1\}.

Answer: A binary number is divisible by 4 iff its last two bits are 00, with the single bit 0 also accepted. Track the last two input bits. States: q0 = suffix 00 or no bits (final), q1 = last bit 1, q2 = last bits 10, q3 = last bits 00 (final).

State 0 1
q0 (final) q0 q1
q1 q2 q1
q2 q3 q1
q3 (final) q3 q1
Check: 0 and 00 finish in q0 (final); 100 -> q3 (4) and 1100 -> q3 (12) accepted; 10 (2), 101 and 11 are rejected.

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 4-state DFA above accepts exactly binary strings whose value is divisible by 4.

δ(q0,a)=q1\delta(q_0, a) = q_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

  • Divisible by 4 iff last two bits are 00
  • States q0 and q3 are final; q0 also accepts the single 0
  • Final states marked in the table
Q2b7MUnit 2 — Algebraic Method Using Arden’s Theorem
Survival ModePredictedRepeated

Compute the regular expression using Arden's Theorem for the following DFA.

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
Q2c7MUnit 3 — Regular Grammars-Right Linear and Left Linear grammars
Core Concept

Write an equivalent left linear grammar from the given right linear grammar. S→OA∣1BS \to OA \mid 1B A→OC∣1A∣0A \to OC \mid 1A \mid 0 B→1B∣1A∣1B \to 1B \mid 1A \mid 1 C→0∣0AC \to 0 \mid 0A

Answer: To convert a right-linear grammar to left-linear, reverse the direction of derivations: a right-linear chain S => aA => abB becomes a left-linear chain S => Bb => Ba => ... with the same string read right-to-left. Given right-linear: S -> 0A | 1B; A -> 0C | 1A | 0; B -> 1B | 1A | 1; C -> 0 | 0A.

  1. Build the equivalent FA: S-0->A, S-1->B; A-0->C, A-1->A, A-0->final; B-1->B, B-1->A, B-1->final; C-0->final, C-0->A.
  2. Reverse all transitions and swap start/final states; then write productions with the terminal on the right of the variable.
  3. Left-linear equivalent (one standard form): S -> A0 | B1; A -> C0 | A1 | 0; B -> B1 | A1 | 1; C -> 0 | A0.

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 left-linear grammar S->A0|B1; A->C0|A1|0; B->B1|A1|1; C->0|A0 generates the same 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

  • Reverse FA transitions to convert right to left linear
  • Swap start and final states
  • Final left-linear rules listed
Q2d7MUnit 4 — Deterministic Pushdown Automata(DPDA) and Deterministic Context free Languages(DCFL)
Survival Mode

Differentiate between DPDA and NPDA. Construct a PDA that accepts language L={anbn∣n≥1}L = \{a^n b^n \mid n \ge 1\}.

Answer:

DPDA NPDA
At most one move per configuration Several moves possible
Accepts deterministic CFLs Accepts all CFLs
No midpoint guessing Can guess midpoint

PDA for L =

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

:

  1. q0: on a with stack Z0 push aZ0; on a with top a push aa (count a's).
  2. On first b with top a, go to q1 and pop one a: delta(q0,b,a)=(q1,epsilon).
  3. q1: on b with top a, pop one a: delta(q1,b,a)=(q1,epsilon).
  4. When Z0 is exposed, accept: delta(q1,epsilon,Z0)=(qf,epsilon). This machine is deterministic because each (state,input,top) has one move.

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: DPDACFLs are a subset of NPCFLs; the given deterministic PDA accepts a^n b^n.

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

  • Deterministic vs nondeterministic moves
  • DPDA accepts DCFL subset
  • PDA pushes a per a and pops per b
Q2e7MUnit 5 — Modifications of Turing Machine
Core Concept

Differentiate between Deterministic Turing machine and Non-Deterministic Turing machine. Design a Turing machine for the language L={ww∣w∈(a+b)∗}L = \{ww \mid w \in (a + b)^*\}.

Answer: A DTM has exactly one transition for each (state, tape symbol); an NTM may have several possible transitions and accepts if any branch accepts. They are equivalent in language power. TM for L =

{ww∣win(a+b)∗}\{ww | w in (a+b)*\}

(nondeterministic):

  1. Guess the midpoint: from q0, on each symbol write a marker (X for a, Y for b) and nondeterministically either continue or switch to q1 at any position.
  2. Remember the first-half symbols on the tape as markers; q1 moves right to the end of input, then reverses direction.
  3. Moving left, compare each first-half marker with the corresponding second-half symbol: X must match a, Y must match b; erase both.
  4. Accept when all symbols are erased; reject on mismatch. Example: abab -> guess midpoint after 'ab', compare a with a, b with b -> accept; abba rejected.

Different Turing machine models are equivalent. A deterministic Turing machine has at most one transition for each state and scanned symbol, while a nondeterministic Turing machine may have several possible moves and accepts if any sequence of choices leads to an accepting state. Although nondeterminism seems to add power, the two models accept exactly the same languages, because a deterministic machine can simulate the nondeterministic one by exploring the computation tree breadth first, keeping track of configurations. Multi tape Turing machines have several tapes and heads and can read or write on each in one step. They are also equivalent in power to single tape machines, since a single tape can be divided into tracks with markers to simulate several tapes, at the cost of a slower computation. Other variants include machines with two way infinite tapes, multiple heads or the ability to stay in place, and all of these leave the class of languages accepted unchanged. What changes is efficiency, not computational power. A machine for the language consisting of a string followed by the same string can mark corresponding symbols on two tracks of a multi tape machine, or on a single tape by shuttling the head back and forth. A complete answer defines each variant, explains a simulation argument for equivalence, gives the transitions for the requested language and traces a short input. Mentioning that equivalence is proved by simulation and that simulation may increase running time but not the set of accepted languages is the central point, and noting that nondeterministic machines accept the same language class but may decide it faster leads naturally to the distinction between polynomial time and nondeterministic polynomial time.

Result: The NTM accepts exactly doubled strings ww; deterministic TMs can also do it but need more work to find the midpoint.

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

  • DTM unique move vs NTM multiple branches
  • Guess midpoint, then compare halves right-to-left
  • Accepts ww; example abab accepted

Section C

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

Construct a DFA corresponding to the following NFA with ε\varepsilon moves:

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 in the minimum state automata equivalent to DFA described in below 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

State Pumping Lemma for Regular Language. Show that the given language L={ap Where p is a prime}L = \{a^p \text{ Where } p \text{ is a prime}\} 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 — Regular and Non-Regular Languages- Closure properties of Regular Languages
Core Concept

Discuss closure properties (i.e. union, concatenation complement, intersection and difference) of regular language.

Answer: Regular languages are closed under all the listed operations. If L1 and L2 are accepted by DFAs M1 and M2, construct product automata.

  1. Union: final states F = (F1 x Q2) union (Q1 x F2); accept if either component accepts.
  2. Concatenation: use NFAs; add epsilon transitions from every final state of M1 to the start of M2; final states are those of M2.
  3. Complement: determinise M1 if needed and swap final and non-final states: complement L = Sigma* - L.
  4. Intersection: final states F1 x F2 in the product automaton. Equivalently L1 intersect L2 = complement(complement L1 union complement L2).
  5. Difference: L1 - L2 = L1 intersect complement(L2), hence regular.

Regular languages are closed under the usual operations. A language class is closed under an operation if applying that operation to languages in the class always produces another language in the same class. Regular languages are closed under union, intersection, concatenation, complement, Kleene star and difference. The proofs are most easily given with finite automata. For union, run two automata in parallel and accept if either accepts; formally the states are pairs and a state is final when either component is final. For intersection, use the same product construction but accept only when both components are final. For complement, take a deterministic automaton for the language and swap final and non final states, which works because a DFA has exactly one run for every string. For concatenation, connect the accepting states of the first machine to the start state of the second with epsilon transitions in an nondeterministic machine. For star, add a new start state that is also accepting and an epsilon transition from every accepting state back to the start. Difference is expressed as intersection with the complement, so closure follows from the previous results. The product construction is the key idea behind union and intersection, and it also underlies many decidability results such as testing emptiness or equivalence of regular languages. A complete answer states each property, gives the construction or identity that proves it, and notes where determinism is required, specifically for complement where a nondeterministic machine would give the wrong answer if its final states were simply swapped. Mentioning that regular languages are not closed under subset or under the infinite union of arbitrary regular languages bounds the result correctly.

Result: Union, concatenation, complement, intersection and difference of regular languages are 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

  • Product construction for union/intersection
  • Complement by swapping final states after determinisation
  • Difference = intersection with complement
Q5a7MUnit 3 — Normal Forms- Chomsky Normal Form(CNF)
Core Concept

Reduce the given grammar G=({S,A,B},{a,b},P,S)G = (\{S, A, B\}, \{a, b\}, P, S) to Chomsky Normal form. Where PP is defined by: S→bA∣aBS \to bA \mid aB A→bAA∣aS∣aA \to bAA \mid aS \mid a B→aBB∣bS∣bB \to aBB \mid bS \mid b

Answer: Grammar: S -> bA | aB; A -> bAA | aS | a; B -> aBB | bS | b.

  1. It is already epsilon-free and has no unit productions. Terminals in long RHS must become variables: introduce Ca -> a, Cb -> b.
  2. Replace mixed RHS: S -> Cb A | Ca B.
  3. A -> Cb A A | Ca S | a (Ca or keep terminal a as A -> a is allowed in CNF). B -> Ca B B | Cb S | b.
  4. Break RHS of length 3: A -> Cb A A becomes A -> Cb X, X -> A A. B -> Ca B B becomes B -> Ca Y, Y -> 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: S -> CbA | CaB; A -> CbX | CaS | a; B -> CaY | CbS | b; X -> AA; Y -> BB; Ca -> a; Cb -> 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

  • No epsilon/unit productions initially
  • Replace terminals in long RHS by Ca, Cb
  • Introduce X->AA, Y->BB for binary CNF
Q5b7MUnit 3 — Programming problems based on the properties of CFGs
Core Concept

Design a CFG for the following language: (i) L={0m1n∣m≠n,m,n>=1}L = \{0^m 1^n \mid m \neq n, m, n >= 1\} (ii) L={apbqcr∣p+q=r&p,q>=1}L = \{a^p b^q c^r \mid p + q = r \& p, q >= 1\}

Answer: (i) L =

{0m1n∣m!=n,m,n>=1}\{0^m 1^n | m != n, m,n >= 1\}

is the union of two cases.

  • m > n: write m = n + k, k >= 1: 0^n 0^k 1^n -> S1 -> 0S1 | 0X; X -> 0X | 0.
  • m < n: write n = m + k, k >= 1: 0^m 1^m 1^k -> S2 -> 0S2 | Y1; Y -> Y1 | 1. Grammar: S -> S1 | S2; S1 -> 0S1 | 0X; X -> 0X | 0; S2 -> 0S2 | Y1; Y -> Y1 | 1. (ii) L =
{apbqcr∣p+q=r,p,q>=1}\{a^p b^q c^r | p+q = r, p,q >= 1\}

. Generate matching a's and b's as pairs and produce two c's per pair (one for each of p and q): S -> a S c | T; T -> b T c | b c. Example p=2,q=1 gives a a b c c c -> r = 3.

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: The two CFGs above generate exactly the specified unequal-count and p+q=r languages.

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

  • Case split m>n and m<n for (i)
  • Grammars with helper variables X,Y
  • For (ii) S->aSc, T->bTc|bc
Q6a7MUnit 4 — Pushdown Automata for Context Free Languages
Survival ModePredicted

Construct PDA equivalent to the following CFG G=({S,A},{0,1},P,S)G = (\{S, A\}, \{0, 1\}, P, S) where PP is defined by: S→0S1∣AS \to 0S1 \mid A A→1AO∣S∣εA \to 1AO \mid S \mid \varepsilon

Answer: Convert CFG G: S -> 0S1 | A; A -> 1A0 | S | epsilon into a top-down PDA whose stack holds sentential forms.

  1. States: q0 (processing), q1 (final). Stack starts with S and bottom Z0.
  2. For each production A -> alpha, add delta(q0,epsilon,A)=(q0,alpha) with A replaced by the reverse of alpha on the stack (so leftmost symbol is on top). Thus S->0S1 pushes 1 S 0; S->A pushes A.
  3. For each terminal a, add delta(q0,a,a)=(q0,epsilon) to match and pop input terminals.
  4. Add delta(q0,epsilon,Z0)=(q1,epsilon) to accept by final state when the whole sentential form has been consumed.
  5. Non-determinism chooses among alternative productions, exactly mirroring derivations.

Converting a pushdown automaton into a grammar. Every pushdown automaton has an equivalent context free grammar, which is the basis of the standard construction from automata to grammars. The construction creates a nonterminal for every ordered pair of states of the automaton, representing the language of input strings that take the machine from the first state to the second while leaving the stack exactly as it was found. For each transition that pops a symbol and pushes a single symbol while moving from state P to state Q on input a, add a production from the pair of P and Q to a. For transitions that push several stack symbols, introduce intermediate nonterminals that represent the effect of consuming each pushed symbol in turn, so that the nested calls reproduce the stack discipline. Variables are also added for the start and final states so that derivation begins and ends at the correct states. A string is accepted by empty stack exactly when the corresponding nonterminal can derive it, because the derivation mirrors the sequence of stack operations. A complete answer states what each pair variable means, derives the productions from the given transition functions, lists the resulting grammar and checks a short string derivation against an accepting computation of the automaton. Explaining why leaving the stack unchanged is the key invariant makes the construction intelligible rather than a set of arbitrary productions. Mentioning that the converse construction turns a grammar in Greibach normal form into a pushdown automaton shows that the two models are equivalent in power.

Result: A string is accepted by this PDA iff the CFG can derive it; the construction is the standard CFG-to-PDA conversion.

L={wwR∣w∈{a,b}}L = \{ww^R \mid w \in \{a, b\}\}
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 stores sentential forms
  • Epsilon moves expand variables by productions
  • Terminal moves match input; accept at Z0
Q6b7MUnit 4 — Context Free grammars for Pushdown Automata
Core Concept

Find the equivalent CFG of the following PDA P=({q0,q1},{a,b},{a,z0},δ,q0,z0)P = (\{q_0, q_1\}, \{a, b\}, \{a, z_0\}, \delta, q_0, z_0) where δ\delta is given by: δ(q0,a,z0)=(q0,az0)\delta(q_0, a, z_0) = (q_0, az_0) δ(q0,a,a)=(q1,aa)\delta(q_0, a, a) = (q_1, aa) δ(q1,a,a)=(q1,ε)\delta(q_1, a, a) = (q_1, \varepsilon) δ(q1,ε,z0)=(q1,ε)\delta(q_1, \varepsilon, z_0) = (q_1, \varepsilon)

Answer: Use the standard PDA-to-CFG construction: create a variable ApqA_{pq} generating all strings that take the PDA from state p to state q leaving the stack as it was found. Given P = (

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

,

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

,

{a,Z0}\{a,Z0\}

,delta,q0,Z0) with delta(q0,a,Z0)=(q0,aZ0), delta(q0,a,a)=(q1,aa), delta(q1,a,a)=(q1,epsilon), delta(q1,epsilon,Z0)=(q1,epsilon).

  1. For a push move that increases stack by one and goes p->r, and a later pop from r->q, add ApqA_{pq} -> a ArqA_{rq} a.
  2. For a move that leaves stack unchanged (p->r), add ApqA_{pq} -> a ArqA_{rq}.
  3. For epsilon moves, add ApqA_{pq} -> ArqA_{rq}.
  4. Base: AppA_{pp} -> epsilon.
  5. Start variable = Aq0qfA_{q0 qf}.

Converting a pushdown automaton into a grammar. Every pushdown automaton has an equivalent context free grammar, which is the basis of the standard construction from automata to grammars. The construction creates a nonterminal for every ordered pair of states of the automaton, representing the language of input strings that take the machine from the first state to the second while leaving the stack exactly as it was found. For each transition that pops a symbol and pushes a single symbol while moving from state P to state Q on input a, add a production from the pair of P and Q to a. For transitions that push several stack symbols, introduce intermediate nonterminals that represent the effect of consuming each pushed symbol in turn, so that the nested calls reproduce the stack discipline. Variables are also added for the start and final states so that derivation begins and ends at the correct states. A string is accepted by empty stack exactly when the corresponding nonterminal can derive it, because the derivation mirrors the sequence of stack operations. A complete answer states what each pair variable means, derives the productions from the given transition functions, lists the resulting grammar and checks a short string derivation against an accepting computation of the automaton. Explaining why leaving the stack unchanged is the key invariant makes the construction intelligible rather than a set of arbitrary productions. Mentioning that the converse construction turns a grammar in Greibach normal form into a pushdown automaton shows that the two models are equivalent in power.

Result: The grammar with variables AijA_{ij} and rules generated from the four transitions above is an equivalent CFG; the construction works by pairing stack push with matching pop.

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

  • Variables A_pq for state pairs
  • Rules for push/pop pairs and epsilon moves
  • Start symbol A_q0,qf
Q7a7MUnit 5 — Techniques for Turing Machine Construction
Predicted

Construct Turing Machine that accepts language L={a2nbn∣n≥1}L = \{a^{2n} b^n \mid n \ge 1\}. Also show the instantaneous description for the string w=aaaabbw = aaaabb.

Answer: L =

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

; pair two a's with each b.

  1. q0: mark first unmarked a as X, go right to q1.
  2. q1: skip X's and mark the next unmarked a as X, go to q2.
  3. q2: move right over X's to find b; mark it Y and return left to q0.
  4. When no unmarked a remains, verify no unmarked b remains; accept at blank. Instantaneous descriptions for w = aaaabb (n=2): q0 aaaabb X q1 aaabb X X q2 aabb (return to left end) q0 X X aabb X X X q1 abb X X X X q2 bb (return to left end) q0 X X X X bb X X X X Y q4 b (mark first b) q0 X X X X Y b X X X X Y Y q4 (mark second b) q0 X X X X Y Y -> blank -> qf (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 accepts aaaabb (2 pairs of a for 2 b's); unequal counts are rejected.

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 two a's then one b per pass
  • Use X for a's and Y for b's
  • w=aaaabb accepted by the shown IDs
Q7b7MUnit 5 — Recursive and Recursively Enumerable language
Core Concept

Explain the any two of the following: i. Universal Turing Machine. ii. Post Correspondence Problem. iii. Recursive and recursively Enumerables Languages.

Answer: Any two of the following:

  1. Universal Turing Machine (UTM): a TM that reads the encoded description of another TM M and its input w, then simulates M step by step, halting with the same result. It formalises the general-purpose computer.
  2. Post Correspondence Problem (PCP): given domino pairs (top_i, bottom_i), decide whether some non-empty sequence gives identical top and bottom concatenations. PCP is undecidable (reduction from the halting problem).
  3. Recursive and recursively enumerable languages: a language is recursive if a TM halts on every input and accepts/rejects correctly (decidable); it is recursively enumerable if a TM halts and accepts every member but may loop forever on non-members. Recursive languages are a proper subset of r.e. languages.

Decidable, semi decidable and beyond. A language is recursive, also called decidable, if there exists a Turing machine that halts on every input and accepts exactly the strings in the language, rejecting all others. A language is recursively enumerable, also called semi decidable or recognizable, if there exists a Turing machine that halts and accepts every string in the language but may either halt and reject or run forever on strings outside it. Every recursive language is recursively enumerable, but not every recursively enumerable language is recursive. The classic example is the halting problem, the set of descriptions of Turing machines that halt on their own description, which is recursively enumerable because we can simulate the machine and accept if it halts, but is not decidable because no machine can always determine in advance whether the simulation will terminate. The complement of a recursively enumerable language need not be recursively enumerable; a language is recursive exactly when both it and its complement are recursively enumerable. These distinctions matter because they tell us what can be solved by an algorithm at all. A good answer defines both classes, states the relationship between them, proves that a language is decidable if and only if it and its complement are semi decidable, and gives the halting problem as the canonical undecidable example. Mentioning that context free languages are decidable while general recursively enumerable languages are not places the result in the hierarchy of language classes and shows why the limit is meaningful.

Result: UTM = universal simulator, PCP = undecidable domino problem, recursive = decidable, r.e. = semi-decidable.

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 encoded TMs
  • PCP domino equality is undecidable
  • Recursive = decidable; r.e. = semi-decidable