2080.1

CSC262 · TU past paper

Theory of Computation 2080.1 question paper

The complete TU 2080.1 exam paper for Theory of Computation (CSC262), all 12 questions with solved model answers written to the mark scheme.

Tap a question to open its answer.

  1. 110 marksNumericalExtended TransitionAnswer

    Describe the extended transition function of NFA. Construct a NFA, using transition table and transition diagram, over {0, 1} that accept the string having substring 01 and ends with 1. Show the acceptance of 0111.[10]

    • Alphabet: $\Sigma = {0, 1}$ - Language: strings containing substring 01 AND ending with 1 - Test string: 0111 --- For an NFA $M = (Q, \Sigma, \delta, q0, F)$ where $\delta : Q \times \Sigma \to 2^Q$, the ordinary transition function ...
  2. 210 marksNumericalIntroduction to Context Free GrammarAnswer

    Define CFG. Construct a CFG that generates the language of all palindromes over {a,b} that do not contain the substring aa. Show the leftmost derivation and construct the equivalent parse tree for string babbbab.[10]

    Context-Free Grammar - Definition and Construction

    STEP 1 - EXTRACT: Given Data

    • Alphabet: $\Sigma = {a, b}$
    • Language: all palindromes over ${a,b}$ that do NOT contain substring $aa$
    • Target string for derivation and parse tree: babbbab
    • Marks: 10

    All required data is present.


    STEP 2 - SOLVE

    1. Definition of CFG

    A Context-Free Grammar is a 4-tuple $G = (V, T, P, S)$ where:

    • $V$ = finite set of variables (non-terminals)
    • $T$ = finite set of terminals, with $V \cap T = \varnothing$
    • $P$ = finite set of productions of the form $A \to \alpha$, where $A \in V$ and $\alpha \in (V \cup T)^*$
    • $S \in V$ = the start symbol

    Every production has exactly one non-terminal on the left, hence "context-free". CFGs generate the class of Context-Free Languages.


    2. Language Analysis

    $$L = {, w \in {a,b}^* \mid w = w^R \text{ and } aa \text{ is not a substring of } w ,}$$

    Constraints:

    • Palindrome: $w = w^R$
    • No $aa$: two $a$'s must never be adjacent

    Because $w$ is a palindrome, when we place an $a$ at both ends the inner string must not begin or end with $a$ (otherwise $aa$ would form at the junction). So an $a$-wrapped layer must contain an inner block that begins and ends with $b$ (or is a single $b$).

    Sample valid strings: $\varepsilon,\ a,\ b,\ aba,\ bab,\ bbb,\ babab,\ babbbab$. Invalid: $aa,\ baab,\ aabaa$.


    3. Constructing the CFG

    Use two variables:

    VariableMeaning
    $S$any palindrome without $aa$
    $B$a palindrome without $aa$ that starts and ends with $b$

    Productions $P$:

    $$ \begin{aligned} S &\to \varepsilon \mid a \mid b \ S &\to bSb \ S &\to aBa \ B &\to b \mid bSb \end{aligned} $$

    Grammar: $G = ({S,B},\ {a,b},\ P,\ S)$.

    Why $aa$ never occurs:

    • $S \to aBa$: the inner $B$ must start and end with $b$, giving $a,b\ldots b,a$, so no adjacent $a$'s at the junction.
    • $S \to bSb$ and $B \to bSb$: wrap with $b$'s, always safe.
    • No production ever places two $a$'s next to each other.

    The palindrome property holds because each recursive rule adds the same terminal symmetrically on both ends.


    4. Leftmost Derivation for babbbab

    Structural decomposition:

    $$ \underbrace{b}{\text{outer}}\ \underbrace{a}{}\ \underbrace{b\ b\ b}{\text{middle}}\ \underbrace{a}{}\ \underbrace{b}_{\text{outer}} $$

    • Outer $b\ldots b$ → $S \to bSb$
    • Inner $abbba$: $a\ldots a$ → $S \to aBa$
    • Inner $bbb$: $b\ldots b$ → $B \to bSb$
    • Center $b$ → $S \to b$

    Leftmost derivation (always expand leftmost non-terminal):

    StepSentential formProduction
    1$S$start
    2$bSb$$S \to bSb$
    3$baBab$$S \to aBa$
    4$babSbab$$B \to bSb$
    5$babbbab$$S \to b$

    $$S \Rightarrow bSb \Rightarrow baBab \Rightarrow babSbab \Rightarrow babbbab$$

    Result: $babbbab$ ✓ (matches target)


    5. Parse Tree for babbbab

                     S
                  /  |  \
                 b   S   b
                   / | \
                  a  B  a
                   / | \
                  b  S  b
                     |
                     b
    

    Reading the leaves left to right: $b,a,b,b,b,a,b = babbbab$ ✓

    The tree is symmetric about its center, confirming both the palindrome property and the absence of substring $aa$ (each $a$ is bounded by $b$'s).


    Final Answer: The CFG $G = ({S,B},{a,b},P,S)$ with productions $S \to \varepsilon \mid a \mid b \mid bSb \mid aBa,\ B \to b \mid bSb$ generates the required language. The leftmost derivation for $babbbab$ uses the sequence $S \Rightarrow bSb \Rightarrow baBab \Rightarrow babSbab \Rightarrow babbbab$, with the parse tree shown above.

  3. 310 marksNumericalTuring Machine as a Computing FunctionAnswer

    How Turing Machine is used as a computing function? Construct a TM for simulating a function f(x) = 2x for x = {1}. Iterate the TM for input 11 and generate the output 1111.[10]

    • Function to compute: $f(x) = 2x$ - Input alphabet symbol: $x \in {1}$ (unary representation) - Test input: 11 (i.e., $x = 2$) - Expected output: 1111 (i.e., $f(2) = 4$) - Representation: value $n$ = string of $n$ ones on the tape All...
  4. 45 marksNumericalPositive Closure of AlphabetAnswer

    Differentiate Kleen closure from positive closure. Compute positive and Kleen closure of {ab}. [5]

    • Set: ${ab}$ (a set containing a single element, the string "ab") - Required: differentiate Kleene closure from positive closure; compute both for ${ab}$. Property Kleene Closure ($L^$) Positive Closure ($L^+$) --------- Definition ...
  5. 55 marksFinite State Machines with outputAnswer

    Design a Mealy machine over {a, b} that generates output 'A' if the input string ends with aa else output 'B' if the string ends with bb. [5]

    A Mealy Machine is a 6-tuple M = (Q, Σ, Δ, δ, λ, q₀) where: - Q = finite set of states - Σ = input alphabet - Δ = output alphabet - δ = transition function (Q × Σ → Q) - λ = output function (Q × Σ → Δ) - q₀ = initial state Note: In a Mea...

  6. 65 marksRegular ExpressionsAnswer

    Construct regular expression over {1,2,...,9} that represents a. strings of even numbers with length 4 starting with 2 and ending with 8. b. strings starting with odd numbers and ending with even numbers. [5]

    • Concatenation (.): places symbols/expressions one after another - Union (+): matches either expression - Kleene Star (): zero or more repetitions - Kleene Plus (+): one or more repetitions --- Constraints: - Length exactly 4 - First sy...
  7. 75 marksPumping Lemma for CFLAnswer

    Prove that th language is not a context free grammar. $L = {a^n b^n c^n \mid n \geq 0}$ [5]

    --- If A is a Context Free Language, then A has a pumping length P such that any string s where s ≥ P may be divided into 5 pieces s = uvxyz satisfying: 1. uv^i xy^i z ∈ A for every i ≥ 0 2. vy 0 (v and y are not both empty) 3. vxy ≤ P -...

  8. 85 marksNumericalConstruction of PDA by Final StateAnswer

    Construct a PDA that accepts string over Σ={a,b}\Sigma = { a, b }Σ={a,b} that contains equal number of a's followed by equal number of b's. Show acceptance of aabb and aab. [5]

    PDA for $L = {a^n b^n \mid n \geq 1}$

    STEP 1 - Given Data

    • Alphabet: $\Sigma = {a, b}$
    • Language: strings with equal number of $a$'s followed by equal number of $b$'s
    • Strings to test: $aabb$ and $aab$

    $$L = {a^n b^n \mid n \geq 1} = {ab, aabb, aaabbb, \ldots}$$


    STEP 2 - Construction and Solution

    Strategy

    1. Push each $a$ onto the stack.
    2. On the first $b$, start popping $a$'s.
    3. On subsequent $b$'s, keep popping $a$'s.
    4. Accept when only $Z_0$ remains after all input consumed (empty count).

    Formal Definition

    $$M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$$

    • $Q = {q_0, q_1, q_2}$
    • $\Sigma = {a, b}$
    • $\Gamma = {a, Z_0}$
    • Start state $q_0$, initial stack symbol $Z_0$
    • $F = {q_2}$

    Transition Table

    StateInputStack TopPushNext State
    $q_0$$a$$Z_0$$aZ_0$$q_0$
    $q_0$$a$$a$$aa$$q_0$
    $q_0$$b$$a$$\varepsilon$$q_1$
    $q_1$$b$$a$$\varepsilon$$q_1$
    $q_1$$\varepsilon$$Z_0$$Z_0$$q_2$

    Notation: input, top / pushed-string.


    Acceptance of $aabb$

    StepStateRemaining InputStack (top→bottom)Transition
    1$q_0$$aabb$$Z_0$$a,Z_0/aZ_0$
    2$q_0$$abb$$aZ_0$$a,a/aa$
    3$q_0$$bb$$aaZ_0$$b,a/\varepsilon$
    4$q_1$$b$$aZ_0$$b,a/\varepsilon$
    5$q_1$$\varepsilon$$Z_0$$\varepsilon,Z_0/Z_0$
    6$q_2$$\varepsilon$$Z_0$halt in final state

    Input consumed, final state $q_2$ reached. $aabb$ is ACCEPTED.


    Acceptance of $aab$

    StepStateRemaining InputStack (top→bottom)Transition
    1$q_0$$aab$$Z_0$$a,Z_0/aZ_0$
    2$q_0$$ab$$aZ_0$$a,a/aa$
    3$q_0$$b$$aaZ_0$$b,a/\varepsilon$
    4$q_1$$\varepsilon$$aZ_0$stack top is $a$, but no $\varepsilon$-move on $a$ in $q_1$

    Input exhausted while stack still holds an unmatched $a$ (top $\neq Z_0$), so $q_2$ cannot be reached. $aab$ is REJECTED (2 a's, 1 b: unequal).


    Summary

    Stringa'sb'sResult
    $aabb$22Accepted ($n=2$)
    $aab$21Rejected

    The PDA correctly accepts $a^n b^n$ and rejects strings with unequal counts.

    Keep the transition table precise: write the $q_2$ transitions so that the empty-stack case is distinguished rather than folded into a,ε/a, and avoid an extra initialization state. The verdicts (accept $aabb$, reject $aab$) are unaffected.

  9. 95 marksRestricted Turing MachinesAnswer

    Describe how multi-stack TM is different from the semi-infinite tape TM? [5]

    A Counter Machine is an offline TM whose storage tapes are semi-infinite (the tape extends infinitely in only one direction) and whose tape alphabet contains only two symbols: - Z -- the bottom-of-stack marker, which appears initially on...

  10. 105 marksIntractabilityAnswer

    What is intractability? Define time and space complexity of turing machine. [5]

    Intractability and Time/Space Complexity of Turing Machine

    Intractability

    Intractability is a concept used to classify problems that cannot be solved in polynomial time but instead require exponential time algorithms.

    • Problems that can be solved within reasonable time and space constraints are called tractable problems.
    • Problems that cannot be solved in polynomial time but require exponential time algorithms are called intractable (or hard) problems.

    An algorithm whose complexity measure increases with input size n no more rapidly than a polynomial in n is said to be polynomially bounded. An algorithm whose complexity grows exponentially is said to be exponentially bounded, and such problems fall under intractability.

    Example: Problems like the Travelling Salesman Problem (decision version) are considered intractable as no known polynomial-time algorithm exists for them.


    Time and Space Complexity of a Turing Machine

    When a Turing Machine (TM) answers a specific instance of a decision problem:

    • Time is measured as the number of moves made during computation.
    • Space is measured as the number of tape squares used during computation.

    The most natural measure of input size is the length of the input string. The worst case is considered, i.e., the maximum time or space required for any input string of that length.


    Time Complexity

    Let T be a Turing Machine. The time complexity of T is the function T_t defined on the natural numbers as:

    For n ∈ N, T_t(n) is the maximum number of moves T can make on any input string of length n.

    • If there exists an input string x such that |x| = n and T loops forever on input x, then T_t(n) is undefined.

    Space Complexity

    The space complexity of T is the function S_t defined as:

    S_t(n) is the maximum number of tape squares used by T for any input string of length n.

    • If T is a multi-tape TM, the number of tape squares means the maximum of the number of squares used across individual tapes.
    • If for some input of length n, T loops forever, then S_t(n) is undefined.

    Summary Table

    MeasureDefinition
    Time Complexity T_t(n)Maximum number of moves on any input of length n
    Space Complexity S_t(n)Maximum number of tape squares used on any input of length n
    Undefined whenT loops forever on some input of length n

    Note: In complexity theory, we are always more interested in the growth rate of these functions rather than their absolute values.

  11. 115 marksConversion of PDA to CFGAnswer

    How is conversion of PDA to CFG done? Illustrate with example. [5]

    Given a Pushdown Automaton (PDA) P = (Q, Σ, Γ, δ, q₀, Z₀, F), we can construct an equivalent Context-Free Grammar (CFG) G = (V, T, R, S). --- For each pair of states (p, q) in the PDA, we create a non-terminal symbol A[p,q], which repres...

  12. 125 marksNumericalConversion of DFA to Regular ExpressionAnswer

    State Arden's theorem. Convert following DFA into its regular expression using Arden theorem.

    01
    $\rightarrow *Q1$$Q1$$Q2$
    $Q2$$Q3$$Q2$
    $Q3$$Q1$$Q2$

    [5]

    Transition table: State 0 1 ------------- →Q1 Q1 Q2 Q2 Q3 Q2 Q3 Q1 Q2 - Start state: Q1 - Final state: Q1 If $P$ and $Q$ are regular expressions over $\Sigma$, and $P$ does not contain $\varepsilon$, then the equation $$R = Q + RP$$ has ...