Unit 3 of 4 · M.Sc IT Sem 4

Unit 3: Pushdown automata and Turing machines

Theory of Computation notes · PTU syllabus (PGCA1927)

3 min read8 topics10 exam questions
On this page
  1. Unit summary
  2. Ambiguity and parse trees
  3. Pushdown automata
  4. Equivalence of PDAs and CFGs; non-deterministic PDAs
  5. Standard Turing machines
  6. Turing machine construction for simple problems
  7. Variations of Turing machines
  8. The universal Turing machine and the Church–Turing thesis
  9. Recursive, recursively enumerable and context-sensitive languages
  10. Key terms
  11. Quick revision
  12. Important questions

Unit summary

Adding memory to automata increases their power, from pushdown automata to Turing machines. This unit covers ambiguity and parse trees, pushdown automata and their equivalence with CFGs, non-deterministic PDAs, standard Turing machines and variations, universal Turing machines, the Church–Turing thesis, recursive and recursively enumerable languages, context-sensitive languages, the Chomsky hierarchy and constructing Turing machines.

After this unit you can

  • Identify ambiguous grammars
  • Design pushdown automata and relate them to CFGs
  • Design Turing machines and explain their variations and the universal machine
  • Distinguish recursive, recursively enumerable and context-sensitive languages

PTU syllabus topics

  • Ambiguity
  • parse trees
  • equivalence of PDAs
  • non-deterministic PDA
  • standard Turing machines and variations
  • universal Turing machines
  • Church-Turing thesis
  • recursive and recursively enumerable languages
  • context-sensitive languages
  • Chomsky hierarchy
  • TM construction for simple problems
ComparisonCNF vs GNF
Chomsky Normal Form
Greibach Normal Form

Rule shapes

A → BC or A → a

A → a followed by variables

Use

CYK parsing algorithm

Top-down parsing, PDA construction

Derivation length

2n − 1 steps for a string of length n

n steps

1

Topic 1

Ambiguity and parse trees

  • A grammar is ambiguous if some string has two different parse trees (or two leftmost derivations).

Example

E → E + E, E × E or id: "id + id × id" has two parse trees — one grouping (id + id) × id. Rewriting with precedence (E → E + T, T → T × F) removes the ambiguity.

  • Some CFLs are inherently ambiguous — every grammar for them is ambiguous, e.g., {aⁱbʲcᵏ : i = j or j = k}.
2

Topic 2

Pushdown automata

  • A PDA is a finite automaton with a stack: a 7-tuple (Q, Σ, Γ, δ, q0, Z0, F). Each move reads an input symbol (or ε), pops the top stack symbol and pushes a string.

Example

PDA for {aⁿbⁿ}: on each a push A; on each b pop A; accept when the input ends and only Z0 remains. For aabb: push, push, pop, pop → accept.

  • Acceptance by final state or by empty stack — equivalent in power.
3

Topic 3

Equivalence of PDAs and CFGs; non-deterministic PDAs

  • For every CFG there is a PDA accepting its language, and every PDA's language is context-free — PDAs recognise exactly the CFLs.
ComparisonDPDA and NPDA
Deterministic PDA
Non-deterministic PDA

Moves

At most one choice in each situation

Several possible moves

Power

Deterministic CFLs only

All CFLs

Example

{wcwᴿ} (marked palindromes)

{wwᴿ} (even palindromes) needs guessing the middle

Use

Parsers of programming languages (LR parsing)

Theory

  • Unlike finite automata, non-deterministic PDAs are more powerful than deterministic ones.
4

Topic 4

Standard Turing machines

  • A Turing machine has a finite control, an infinite tape and a read–write head that moves left or right: 7-tuple (Q, Σ, Γ, δ, q0, B, F), with δ(q, X) = (p, Y, L or R).
ProcessTM for {0ⁿ1ⁿ}
  1. 1Replace the leftmost 0 by X
  2. 2Move right to the leftmost 1 and replace it by Y
  3. 3Move left back to the leftmost remaining 0
  4. 4Repeat
  5. 5If no 0s remain and no 1s remain beyond the Ys, accept; otherwise reject
5

Topic 5

Turing machine construction for simple problems

Example

Unary addition 111 0 11 → 11111: move right to the 0, change it to 1, move to the end, change the last 1 to blank, halt. The machine computes 3 + 2 = 5.

  • Other exercises: binary increment, copying a string, checking palindromes, computing n mod 2.
6

Topic 6

Variations of Turing machines

Key termsTM variants
Multi-tape TM
Several tapes and heads — same power, faster (polynomially)
Non-deterministic TM
Several possible moves — same power
Multi-head and two-way infinite tape
Same power
Enumerators
Print strings of a language — same as recognisers
Linear bounded automaton
Tape limited to the input length — accepts context-sensitive languages
  • All reasonable variants recognise the same class of languages, supporting the robustness of the model.
7

Topic 7

The universal Turing machine and the Church–Turing thesis

  • A universal Turing machine U takes the encoding of any TM M and an input w and simulates M on w — the theoretical model of a stored-program computer.
  • Church–Turing thesis: every function that is effectively computable by an algorithm can be computed by a Turing machine. It is a thesis, not a theorem, supported by the equivalence of many models (lambda calculus, recursive functions, register machines).
8

Topic 8

Recursive, recursively enumerable and context-sensitive languages

ComparisonLanguage classes
Recognised by
Behaviour

Recursive (decidable)

TM that always halts

Answers yes or no for every input

Recursively enumerable (semi-decidable)

TM that halts on members

May loop forever on non-members

Context-sensitive

Linear bounded automata

Decidable; e.g., {aⁿbⁿcⁿ}

  • Recursive languages are closed under complement; if both L and its complement are r.e., L is recursive.
HierarchyChomsky hierarchy with machines
  1. Regular

    Finite automata

  2. Context-free

    Pushdown automata

  3. Context-sensitive

    Linear bounded automata

  4. Recursively enumerable

    Turing machines

Key terms

Ambiguous grammar
Grammar giving two parse trees for some string
Pushdown automaton
Finite automaton with a stack
Turing machine
Finite control with an infinite read–write tape
Universal Turing machine
TM simulating any other TM from its description
Recursively enumerable language
Language accepted by some TM

Quick revision

  • Ambiguity; removing it with precedence; inherent ambiguity.
  • PDA 7-tuple; acceptance by final state or empty stack; PDA ⇔ CFG; DPDA weaker than NPDA.
  • TM 7-tuple; constructing TMs; variants equal in power; LBAs.
  • Universal TM; Church–Turing thesis.
  • Recursive vs r.e.; context-sensitive; full Chomsky hierarchy.

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.When is a grammar ambiguous?
  2. Q2.Design the idea of a PDA for {aⁿbⁿ}.
  3. Q3.Are DPDAs as powerful as NPDAs?
  4. Q4.Define a Turing machine.
  5. Q5.State the Church–Turing thesis.
  6. Q6.Distinguish recursive and recursively enumerable languages.

Long-answer questions

  1. Q1.Explain ambiguity with an example and how to remove it.
  2. Q2.Design a PDA for a given language and explain PDA–CFG equivalence.
  3. Q3.Design a Turing machine for {0ⁿ1ⁿ} and explain TM variations.
  4. Q4.Explain the universal TM, Church–Turing thesis and the Chomsky hierarchy.

Stuck on this unit?

Message SBS on WhatsApp for help with Theory of Computation, or to ask about studying M.Sc IT at Synetic.

WhatsApp us