2. Chomsky Hierarchy
2
▪ Chomsky hierarchy represents the class of languages that
are accepted by the different machine.
▪ The category of language in Chomsky’s Hierarchy is given
below:
1) Type 0 – Unrestricted Grammar
2) Type 1 – Context Sensitive Grammar
3) Type 2 – Context Free Grammar
4) Type 3 – Regular Grammar
▪ Two major models of automata:
• Generators
– with output and without input
– tell us how to generate all strings in a Language L
• Acceptors
– with input and without output
– tell us if a specific string is in Language L
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
3. Schematic of a Finite Automaton
3
Finite control
a ba a c input
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Finite Automaton
▸ The control represents the states and transition function.
▸ The tape contains the input string.
▸ The arrow represents the input head, pointing at the next input symbol to be read.
FA can remember a finite amount of information
4. Schematic of a Pushdown Automaton
4
z
Finite control
b cc a a
x
y
stack
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Based on the characteristics of CFG containing recursive rules,
how can we apply a finite state machine to CFG?
▸ The idea to reach the goal is to add a memory device to a
FSM.
Push Down Automaton
▸ Input string
▹ Same as FSM
▹ Cannot back up
▸ Stack operations on each transition
▹ READ + POP or, IGNORE
▹ PUSH or, IGNORE
PDA can remember an infinite amount of information
5. PDA >> Informal Description & Non-determinism
5
▸ A Pushdown Automata (PDA) can write an unbounded number of Stack Symbols on the stack and read these symbols
later.
▸ Writing a symbol onto the stack is called pushing and it pushes all symbols on the stack one stack cell down.
▸ Removing a symbol off the stack is called popping and every symbol on the stack moves one stack cell up.
Note: A PDA can access only the stack’s topmost symbol (LIFO).
▸ A Nondeterministic PDA allows nondeterministic transitions.
▸ Nondeterministic PDA-s are strictly stronger than deterministic PDA-s.
- In this respect, the situation is not similar to the situation of DFA-s and NFA-s.
- Nondeterministic PDA- are equivalent in power to CFG-s.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
6. PDA >> Formal Definition
6
A pushdown automaton is a 6-tuple (Q, 𝛴, 𝛤, 𝛿, q0 , F) where:
▸ Q is a finite set called the states
▸ 𝛴 is the input alphabet
▸ 𝛤 is the stack alphabet
▸ 𝛿: Q X 𝛴 𝜀 X 𝛤 𝜀 → P(Q, 𝛤 𝜀) is the transition function
▸ q0 𝜖 Q is the start state and
▸ F ⊆ Q is the set of accepting states.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
7. PDA >> Practices 1
7
Create a PDA that recognizes the context free language: L = { 0n 1n | n >=0 }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
8. PDA >> Practices 1 - Formal Definition
8
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
9. PDA >> Practices 2 – How PDA works!!!
9
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Example: PDA that recognizes all the balanced parenthesis strings only.
10. PDA >> Practices 2 – How PDA works!!!
10
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Instantaneous Description for the string “( ( ) ) ( ) )”
11. PDA >> Practice 3
11
Create a PDA that recognizes the following context free language:
L = { w ϵ {0, 1}* | w contains at least three 1’s }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
12. PDA >> Practice 4
12
Create a PDA that recognizes the following context free language:
L = { w ϵ {0, 1}* | w = wR and the length of w is odd}
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
13. PDA >> Practice 5
13
Create a PDA that recognizes the following context free language:
L = { w ϵ {0, 1}* | w = wR }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
14. PDA >> Practices 6
14
Create a PDA that recognizes the following context free language:
L = { ai bj ck | i, j, k >=0 and i=j }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
15. PDA >> Practices 7
15
Create a PDA that recognizes the following context free language:
L = { ai bj ck | i, j, k >=0 and j=k }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
16. PDA >> Practice 8
16
Create a PDA that recognizes the following context free language:
L = { ai bj ck | i, j, k >=0 and i=j or j=k }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
17. PDA >> Practice 9
17
Create a PDA that recognizes the following context free language:
L = { ai bj ck | i, j, k >=0 and i+j = k }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
18. PDA >> Practice 10
18
Create a PDA that recognizes the following context free language:
L = { a2n b3n | n>=0 }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
19. PDA >> Practice set 1
19
Design a Push-Down Automaton for each one of the following languages:
1. L = { an bn | n >= 0 }
2. L = {an b2n | n >= 0 }
3. L = { a2n bn | n >= 0 }
4. L = { an+1 bn | n > 0 }
5. L = { a2n+1 bn | n > 0 }
6. L = { an+m bm+t at bn | n,t >0 and m>=0 }
7. L = { an+m bm+t at bn | n, t, m > 0 }
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
20. PDA >> Practices 11
20
Create a PDA that recognizes the following context free language:
L = { wwR | w ϵ { 0, 1 }* }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
21. PDA >> Practices 12
21
Create a PDA that recognizes the following context free language:
L = { a* w ck | w ϵ {a, b}* and k = |w|a (k=number of a’s in w) }
Solution:
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
22. PDA >> Practices 13
22
Consider the following PDA:
▸ Now show that the PDA accepts the word ‘aaadbabacc’
▸ Describe the language
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
23. PDA >> Practices 14
23
▸ Design a Push Down Automata(PDA) for the given language –
L = { ai bj ck dm | i + j = k and I, j, k, m > 0 }
a) Now write the components of your designed PDA.
b) Write Instantaneous Description(ID) for the string ‘aaabccccd’ for this PDA.
▸ Consider the following language –
L = { am bi cm dk | m, I, k >=1 }
a) Design a pushdown automaton(PDA)
b) Write the seven components to represent the above PDA.
c) Show instantaneous descriptions for the above PDA when the input is ‘aabccdd’ .
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
24. PDA >> Practices 15
24
▸ Consider the following language –
L = { 12m 05m 2n | m, n >= 1 }
a) Design a pushdown automaton (PDA) for the given language.
b) Write all seven components to represent the above PDA.
c) Show the instantaneous descriptions for the above PDA when the input is ‘11000002’
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
25. PDA >> Practice Set 2
25
▸ L = { 0n 1m 2m 3n | n>=1, m>=1 }
▸ L = { 0n 1m 2m 3n | n, m >=0 }
▸ L = { 0n 1m 2n+m | m,n >=0 }
▸ L = { 0m 1n+m 2n | m,n >=0 }
▸ L = { 0n+m 1m 2n | m,n >=0 }
▸ L = { 0n 1m | n>=1, m>=1, m>n+2 }
▸ L = { a2m c4n dn bm | m,n >=0 }
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
26. PDA >> CFG to PDA
26
▸ Place the marker symbol $ and the start variable on
the stack.
▸ Repeat the following steps forever.
- If the top of stack is a variable symbol A, non-
deterministically select one of the rules for A
and substitute A by the string on the right-hand
side of the rule.
- If the top of stack is a terminal symbol a, read
the next symbol from the input and compare it
to a. If they match, repeat. If they do not match,
reject on this branch of the nondeterminism.
- If the top of stack is the symbol $, enter the
accept state. Doing so accepts the input if it
has all been read.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
For the CFG,
S → aTb | b
T → Ta | 𝜖
27. 27
References:
Chapter 2(section 2.2), Introduction to the Theory of Computation, 3rd Edition by Michael Sipser
THANKS!
Any questions?
You can find me at imam@cse.uiu.ac.bd