2076

CSC262 ยท TU past paper

Theory of Computation 2076 question paper

The complete TU 2076 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. Q1.10 marksReduction of Regular Expression to ฮต โ€“ NFAAnswer

    Define the NFA with ฯตโˆ’transition\epsilon-transitionฯตโˆ’transition and ฯตโˆ’closure\epsilon-closureฯตโˆ’closure of a state. Show that for every regular expression r, representing a language L, there is ฯตโˆ’NFA\epsilon-NFAฯตโˆ’NFA accepting the same language. Also convert regular expression (a+b)ab into equivalent Finite Automata.[10]

    NFA with ฮต-Transition, ฮต-Closure, and Regular Expression to FA Conversion


    1. NFA with ฮต-Transition (ฮต-NFA)

    An NFA with ฮต-transition (also called ฮต-NFA) is a Nondeterministic Finite Automaton that allows transitions on the empty string ฮต (without consuming any input symbol).

    Formally, an ฮต-NFA is defined as a 5-tuple:

    M = (Q, ฮฃ, ฮด, qโ‚€, F)

    where:

    • Q = finite set of states
    • ฮฃ = finite input alphabet
    • ฮด : Q ร— (ฮฃ โˆช {ฮต}) โ†’ 2^Q = transition function (can take ฮต as input)
    • qโ‚€ โˆˆ Q = start state
    • F โІ Q = set of final/accepting states

    The key difference from a standard NFA is that the transition function accepts ฮต as a valid input, allowing the automaton to move from one state to another without reading any symbol.


    2. ฮต-Closure of a State

    The ฮต-closure of a state q is the set of all states reachable from q by following zero or more ฮต-transitions (including q itself).

    ฮต-closure(q) = {p โˆˆ Q | p is reachable from q using only ฮต-transitions}

    Properties:

    • q is always in ฮต-closure(q) (reflexive)
    • If p โˆˆ ฮต-closure(q) and r โˆˆ ฮต-closure(p), then r โˆˆ ฮต-closure(q) (transitive)

    Example: If q --ฮต--> p --ฮต--> r, then ฮต-closure(q) = {q, p, r}


    3. Theorem: For Every Regular Expression r, There Exists an ฮต-NFA Accepting L(r)

    Proof by Structural Induction (Thompson's Construction Rules):

    We show construction rules for each case of a regular expression.


    Base Cases

    Rule 1: r = โˆ… (empty language)

      โ†’[qโ‚€]  (no transitions, no final state)
    

    The ฮต-NFA has start state qโ‚€ with no accepting states.


    Rule 2: r = ฮต (empty string)

      โ†’[qโ‚€] --ฮต--> ((q_f))
    

    One ฮต-transition from start to final state.


    Rule 3: r = a (single symbol a โˆˆ ฮฃ)

      โ†’[qโ‚€] --a--> ((q_f))
    

    One transition on symbol a from start to final state.


    Inductive Cases

    Assume ฮต-NFAs N(r) and N(s) exist for regular expressions r and s.


    Rule 4: r = rโ‚ | rโ‚‚ (Union / Alternation)

    Create a new start state and new final state, connect with ฮต-transitions:

                  ฮต --> [N(rโ‚)] --> ฮต
      โ†’[qโ‚€] --<                        >--> ((q_f))
                  ฮต --> [N(rโ‚‚)] --> ฮต
    
    • New start state qโ‚€ goes to start of N(rโ‚) and N(rโ‚‚) via ฮต
    • Final states of N(rโ‚) and N(rโ‚‚) go to new final state q_f via ฮต

    Rule 5: r = rโ‚ . rโ‚‚ (Concatenation)

    Connect the final state of N(rโ‚) to the start state of N(rโ‚‚) via ฮต:

      โ†’[N(rโ‚)] --ฮต--> [N(rโ‚‚)]-->((q_f))
    
    • Final state of N(rโ‚) becomes non-final
    • ฮต-transition connects it to start of N(rโ‚‚)

    Rule 6: r = rโ‚ (Kleene Star / Closure)*

             ฮต (loop back)
             โ†‘___________โ†“
      โ†’[qโ‚€] --ฮต--> [N(rโ‚)] --ฮต--> ((q_f))
          |_________________________โ†‘
                      ฮต (skip, for empty string)
    
    • New start state qโ‚€ connects to start of N(rโ‚) via ฮต
    • Final state of N(rโ‚) loops back to start of N(rโ‚) via ฮต
    • New start state also connects directly to new final state via ฮต (to accept ฮต)

    Since every regular expression is built from these base cases and operations, and we have shown an ฮต-NFA construction for each, by induction, every regular expression has an equivalent ฮต-NFA. โˆŽ


    4. Convert Regular Expression (a+b)ab to Equivalent Finite Automaton

    The regular expression is: (a+b)*ab*

    This means: strings over {a,b} that contain at least one 'a', ending with zero or more b's -- more precisely, any string of a's and b's, followed by 'a', followed by zero or more b's.

    Step 1: Break the expression into parts

    PartMeaning
    (a+b)*Zero or more a's or b's (any string)
    aSingle symbol a
    b*Zero or more b's

    Step 2: Build ฮต-NFA for each part

    Part 1: (a+b)*

             a
        ฮต โ†—[qโ‚]โ†˜ ฮต
    [qโ‚€]          [qโ‚ƒ] --ฮต--> ((qโ‚„))
        ฮต โ†˜[qโ‚‚]โ†— ฮต
             b
    

    With loop: qโ‚„ --ฮต--> qโ‚€ (for the * closure), and qโ‚€ --ฮต--> qโ‚„ (for accepting zero repetitions of (a+b), i.e. the empty string). This gives the complete ฮต-NFA fragment for (a+b)*, with qโ‚€ as its start state and qโ‚„ as its accepting state.

    Part 2: Single symbol a

      โ†’[q5] --a--> ((q6))
    

    Part 3: b*

            ฮต (loop back)
            โ†‘___________โ†“
      โ†’[q7] --ฮต--> [q8] --b--> ((q9))
          |_____________________โ†‘
                      ฮต (skip, for zero b's)
    

    Step 3: Concatenate the Three Parts

    By the concatenation rule (Rule 5 above), the accepting state of one block is joined to the start state of the next block with an ฮต-transition, and it stops being an accepting state in its own right (only the final block keeps an accepting state):

    • qโ‚„ --ฮต--> qโ‚… (end of the (a+b)* block feeds into the mandatory a)
    • qโ‚† --ฮต--> qโ‚‡ (end of the mandatory a feeds into the b* block)

    Step 4: Complete ฮต-NFA for (a+b)*ab*

    StateOn ฮตOn aOn b
    q0 (start)q1, q2, q4----
    q1--q3--
    q2----q3
    q3q0----
    q4q5----
    q5--q6--
    q6q7----
    q7q8, q9----
    q8q9--q8
    q9 (accept)------

    Verification:

    • On "ab": q0 --ฮต--> q4 (zero repetitions of (a+b)) --ฮต--> q5 --a--> q6 --ฮต--> q7 --ฮต--> q9 (zero b's). Accepted.
    • On "aabb": q0 --ฮต--> q1 --a--> q3 --ฮต--> q0 --ฮต--> q4 --ฮต--> q5 --a--> q6 --ฮต--> q7 --ฮต--> q8 --b--> q8 --b--> q8 --ฮต--> q9. The symbols consumed, in order, are a (one turn of the star), a (the mandatory a), b, b (two turns of b*), i.e. exactly "aabb". Accepted.

    This ฮต-NFA accepts precisely the language of (a+b)*ab*: any string over {a, b} (possibly empty), followed by a mandatory a, followed by zero or more b's. This completes the required conversion of the regular expression to an equivalent finite automaton via Thompson's construction.

  2. Q2.10 marksConversion of PDA by Final State to PDA acAnswer

    How can you define the language accepted by a PDA? Explain how a PDA accepting language by empty stack is converted into an equivalent PDA accepting by final state and vice-versa.[10]

    A Pushdown Automaton (PDA) is a 7-tuple: $$P = (Q, \Sigma, \Gamma, \delta, q0, Z0, F)$$ Where: - $Q$ = finite set of states - $\Sigma$ = input alphabet - $\Gamma$ = stack alphabet - $\delta$ = transition function:

  3. Q3.10 marksIntroduction to Turing MachinesAnswer

    Define a Turing machine. Construct a TM that accept $L = { wcw^R \mid w \in {0, 1} \text{ and } c \text{ is } \varepsilon \text{ or } 0 \text{ or } 1 }$. Show that string 0110 is accepted by this TM with sequence of Instantaneous Description (ID). [10]

    A Turing Machine (TM) is a theoretical model of computation defined as a 7-tuple: $$TM = (Q, \Sigma, \Gamma, \delta, q0, B, F)$$ Where: Component Meaning -------------------- $Q$ Finite set of states $\Sigma$ Input alphabet (finite set of input symbols) $\Gamma$ Tape alphabet (

  4. Q4.5 marksDeterministic Finite AutomataAnswer

    Give the formal definition of DFA. Construct a DFA accepting all strings of {0, 1} with even number of 0's and even number of 1's. [5]

    A Deterministic Finite Automaton (DFA) is a 5-tuple: $$M = (Q, \Sigma, \delta, q0, F)$$ Where: Component Description ------------------------ $Q$ A finite, non-empty set of states $\Sigma$ A finite set of input symbols (alphabet) $\delta$ A transition function:

  5. Q5.5 marksChomsky Normal FormAnswer

    Define Chomsky Normal Form and Greibach Normal Form in reference to CFG. Give a suitable example of each. [5]

    --- A Context-Free Grammar (CFG) is said to be in Chomsky Normal Form if every production rule is of exactly one of the following two forms: A โ†’ BC (a non-terminal produces exactly two non-terminals) A โ†’ a (a non-terminal produces exactly one terminal) Where A, B, C are non-terminal symbols and a...

  6. Q6.5 marksRegular ExpressionsAnswer

    Give the regular expressions for following language over alphabet {0, 1}. a. Set of all strings with 2nd symbol from right is 1. b. Set of all strings starting with 00 or 11 and ending with 10 or 01. [5]

    Analysis: To ensure the 2nd symbol from the right is 1, the string must have the form: - The last symbol can be either 0 or 1, i.e., (0+1) - The 2nd from right must be 1 - Before that, there can be any string of 0s and 1s (including empty), i.e., (0+1) Regular Expression: $$R = (0+1)^ \cdot 1 \cd...

  7. Q7.5 marksPumping LemmaAnswer

    Show that language is not a regular language. $L = { 0^m 1^m \mid m \geq 1 }$ [5]

    --- If A is a regular language, then there exists a pumping length p such that any string s with s โ‰ฅ p can be divided into three parts s = xyz satisfying: 1. xy^i z โˆˆ A for every i โ‰ฅ 0 2. y 0 (y cannot be empty) 3. xy โ‰ค p (xy together must not exceed pumping length) --- Step 1: Assume L is regula...

  8. Q8.5 marksTuring Machine with Multiple TapesAnswer

    Describe the Turing machines with multiple tape, multiple track and storage in state. [5]

    --- A multiple tape Turing Machine is an extension of the standard TM that has k independent tapes, each with its own read/write head. The standard TM is a special case where k = 1. The transition function is extended as: This means: given the current state and the symbols scanned on all k tapes,...

  9. Q9.5 marksMethod for reduction of NFA to DFAAnswer

    Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA. [5]

    NFA Accepting Strings Ending with 01, and its Equivalent DFA

    Part 1: Constructing the NFA

    Language: L = { w | w โˆˆ {0,1}* and w ends with 01 }

    Example strings: 01, 001, 101, 0001, 1101, ...

    NFA States and Design

    We need 3 states:

    StateRole
    q0Start state (reading any symbol, staying in loop)
    q1Just read '0' (possible start of ending "01")
    q2Just read '01' -- Final/Accept state

    NFA Transition Diagram

         0,1          0              1
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚      โ–ผ    โ”‚      โ–ผ       โ”‚      โ–ผ
     (q0) โ”€โ”€0โ”€โ”€โ–บ (q1) โ”€โ”€1โ”€โ”€โ–บ  ((q2))
      โ–ฒ                           
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    

    More precisely:

    • q0 loops on both 0 and 1 (to consume any prefix)
    • q0 on input 0 also goes to q1 (non-deterministic choice)
    • q1 on input 1 goes to q2 (accept)
    • q2 has no outgoing transitions

    NFA Transition Table

    StateInput 0Input 1
    โ†’q0{q0, q1}{q0}
    q1{}{q2}
    *q2{}{}

    โ†’ = start state, * = final state


    Part 2: Converting NFA to Equivalent DFA (Subset Construction)

    Each DFA state represents a subset of NFA states.

    Step 1: Start State

    DFA start state = {q0}

    Step 2: Compute Transitions for Each DFA State

    For {q0}:

    • On 0: ฮด(q0, 0) = {q0, q1} โ†’ new state {q0, q1}
    • On 1: ฮด(q0, 1) = {q0} โ†’ state {q0}

    For {q0, q1}:

    • On 0: ฮด(q0,0) โˆช ฮด(q1,0) = {q0,q1} โˆช {} = {q0, q1}
    • On 1: ฮด(q0,1) โˆช ฮด(q1,1) = {q0} โˆช {q2} = {q0, q2} โ†’ new state

    For {q0, q2}:

    • On 0: ฮด(q0,0) โˆช ฮด(q2,0) = {q0,q1} โˆช {} = {q0, q1}
    • On 1: ฮด(q0,1) โˆช ฮด(q2,1) = {q0} โˆช {} = {q0}

    Step 3: DFA Transition Table

    DFA StateOn 0On 1Final?
    โ†’ A = {q0}B = {q0,q1}A = {q0}No
    B = {q0,q1}B = {q0,q1}C = {q0,q2}No
    *C = {q0,q2}B = {q0,q1}A = {q0}Yes (contains q2)

    C is a final state because it contains q2 (the NFA's final state).

    Step 4: DFA Transition Diagram

            0              0
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚          โ–ผ    โ”‚         โ–ผ
     (A) โ”€โ”€0โ”€โ”€โ–บ (B) โ”€โ”€1โ”€โ”€โ–บ  ((C))
      โ–ฒ    1     โ”‚              โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    0         โ”‚ 1
           โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    

    Simplified transitions:

         1          0           1
    (A) โ”€โ”€โ–บ (A)   (A) โ”€โ”€โ–บ (B) โ”€โ”€โ–บ (C)
                    (B) โ”€โ”€โ–บ (B)
                    (C) โ”€โ”€โ–บ (B)
                    (C) โ”€โ”€1โ”€โ”€โ–บ (A)
    

    Summary

    • 3 DFA states are sufficient: A, B, C
    • C = {q0, q2} is the only final state
    • The DFA correctly accepts all strings over {0,1} that end with 01
  10. Q10.5 marksAcceptance of strings by PDAAnswer

    Construct a PDA accepting language over {0, 1} representing strings with equal no of 0s and 1s. Show by sequence of IDs that 0101 is accepted by this PDA. [5]

    A Pushdown Automaton (PDA) is a 7-tuple: M = (Q, ฮฃ, ฮ“, ฮด, qโ‚€, Zโ‚€, F) --- Language: L = { w โˆˆ {0,1} 0(w) = 1(w) } Idea: Use the stack to track the difference between counts of 0s and 1s. - Push a symbol when one character is in excess. - Pop when the opposite character is read. - Accept when the s...

  11. Q11.5 marksTime and Space complexity of A Turing MachAnswer

    Define complexity of a Turing machine. Explain about big Oh, big Omega and big Theta notation used for complexity measurement. [5]

    The complexity of a Turing Machine refers to the measurement of resources (primarily time and space) used during a computation. When a Turing Machine answers a specific instance of a decision problem: - Time is measured as the number of moves made by the TM. - Space is measured as the number of t...

  12. Q12.5 marksIntractabilityAnswer

    What do you mean by tractable and Intractable problems? Explain with reference to TM. [5]

    A problem is said to be tractable if it can be solved within reasonable time and space constraints. More formally, a problem is tractable if there exists an algorithm whose complexity (time and space) grows no more rapidly than a polynomial function of the input size n. - An algorithm satisfying ...