Course Test · University: upper level

Theory of computation: independent answers

Each answer here was worked out by hand, without RatMath, before the RatMath code was written. Where the arithmetic is long, the working says how it was checked.

  1. 1.Deterministic automata
    Design a DFA over {0,1}\{0, 1\} accepting words with an even number of 1s. Does it accept 1011? 1001?
    Answer
    Two states, even (start, accepting) and odd, swapped by each 1. 1011 has three 1s: rejected. 1001 has two: accepted.
  2. 2.Minimal DFA
    How many states does the minimal DFA for binary words ending in 01 have?
    Answer
    It must remember whether the word ends in nothing useful, in 0, or in 01: three states, which are pairwise distinguishable (by the suffixes 01, 1, and ε\varepsilon).
  3. 3.Subset construction
    Convert (a∣b)∗abb(a|b)^*abb to a DFA and minimise it. How many states? Does it accept aababbaababb and abababab?
    Answer
    The minimal DFA tracks the longest suffix that is a prefix of abbabb: ε,a,ab,abb\varepsilon, a, ab, abb: 4 states. aababbaababb ends in abbabb: yes; abababab: no.
  4. 4.Equivalent regular expressions
    Are (a∣b)∗(a|b)^* and (a∗b∗)∗(a^*b^*)^* equivalent?
    Answer
    Yes: both denote all words over {a,b}\{a, b\} (every letter is an a∗b∗a^*b^* block).
  5. 5.Product construction
    Build an automaton for words over {a,b}\{a, b\} with an even number of aas and an odd number of bbs. Test aabaab and abab.
    Answer
    Pair the two 2-state parity automata: 4 states, accepting (even, odd). aabaab: 2 aas, 1 bb: yes. abab: no.
  6. 6.From DFA to regular expression
    Give a regular expression for binary words with an even number of 1s.
    Answer
    0∗(10∗10∗)∗0^*(10^*10^*)^*, or equivalently 0∗∣0∗1(0∣10∗1)∗10∗0^* \mid 0^*1(0 \mid 10^*1)^*10^*.
  7. 7.Context-free grammars
    Give a grammar for {anbn:n≥0}\{a^nb^n : n \ge 0\}. Does it generate aabbaabb? aabaab? List its words of length at most 6.
    Answer
    S→aSb∣εS \to aSb \mid \varepsilon. aabbaabb: yes; aabaab: no. Words: ε,ab,aabb,aaabbb\varepsilon, ab, aabb, aaabbb.
  8. 8.Chomsky normal form
    Convert S→aSb∣εS \to aSb \mid \varepsilon to Chomsky normal form.
    Answer
    New start S0→ε∣SS_0 \to \varepsilon \mid S; remove ε\varepsilon: S→aSb∣abS \to aSb \mid ab; terminals A→aA \to a, B→bB \to b; split: S→AX∣ABS \to AX \mid AB, X→SBX \to SB, and S0→ε∣AX∣ABS_0 \to \varepsilon \mid AX \mid AB.
  9. 9.Pushdown automata
    Run a PDA for anbna^nb^n (push on aa, pop on bb) on aabbaabb and aabaab.
    Answer
    aabbaabb: push, push, pop, pop, the stack is back to its bottom: accept. aabaab: one AA is left: reject.
  10. 10.Pumping lemma
    Prove that {anbn}\{a^nb^n\} is not regular.
    Answer
    If it were, with pumping length pp, write apbp=xyza^pb^p = xyz with ∣xy∣≤p|xy| \le p, ∣y∣≥1|y| \ge 1. Then y=aky = a^k, and xy2z=ap+kbpxy^2z = a^{p+k}b^p is not in the language. Contradiction.
  11. 11.Turing machines
    Run a Turing machine that adds one to a binary number on the input 1011.
    Answer
    Move to the right end, turn trailing 1s into 0s moving left, then turn the first 0 into 1: 1011+1=11001011 + 1 = 1100.
  12. 12.Primitive recursion
    Using only primitive recursive building blocks, compute 3+43 + 4, 2102^{10} and 7!7!.
    Answer
    77, 10241024, 50405040.
  13. 13.Composition of recursive functions
    Define d(x)=x+xd(x) = x + x by composing addition with projections, and evaluate d(21)d(21).
    Answer
    d=add⁡∘(π11,π11)d = \operatorname{add}\circ(\pi^1_1, \pi^1_1), d(21)=42d(21) = 42.
  14. 14.Minimisation
    Use the μ\mu operator to compute the integer square root of 30: the least yy with (y+1)2>30(y + 1)^2 > 30.
    Answer
    52=25≤30<36=625^2 = 25 \le 30 < 36 = 6^2: ⌊30⌋=5\lfloor\sqrt{30}\rfloor = 5.
  15. 15.The halting problem
    Is there an algorithm that decides, for every program and input, whether the program halts?
    Answer
    No (Turing). If HH decided halting, the program DD that runs HH on its own code and does the opposite would halt exactly when it does not.
  16. 16.Circuits
    A full adder adds bits a,ba, b and a carry cinc_{in}. What are the sum and carry for 1+1+11 + 1 + 1?
    Answer
    1+1+1=3=1121 + 1 + 1 = 3 = 11_2: sum 1, carry 1.
  17. 17.Ripple-carry adder
    How many gates and what depth does a ripple-carry adder for 4-bit numbers have, built from full adders of 5 gates and depth 3?
    Answer
    Four full adders: about 20 gates; the carry passes through each stage, so the depth grows linearly (roughly 2n+1=92n + 1 = 9 for the carry chain).
  18. 18.Master theorem
    Solve T(n)=2T(n/2)+nT(n) = 2T(n/2) + n and T(n)=8T(n/2)+n2T(n) = 8T(n/2) + n^2 asymptotically.
    Answer
    nlog⁡22=nn^{\log_2 2} = n matches f(n)=nf(n) = n: Θ(nlog⁡n)\Theta(n\log n). nlog⁡28=n3n^{\log_2 8} = n^3 beats n2n^2: Θ(n3)\Theta(n^3).
  19. 19.SAT as a decision problem
    Is (x1∨x2)∧(¬x1∨x3)∧(¬x2∨¬x3)∧(x1∨¬x3)(x_1 \lor x_2) \land (\lnot x_1 \lor x_3) \land (\lnot x_2 \lor \lnot x_3) \land (x_1 \lor \lnot x_3) satisfiable? Give a satisfying assignment.
    Answer
    Try x1=1x_1 = 1: then x3=1x_3 = 1 (clause 2), so x2=0x_2 = 0 (clause 3); clause 1 holds by x1x_1, clause 4 by x1x_1. Satisfiable with x1=1,x2=0,x3=1x_1 = 1, x_2 = 0, x_3 = 1.
  20. 20.Counting accepted words
    How many binary words of length 4 have an even number of 1s?
    Answer
    Half of the 16: (40)+(42)+(44)=1+6+1=8\binom40 + \binom42 + \binom44 = 1 + 6 + 1 = 8.