Professional Documents
Culture Documents
6-Chomsky Hierarchy, DFA-11-01-2024
6-Chomsky Hierarchy, DFA-11-01-2024
Theory of Computation
Lecture 5
Dr. Saritha Murali
(SCOPE, VIT Vellore)
11-01-2024
Recap
• Grammars
• Derivations
• Sentential Forms
• Language generated from a grammar
Types of grammars
Chomsky Hierarchy
Grammars based on the type of production rules:
Language Grammar Machine Example
Regular grammars
Finite-state
Type 3 Regular languages • Right-linear grammars a*
automata
• Left-linear grammars
Push-down
Type 2 Context-free languages Context-free grammars anbn
automata
Linear-bound
Type 1 Context-sensitive languages Context-sensitive grammars an bn cn
automata
Read as: unrestricted grammars can generate the languages that can be accepted by a Turing machine.
Chomsky Hierarchy
Non-recursively enumerable
Recursively-enumerable
Recursive
Context-sensitive
Context-free
Regular
Type – 0 Unrestricted or Phrase structured
grammar
Productions of the form 𝜶 → 𝜷
𝜶 ∈ (𝑽 + 𝑻)* 𝑽 (𝑽 + 𝑻)*
𝜷 ∈ (𝑽 + 𝑻)∗
• The productions have no restrictions.
• 𝜶 is a string of terminals and non-terminals with at least one non-terminal
and 𝜶 cannot be null.
• 𝜷 is a string of terminals and non-terminals.
Type – 0 Unrestricted or Phrase structured
grammar
• Type-0 grammars include all formal grammars.
• Type-0 grammar languages are recognized by Turing machine.
• The languages generated are recursive or recursively enumerable
languages.
e.g.,
S → Aa
SBb→ abc
a → Acb (not type-0 as there is no variable/Non-Terminal on LHS)
aB → BabcS
Type – 1 Context-sensitive grammar
Productions of the form 𝜶 → 𝜷
|𝜶| ≤ |𝜷|
𝜶 ∈ (𝑽 + 𝑻)* 𝑽 (𝑽 + 𝑻)*
𝜷 ∈ (𝑽 + 𝑻)∗
e.g.,
AB → CDB
AB → CdEB
ABcd → abCDBcd
A → bcA
B→b
Type – 1 Context-sensitive grammar
• Type 1 grammar should be Type 0
• Type 1 grammars generate context-sensitive languages
• The language generated by the grammar are recognized by the Linear
Bound Automata.
Type – 2 Context-free grammar
Productions of the form 𝜶 → 𝜷
|𝜶| ≤ |𝜷|
𝜶 ∈ 𝑽 and |𝜶| = 𝟏
𝜷 ∈ (𝑽 + 𝑻)∗
5. Construct a grammar that accepts all strings from the language L={w|w ¹ wR and
Σ={a,b}} . i.e., Construct grammar for non-palindromes over {a, b}
6. Construct a grammar that accepts all strings from the following languages
• L = {w | na(w) = nb(w)} i.e., no. of a is equal to no. of b
• L = {w | na(w)>nb(w)}
• L = {w | na(w) = 2nb(w)}
Finite State Automata (FA)
Design the logic behind an electric bulb.
• States = {0, 1, 2, 3}
• Input = {↷, ↶}
• Finite Automaton.
Design the logic behind automatic doors
Finite
Control
n(Q) = 2 , n(Σ) = 2
d:Q´Σ→Q
Examples
M = ( {q0 , q1 , q2 , D } , {a, b} , q0 , d , {q2} ) a b
q1 D
where d(q0 , a) = q1 d(q0 , b) = D q0
q1 q2
d(q1 , a) = q1 d(q1 , b) = q2 q1
D q2
d(q2 , a) = D d(q2 , b) = q2 q2
d(D , a) = D d(D , b) = D D D D
a
Transition Table or State Table
q0 a b b
q1 q2
Transition diagram or State diagram
b a
D
a,b
DFA
• In a DFA, for a particular input symbol from an input state, the
machine goes to ONE state only.
• A transition function is defined on every state for every input symbol.
• Also in DFA, null move is not allowed, i.e., DFA cannot change state
without any input character.
• A DFA has exactly one transition from every state on every symbol in the
alphabet.
• Does not have exactly one transition from every state on every symbol:
• Two transitions from q0 on a
• No transition from q1 (on either a or b)
• Hence not a DFA