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.Deterministic automataDesign a DFA over accepting words with an even number of 1s. Does it accept 1011? 1001?AnswerTwo states, even (start, accepting) and odd, swapped by each 1. 1011 has three 1s: rejected. 1001 has two: accepted.
- 2.Minimal DFAHow many states does the minimal DFA for binary words ending in 01 have?AnswerIt 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 ).
- 3.Subset constructionConvert to a DFA and minimise it. How many states? Does it accept and ?AnswerThe minimal DFA tracks the longest suffix that is a prefix of : : 4 states. ends in : yes; : no.
- 4.Equivalent regular expressionsAre and equivalent?AnswerYes: both denote all words over (every letter is an block).
- 5.Product constructionBuild an automaton for words over with an even number of s and an odd number of s. Test and .AnswerPair the two 2-state parity automata: 4 states, accepting (even, odd). : 2 s, 1 : yes. : no.
- 6.From DFA to regular expressionGive a regular expression for binary words with an even number of 1s.Answer, or equivalently .
- 7.Context-free grammarsGive a grammar for . Does it generate ? ? List its words of length at most 6.Answer. : yes; : no. Words: .
- 8.Chomsky normal formConvert to Chomsky normal form.AnswerNew start ; remove : ; terminals , ; split: , , and .
- 9.Pushdown automataRun a PDA for (push on , pop on ) on and .Answer: push, push, pop, pop, the stack is back to its bottom: accept. : one is left: reject.
- 10.Pumping lemmaProve that is not regular.AnswerIf it were, with pumping length , write with , . Then , and is not in the language. Contradiction.
- 11.Turing machinesRun a Turing machine that adds one to a binary number on the input 1011.AnswerMove to the right end, turn trailing 1s into 0s moving left, then turn the first 0 into 1: .
- 12.Primitive recursionUsing only primitive recursive building blocks, compute , and .Answer, , .
- 13.Composition of recursive functionsDefine by composing addition with projections, and evaluate .Answer, .
- 14.MinimisationUse the operator to compute the integer square root of 30: the least with .Answer: .
- 15.The halting problemIs there an algorithm that decides, for every program and input, whether the program halts?AnswerNo (Turing). If decided halting, the program that runs on its own code and does the opposite would halt exactly when it does not.
- 16.CircuitsA full adder adds bits and a carry . What are the sum and carry for ?Answer: sum 1, carry 1.
- 17.Ripple-carry adderHow 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?AnswerFour full adders: about 20 gates; the carry passes through each stage, so the depth grows linearly (roughly for the carry chain).
- 18.Master theoremSolve and asymptotically.Answermatches : . beats : .
- 19.SAT as a decision problemIs satisfiable? Give a satisfying assignment.AnswerTry : then (clause 2), so (clause 3); clause 1 holds by , clause 4 by . Satisfiable with .
- 20.Counting accepted wordsHow many binary words of length 4 have an even number of 1s?AnswerHalf of the 16: .