Theory of Computation | Semester 4 Core Notes
Semester 4 - Page 3: Theory of Computation. 30 numbered topics, highlighted definitions, worked derivations, answered exam questions, three diagrams, comparison tables and three complete Python 3 recognizers. General common-core preparation, not an official syllabus or past-paper prediction. Epsilon denotes the empty string; notation varies across courses.
Topic map
- Alphabet, strings and empty objects
- Language operations and powers
- DFA formal definition
- Worked suffix DFA and traces
- Dead states and extended transition
- NFA definition and acceptance
- Epsilon moves and closure
- Subset construction and equivalence
- Regular expressions and precedence
- Regex, automata and Arden equations
- Closure of regular languages
- DFA minimization and distinguishing suffixes
- Regular pumping lemma and quantifiers
- Myhill-Nerode and nonregularity
- Context-free grammars and derivation
- Parse trees, ambiguity and precedence
- Grammar simplification, CNF and GNF
- PDA and stack recognition
- PDA acceptance and determinism
- CFL closure and decision questions
- CFL pumping and the triple-count language
- Chomsky hierarchy
- Turing machine definition and configurations
- Machine variants and Church-Turing thesis
- Recognizers, deciders and complements
- Universal simulation and enumerators
- Undecidability and the halting contradiction
- Mapping reductions, PCP and Rice's theorem
- Complexity, P and NP
- Proof and revision checklist
1. Alphabet, strings and empty objects
An alphabet is a finite set of symbols; a string is a finite sequence of them. The empty string epsilon has length zero. The empty language contains no strings, while {epsilon} contains one.
Answer: No. Their cardinalities are zero and one respectively.
2. Language operations and powers
A language is a subset of Sigma star. Union collects members of either language; concatenation joins one string from each; Kleene star permits zero or more repetitions and always includes epsilon.
Answer: L plus allows one or more factors. They can differ on epsilon; if epsilon is already in L, both include it.
3. DFA formal definition
A DFA is (Q,Sigma,delta,q0,F), with finite states Q, total transition function delta:Q x Sigma->Q, start q0 and accepting set F. Acceptance is determined after all input is consumed.
Answer: No. Exactly one next state is defined per state and alphabet symbol.
4. Worked suffix DFA and traces
A suffix recognizer stores only enough recent history to decide the language. For strings over {A,B} ending in AB, three states suffice; acceptance in the middle of input is not final acceptance.
Answer: The last A may begin the next desired AB suffix.
start q0 --A--> qA --B--> [qAB accepts] q0: B loops qA: A loops qAB: A -> qA; B -> q0
DFA for strings ending in AB
def ends_ab(text):
transition = {"q0": {"A": "qA", "B": "q0"},
"qA": {"A": "qA", "B": "qAB"},
"qAB": {"A": "qA", "B": "q0"}}
state = "q0"
trace = [state]
for symbol in text:
if symbol not in {"A", "B"}:
raise ValueError("symbol outside alphabet")
state = transition[state][symbol]
trace.append(state)
return state == "qAB", trace
for text in ["", "AB", "BAB", "ABA", "AAB"]:
print(repr(text), ends_ab(text))
try:
ends_ab("ABC")
except ValueError:
print("invalid symbol rejected")
Checked output:
'' (False, ['q0']) 'AB' (True, ['q0', 'qA', 'qAB']) 'BAB' (True, ['q0', 'q0', 'qA', 'qAB']) 'ABA' (False, ['q0', 'qA', 'qAB', 'qA']) 'AAB' (True, ['q0', 'qA', 'qA', 'qAB']) invalid symbol rejected
5. Dead states and extended transition
A dead or sink state loops on every alphabet symbol and cannot reach acceptance. The extended transition delta star processes a whole string, with delta star(q,epsilon)=q.
Answer: Only under an explicitly partial notation; a formal complete DFA includes the sink transitions.
6. NFA definition and acceptance
An NFA transition maps a state and symbol to a set of states. Acceptance means at least one complete run ends in an accepting state, not that all runs accept.
Answer: It dies; other branches can continue.
7. Epsilon moves and closure
An epsilon transition consumes no input. Epsilon-closure(S) contains S and every state reachable from it using only epsilon moves; apply closure initially and after each symbol transition.
Answer: No. They consume nothing and must not advance the input position.
8. Subset construction and equivalence
Subset construction turns each reachable set of NFA states into a DFA state. Start with the epsilon-closure of the NFA start; a subset accepts when it intersects the NFA final set. At most 2^n subsets arise for n states.
Answer: No. Both recognize exactly regular languages; an NFA can be more compact.
NFA subset simulation for strings ending in 01
def accepts(text):
delta = {(0, "0"): {0, 1}, (0, "1"): {0}, (1, "1"): {2}}
current = {0}
for symbol in text:
if symbol not in {"0", "1"}:
raise ValueError("binary alphabet required")
current = {v for u in current for v in delta.get((u, symbol), set())}
return 2 in current
for text in ["", "01", "1101", "1100", "0101"]:
print(repr(text), accepts(text))
Checked output:
'' False '01' True '1101' True '1100' False '0101' True
9. Regular expressions and precedence
Theoretical regular expressions use union, concatenation and star, plus empty-language and empty-string constants. Star binds tighter than concatenation, which binds tighter than union; parentheses remove doubt.
Answer: No. Features such as backreferences can go beyond theoretical regular expressions.
10. Regex, automata and Arden equations
Kleene's theorem equates finite automata and regular expressions. Thompson-style construction combines epsilon-NFA fragments; state elimination combines path expressions. Arden's equation X=AX union B has solution A star B, unique when epsilon is not in A.
Answer: It ensures uniqueness in the standard left-concatenation form of Arden's lemma.
11. Closure of regular languages
Regular languages are closed under union, intersection, complement, difference, concatenation, star and reversal. Complementing a DFA requires a fixed alphabet and complete transitions.
Answer: NFA acceptance is existential over runs; flipping finals does not negate that existential condition.
12. DFA minimization and distinguishing suffixes
Remove unreachable states, partition final versus nonfinal states, then refine until transitions lead to matching equivalence classes. Equivalent states accept exactly the same continuation strings.
Answer: Not without checking all future continuation behavior.
13. Regular pumping lemma and quantifiers
If L is regular, some p makes every w in L with length at least p splittable as xyz, with length(xy)<=p, length(y)>0 and xy^i z in L for all i>=0. For nonregularity, defeat every allowed split of your chosen witness.
Answer: No. The split is chosen adversarially; your argument must cover all allowed splits.
14. Myhill-Nerode and nonregularity
Two prefixes are distinguishable if some suffix makes exactly one resulting string a member. A language is regular exactly when it has finitely many equivalence classes under indistinguishability.
Answer: It is a necessary condition, not a general sufficient test; explicit construction or equivalence tools are stronger.
15. Context-free grammars and derivation
A CFG has variables, terminals, productions and a start variable. Each production replaces one variable; a derivation ends in a terminal string. S->aSb or epsilon generates exactly a^n b^n for n>=0.
Answer: No. It defines generated strings; parsing algorithms choose how to recover structure.
16. Parse trees, ambiguity and precedence
A grammar is ambiguous when at least one string has two distinct parse trees, equivalently two distinct leftmost derivations. A language is inherently ambiguous only if every CFG for it is ambiguous.
Answer: No. A different grammar may be unambiguous.
17. Grammar simplification, CNF and GNF
Simplification removes useless symbols, unit productions and nullable productions with care to preserve epsilon when needed. CNF uses A->BC or A->a, with a controlled start-to-epsilon exception; GNF uses a leading terminal followed by variables.
Answer: No. Alternative productions must account for omitting nullable occurrences, and start-language membership must be preserved.
18. PDA and stack recognition
A pushdown automaton adds a stack to finite control. A nondeterministic PDA recognizes exactly the context-free languages. Push a marker for each a, then pop for each b, and reject wrong order or mismatched counts.
Answer: Unbounded matching counts require arbitrarily many distinguishable histories.
input: a a b b stack: [] -> [a] -> [a,a] -> [a] -> [] phase: push a symbols, then pop b symbols
Stack recognition of a^n b^n
def equal_blocks(text):
stack = []
in_b_phase = False
for symbol in text:
if symbol == "a" and not in_b_phase:
stack.append(symbol)
elif symbol == "b":
in_b_phase = True
if not stack:
return False
stack.pop()
else:
return False
return not stack
for text in ["", "ab", "aabb", "aaabbb", "aab", "abab", "ba", "ac"]:
print(repr(text), equal_blocks(text))
Checked output:
'' True 'ab' True 'aabb' True 'aaabbb' True 'aab' False 'abab' False 'ba' False 'ac' False
19. PDA acceptance and determinism
For nondeterministic PDAs, acceptance by final state and acceptance by empty stack define the same CFL class after conversion. Always specify that the entire input must be consumed. Deterministic PDAs recognize a proper subclass of CFLs.
Answer: No. This differs from the DFA/NFA equivalence.
20. CFL closure and decision questions
CFLs are closed under union, concatenation and star, and intersection with a regular language. They are not closed under arbitrary intersection or complement. CFG membership and emptiness are decidable; general CFG equivalence is undecidable.
Answer: No. Asking about one string differs from comparing all strings in two languages.
21. CFL pumping and the triple-count language
The CFL pumping lemma splits w=uvxyz, with length(vxy)<=p, length(vy)>0, and uv^i xy^i z in L for every i>=0. Both v and y pump together. To refute a CFL, cover all valid splits.
Answer: A grammar branch can grow two coordinated sides, unlike the single regular-language pump.
22. Chomsky hierarchy
Regular languages fit finite automata; context-free languages fit nondeterministic PDAs; context-sensitive languages fit linear-bounded automata; recursively enumerable languages fit Turing recognizers. These language classes form strict inclusions.
Answer: No. Decidability is a different boundary; linear-space restrictions can exclude some decidable languages.
Regular
strictly inside Context-free
strictly inside Context-sensitive
strictly inside Turing-recognizable23. Turing machine definition and configurations
A Turing machine has finite control, a tape alphabet including blank, an unbounded tape model and a head that reads, writes and moves. A configuration records state, tape content and head position.
Answer: No. It is a mathematical model with no fixed finite bound on available cells.
24. Machine variants and Church-Turing thesis
Multitape and nondeterministic Turing machines have the same computability power as the standard model, though simulation costs can differ. The Church-Turing thesis relates effective computation to Turing computability, not a theorem about all imaginable physics.
Answer: No. A simulation may incur additional time or space.
25. Recognizers, deciders and complements
A decider halts with the correct answer on every input. A recognizer accepts members, but may reject or loop on nonmembers. A language is decidable iff both it and its complement are recognizable.
Answer: The first may never stop; dovetailing prevents that starvation.
26. Universal simulation and enumerators
A universal Turing machine simulates a supplied encoded machine on supplied input. An enumerator prints language members, possibly with repetition and no order guarantee. Enumerability and recognizability are equivalent.
Answer: No. The enumeration can be arbitrarily delayed.
27. Undecidability and the halting contradiction
The halting problem has no decider for all program-input pairs. Assume a decider H; construct D that loops when H predicts D's input-machine halts on itself and halts otherwise; running D on its own code contradicts H.
Answer: Yes. Simulate the machine and accept if it halts; nonhalting runs can loop forever.
28. Mapping reductions, PCP and Rice's theorem
A computable mapping reduction A<=m B transforms membership in A into membership in B. To prove B undecidable, reduce a known undecidable A to it. PCP asks for a nonempty tile-index sequence with equal top/bottom concatenations; it is undecidable in general.
Answer: No. That is a syntactic property, outside the theorem's semantic-language scope.
29. Complexity, P and NP
Computability asks whether an algorithm exists; complexity asks its resource use. P contains polynomial-time decision problems; NP has polynomial-time verifiable yes-certificates. P subset NP; equality is unresolved.
Answer: No. It means nondeterministic polynomial time, equivalently certificate verification.
30. Proof and revision checklist
Choose the language class, define the machine or grammar, trace examples and prove the claim. For impossibility arguments, state the quantifiers or reduction direction. For deciders, explicitly establish halting on every input.
Answer: Using examples as a universal proof, choosing only one pumping split, or reducing in the wrong direction.
Machine and language comparison
| Model | Memory | Language class / limit |
|---|---|---|
| DFA / NFA | Finite control | Regular; NFA is not more powerful |
| NPDA | Finite control plus stack | Context-free |
| DPDA | Finite control plus deterministic stack | Proper subset of context-free |
| LBA | Tape bounded linearly in input length | Context-sensitive |
| Turing recognizer | Unbounded tape model | May loop on nonmembers |
| Turing decider | Unbounded tape model | Always halts with the right answer |
Closure and decision reference
| Class / question | Yes | No / caution |
|---|---|---|
| Regular closure | Union,intersection,complement,concat,star | Complete DFA and fixed alphabet for complement |
| CFL closure | Union,concat,star,intersection with regular | Not general intersection or complement |
| DFA membership / equivalence | Decidable | An NFA may expand exponentially when determinized |
| CFG membership / emptiness | Decidable | General CFG equivalence undecidable |
| Turing language membership | Recognizable in general | Not decidable in general |
| P versus NP | P is a subset of NP | Equality remains unresolved |
Proof mistakes to avoid
- Do not confuse epsilon, the empty language, and {epsilon}.
- A final state visited before the input ends does not guarantee acceptance.
- For nonregularity or non-context-freeness, cover every permitted pumping split.
- A DFA can be complemented by flipping finals only after completing transitions.
- Do not claim a recognizer rejects merely because it has not yet accepted.
- A reduction into a known undecidable problem does not by itself prove your problem undecidable; reduce from the known hard problem.
- State whether a theorem concerns syntax, language semantics, decidability or complexity.
Practice resources and sources
The following references support the definitions and proof methods. Page examples, code and diagrams are original teaching material.
Comments
Post a Comment