Theory of Computation - Complete Tutorial Guide
This tutorial provides comprehensive practice problems, exam-style questions, and review materials covering all three units of Theory of Computation.
Unit 1: Regular Languages & Finite Automata
Tutorial 1.1: Finite Automata Design
Q1: Design DFA accepting strings with even number of 0’s and odd number of 1’s.
Solution:
States: {q₀₀, q₀₁, q₁₀, q₁₁}
q₀₀ = even 0's, even 1's (start)
q₀₁ = even 0's, odd 1's (accept)
q₁₀ = odd 0's, even 1's
q₁₁ = odd 0's, odd 1's
Transitions:
δ(q₀₀, 0) = q₁₀
δ(q₀₀, 1) = q₀₁
δ(q₀₁, 0) = q₁₁
δ(q₀₁, 1) = q₀₀
δ(q₁₀, 0) = q₀₀
δ(q₁₀, 1) = q₁₁
δ(q₁₁, 0) = q₀₁
δ(q₁₁, 1) = q₁₀
Q2: Design NFA accepting strings ending with “01”.
Solution:
States: {q₀, q₁, q₂}
Start: q₀
Accept: {q₂}
δ(q₀, 0) = {q₀, q₁}
δ(q₀, 1) = {q₀}
δ(q₁, 1) = {q₂}
Q3: Convert NFA to DFA for language {w | w contains “ab”}.
Solution: Use subset construction, create states for all possible NFA state combinations.
Tutorial 1.2: Regular Expressions
Q1: Write regular expression for strings with at least two a’s.
Answer: babab*
Q2: Convert (a|b)*abb to ε-NFA.
Solution: Use Thompson’s construction.
Q3: Are these equivalent? (a|b)* and a*b*
Answer: No! First accepts “ab”, second doesn’t.
Tutorial 1.3: Pumping Lemma
Q1: Prove {0ⁿ1ⁿ | n ≥ 0} not regular.
Proof:
- Assume regular, let p be pumping length
- Choose w = 0ᵖ1ᵖ, |w| = 2p ≥ p
- By pumping lemma, w = xyz where |xy| ≤ p, |y| ≥ 1
- So xy consists only of 0’s
- Pump: xy²z = 0ᵖ⁺|y|1ᵖ
- Different number of 0’s and 1’s - not in language!
- Contradiction, so not regular.
Q2: Prove {ww | w ∈ {a,b}*} not regular.
Proof: Use pumping lemma with w = aᵖbaᵖb.
Q3: Is {aⁱbʲ | i ≥ j} regular?
Answer: No! Use pumping lemma.
Unit 2: Context-Free Languages & Pushdown Automata
Tutorial 2.1: Context-Free Grammars
Q1: Design CFG for {aⁿbⁿ | n ≥ 0}.
Solution:
S → aSb | ε
Q2: Design CFG for balanced parentheses.
Solution:
S → SS | (S) | ε
Q3: Show derivation for “aabb” in {aⁿbⁿ} grammar.
Solution:
S ⇒ aSb ⇒ aaSbb ⇒ aabb
Tutorial 2.2: Chomsky Normal Form
Q1: Convert to CNF:
S → ASB | ε
A → aAS | a
B → SbS | A | bb
Solution:
- Add S₀ → S (new start)
- Remove ε-productions
- Remove unit productions
- Convert to A → BC or A → a form
Q2: Use CYK to parse “aabb” with CNF grammar.
Solution: Build parse table bottom-up.
Tutorial 2.3: Pushdown Automata
Q1: Design PDA for {aⁿbⁿ | n ≥ 0}.
Solution:
1. Push a's onto stack
2. Pop for each b
3. Accept if stack empty
δ(q₀, a, Z₀) = (q₀, AZ₀)
δ(q₀, a, A) = (q₀, AA)
δ(q₀, b, A) = (q₁, ε)
δ(q₁, b, A) = (q₁, ε)
δ(q₁, ε, Z₀) = (qaccept, Z₀)
Q2: Design PDA for {wcwᴿ | w ∈ {a,b}*}.
Solution: Push w, see c, pop and compare.
Q3: Convert CFG S → aSb | ε to PDA.
Solution: Use standard conversion (single state, simulate leftmost derivation).
Tutorial 2.4: Pumping Lemma for CFLs
Q1: Prove {aⁿbⁿcⁿ | n ≥ 0} not context-free.
Proof:
- Assume CFL, let p be pumping length
- Choose w = aᵖbᵖcᵖ
- w = uvxyz where |vxy| ≤ p, |vy| ≥ 1
- vxy contains at most 2 symbol types
- Pumping changes at most 2 counts, third unchanged
- Violates equality - contradiction!
Q2: Prove {ww | w ∈ {a,b}*} not context-free.
Proof: Choose w = aᵖbaᵖb, pumping destroys ww pattern.
Q3: Is {aⁿb²ⁿ | n ≥ 0} context-free?
Answer: Yes! Grammar: S → aSbb | ε
Unit 3: Turing Machines & Complexity
Tutorial 3.1: Turing Machine Design
Q1: Design TM for {0ⁿ1ⁿ | n ≥ 0}.
Solution:
1. Mark leftmost 0 with X
2. Scan right to first 1, mark with Y
3. Return to start
4. Repeat until all matched
5. Accept if all marked correctly
Q2: Design TM for {aⁿbⁿcⁿ | n ≥ 0}.
Solution: Mark one of each (a,b,c) repeatedly until all matched.
Q3: Trace execution of {0ⁿ1ⁿ} TM on input “0011”.
Solution: Show step-by-step configuration changes.
Tutorial 3.2: Decidability
Q1: Is {⟨M⟩ | M accepts at least one string} decidable?
Answer: No! Undecidable by Rice’s theorem (non-trivial property).
Q2: Is {⟨M⟩ | M has 5 states} decidable?
Answer: Yes! Syntactic property, can check encoding.
Q3: Prove acceptance problem A_TM undecidable.
Solution: Reduce from HALT or use diagonalization.
Tutorial 3.3: Complexity Theory
Q1: Show sorting is in P.
Solution: Merge sort runs in O(n log n) = polynomial.
Q2: Show SAT is in NP.
Solution:
- Certificate: Variable assignment
- Verifier: Plug values, evaluate (polynomial time)
Q3: What is time complexity of:
for i = 1 to n:
for j = 1 to i:
for k = 1 to j:
do O(1) work
Answer: O(n³)
Comprehensive Practice Problems
Problem Set 1: Automata
- Design DFA for strings with substring “101”
- Convert NFA with ε-transitions to DFA
- Minimize given DFA using equivalence classes
- Prove language not regular using pumping lemma
- Write regular expression for “all strings except those containing aa”
Problem Set 2: Grammars
- Design CFG for palindromes over {a,b}
- Show grammar is ambiguous with example
- Convert CFG to Chomsky Normal Form
- Convert CFG to Greibach Normal Form
- Remove left recursion from grammar
Problem Set 3: PDAs
- Design PDA accepting by empty stack for {aⁿbⁿ}
- Convert PDA to CFG
- Prove language requires PDA (not regular)
- Design PDA for {aⁱbʲcᵏ | i = j or j = k}
- Compare DPDA vs NPDA with examples
Problem Set 4: Turing Machines
- Design TM for {ww | w ∈ {a,b}*}
- Design TM for prime numbers {aᵖ | p prime}
- Show multi-tape TM more efficient than single-tape
- Design Universal TM (conceptual)
- Prove variant of TM equivalent to standard
Problem Set 5: Decidability
- Prove halting problem undecidable
- Show problem undecidable using reduction
- Apply Rice’s theorem to prove undecidability
- Distinguish decidable from recognizable
- Prove language not even recognizable
Problem Set 6: Complexity
- Analyze time complexity of algorithms
- Show problem is in P with algorithm
- Prove problem is NP-complete
- Design polynomial-time reduction
- Compare space vs time complexity
Exam-Style Questions
Short Answer Questions (5 marks each)
- Define DFA formally and give example
- State and explain pumping lemma for regular languages
- What is difference between PDA and DPDA?
- Define Turing Machine with all components
- Explain Church-Turing thesis
- What is halting problem? Why undecidable?
- Define P and NP complexity classes
- What are NP-complete problems?
Long Answer Questions (10 marks each)
- Design DFA for given language and prove correctness
- Convert CFG to CNF showing all steps
- Design PDA and show acceptance trace
- Design TM and trace execution on example input
- Prove language not regular using pumping lemma
- Prove halting problem undecidable (complete proof)
- Prove problem is NP-complete using reduction
- Compare complexity classes P, NP, PSPACE
Important Theorems to Remember
Unit 1
- NFA = DFA in power
- Regular expressions = FA
- Pumping lemma for regular languages
- Myhill-Nerode theorem
- Closure properties of regular languages
Unit 2
- PDA = CFG in power
- Pumping lemma for CFLs
- CFLs closed under union, concat, star
- CFLs NOT closed under intersection, complement
- CYK parsing algorithm O(n³)
Unit 3
- Church-Turing thesis
- Halting problem undecidable
- Rice’s theorem
- Every NTM has equivalent DTM
- Multi-tape = single-tape (simulation)
- Savitch’s theorem: NSPACE(f) ⊆ DSPACE(f²)
- Time hierarchy theorem
- Space hierarchy theorem
- Cook-Levin theorem (SAT NP-complete)
Quick Reference
Language Hierarchy
Regular Languages
⊂
Context-Free Languages
⊂
Context-Sensitive Languages (DSPACE(n))
⊂
Recursive (Decidable) Languages
⊂
Recursively Enumerable Languages
⊂
All Languages
Complexity Hierarchy
L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE ⊆ EXPTIME
Known:
- P ⊊ EXPTIME (strict)
- L ⊊ PSPACE (strict)
Unknown:
- P vs NP
- NP vs PSPACE
- L vs NL
Closure Properties
| Operation | Regular | CFL | Recursive | RE |
|---|---|---|---|---|
| Union | ✓ | ✓ | ✓ | ✓ |
| Intersection | ✓ | ✗ | ✓ | ✓ |
| Complement | ✓ | ✗ | ✓ | ✗ |
| Concatenation | ✓ | ✓ | ✓ | ✓ |
| Kleene star | ✓ | ✓ | ✓ | ✓ |
Decision Problems
| Problem | Regular | CFL | Recursive |
|---|---|---|---|
| Membership | ✓ | ✓ | ✗ |
| Emptiness | ✓ | ✓ | ✗ |
| Equivalence | ✓ | ✗ | ✗ |
| Universality | ✓ | ✗ | ✗ |
Exam Tips
Unit 1 Tips
- Practice drawing state diagrams
- Master subset construction (NFA → DFA)
- Memorize pumping lemma proof structure
- Know closure properties with proofs
- Practice regular expression conversions
Unit 2 Tips
- Understand derivation types (leftmost, rightmost)
- Master CNF conversion steps
- Practice PDA design with stack operations
- Know when to use pumping lemma for CFLs
- Understand why some languages not CFL
Unit 3 Tips
- Practice TM design with detailed traces
- Master reduction technique for undecidability
- Know Rice’s theorem applications
- Understand complexity class relationships
- Practice NP-completeness proofs
General Tips
- Draw diagrams whenever possible
- Show all steps in conversions
- Provide examples and counterexamples
- State theorems before using them
- Check your proofs for completeness
Common Mistakes to Avoid
- ✗ Confusing DFA and NFA requirements
- ✗ Forgetting ε-transitions in NFA
- ✗ Wrong pumping lemma string choice
- ✗ Confusing decidable and recognizable
- ✗ Thinking NP means “not polynomial”
- ✗ Forgetting to show NP membership in NP-complete proofs
- ✗ Confusing time and space complexity
- ✗ Applying Rice’s theorem to syntactic properties
Study Checklist
Before Exam
- Review all definitions
- Memorize key theorems
- Practice automata design
- Master pumping lemma proofs
- Understand TM construction
- Know undecidability proofs
- Understand complexity classes
- Practice reductions
- Review closure properties
- Solve practice problems
Summary
This tutorial covered:
- Unit 1: Finite automata, regular languages, pumping lemma
- Unit 2: Context-free grammars, PDAs, CFL pumping lemma
- Unit 3: Turing machines, decidability, complexity theory
- Practice: Comprehensive problem sets
- Exam prep: Tips, common mistakes, quick reference
Key to success: Practice, practice, practice!
Good luck with your Theory of Computation exam! 🎓