Toc Assignments
Toc Assignments
Computer Science,
University of
Kashmir.
Introduction
GROUP NUMBER: 06 ▪
Submitted By:
1. Shaista Nazir 22045110009
2. Oumia Rashid 22045110014
3. Salma Shabir 22045110015
COMPONENTS OF PDA:-
1. Input tape:- The input tape consists of strings of symbols to be read.
2. Control unit:- The control unit has some pointer which points to the
current symbol which is to be read.
3. Stack:- The stack stores the symbols. The push operation adds a symbol on
top of stack. The pop operation removes a symbol from top of stack.
Input tape
Definition:-
Push down automata can be represented as 7 tuple.
Transition function:-
Q x (ΣU{ε})x Γ Q x Γ*.
It means that if the PDA reads the whole string and then enters the final state,
then we can say that the string is accepted by pushdown automata.
After reading the input string if the PDA has an empty stack, then the string is
accepted by finite automata.
Example
1. Construct a PDA for L= {am+n bm cn |m, n>=1}
q0 q1 q2 q3q3
(b,a/ε) (c,a/ε) (^,z0,z0)
In the above example first we have m+n a’s and m b’s and n c’s. So first
we push (m+n) a’s on stack.Then we pop one a for every input of b. After that
remaining a’s are popped when c is input.
1. (a,z0/az0):-
Here , a is the current input symbol. z0 is the symbol on top of stack and it
denotes that the stack is empty. So we pop z0 from the stack, then push z0 and
input symbol a. 2. (a, a/aa):-
a is the current input symbol, the symbol on top of stack is also a. We pop an a
from the stack, then push a and current input symbol(a). By using this transition
we push all the a’s on the stack.
3. (b, a, ε):-
Now the input symbol is b, the top of stack is a and ε denotes that we have to
pop a symbol from top of stack.
By using this transition we pop a’s from the stack at every input symbol of b.
4. (c, a/ε):-
Now the remaining a’s are popped using the input symbol c.
After that the PDA reaches the final state and the string is accepted.
In this example both the conditions are satisfied, the PDA reaches the final state
and also the stack is empty.
a
stack
a
Z0
Grammar:
Firstly, Grammar in TOC is same as grammar in natural language. Grammar is a
standard way of representing a language.
G = {NT, T, P, S}
P: Production Rule.
A→α
Example:
Q: Construct a CFG for the language L= {a2n bn|n>=0}
L={ ,aab,aaaabb,aaaaaabbb……}
S→ ….(2)
S→aaSb……..rule(1)
S→aaaaSbb…..rule(1)
S→ aaaabb…..rule(2)
a a S b
a a S b
Closure means suppose if we have set of natural numbers and if we perform any
operation(+, -,*,%)between them then there result should also be a natural
number.
For regular language , we can use any of its representation (FA or Re) to prove a
closure property.
1. UNION:
If L1 and L2 are regular languages, then L1 L2is regular.
Proof:
• Since L1 and L2 are regular, they have regular expressions; say L1 = L(R)
and L2= L(S).
• Then L1 L2 = L(R+S) by the definition of the + operator for regular
expressions.
• Thus, L1 L2 is regular.
2. CONCATENATION:
If L1 and L2 are regular languages, then L1L2 is regular.
Proof:
• Since L1 and L2 are regular, they have regular expressions; say L1=L(R)
and L2=L(S).
• Then L1L2=L(RS) by the definition of the concatenation operator for
regular expressions.
• Thus, L1L2 is regular
3. KLEENE CLOSURE:
If L1 is a regular language, then L1* is regular.
Proof:
• Since L1 is regular, it has a regular expression; say L1=L(R).
• Then L1*=L(R*) by the definition of the closure operator for regular
expressions.
• Thus, L1* is regular.
4. COMPLEMENTATION:
Proof:
• Take deterministic FA for L1 and interchange the accept and reject states.
5. INTERSECTION:
If L1 and L2 are regular languages, then L1∩L2 is regular.
Proof:
6. DIFFERENCE:
If L1 and L2 are regular languages, then L1-L2 is regular.
Proof:
7. REVERSAL:
If L1 is a regular language, then its reversal L1R is regular.
Proof:
•Make initial state of M as final state of M’.
•Final state of M become initial state of M’.
8. HOMOMORPHISM:
A homomorphism on an alphabet is a function h that gives a string for
each symbol in that alphabet.
– Suppose and are alphabets, the function h: → * is called a
homomorphism.
• Extend to strings by h(a1…an ) = h(a1)…h(an). • Extend to
languages h(L) = { h(w) | w L } Example:
• h(0) = ab; h(1) = ε.
• h(01010) = ababab.
• h({010110, 11, 1001}) = {ababab, ε, abab} Closure
property:-
Closure means if we perform a certain operation of the two languages belonging
to a particular class(e.g context free language .Then the result obtained after the
operation will also belong to that class.
Example:-
L1={anbn|n>=1}
L1={ab,aabb,aaabbb,aaaabbbb,……}
L2={cmdm+1|n>=1}
L2={cdd,ccddd,cccdddd,……}
2. Concatenation:-
Concatenation is the closure property of context free languages that if we
perform concatenation of two context free languages, then the resulting
language will also be CFL.
Example:-
L1={11,01,000,10}
L2={ε,aa}
L1.L2={11,01,000,10,11aa,01aa,000aa,10aa}
3.Kleene star:-
Given a language L if we perform Kleene star operation of a context free
language then it will also belong to the class of context free languages.
4. Intersection:-
Context free languages are not closed under intersection.The kleene star
operation of two languages L1 and L2 denoted as L1UL2 is not context free. So
we can say that context free languages are not closed under intersection.
Example:-
L1 and L2 are two context free languages.
L1={anbncm|n,m>=0}
L2={ambncm|n,m>=0}
L1={ε,ab,abc,aabb,aabbc,aabbcc,aaabbb,aaabbbc,aaabbbccc,}
L2={ε,bc,abc,bbcc,abbcc,aabbcc,bbbccc,abbbccc,aabbbccc,aaabbb}
L1∩L2={ε,abc,aabbcc,aaabbbccc…….}
5.Complement:-
The complement of a language is defined with respect to universal set.The
complement denoted as L’ includes all the strings that are not present in the
language.
EXAMPLES
NET 2015
S→XYX
X→aX/bX/ε
Y→bbb
(a).(a+b)*bbb
(b).abbb(a+b)*
(c).(a+b)*(bbb)(a+b)*
(d).(a+b)(bbb)(a+b)*
Explanation:-
1. S→XYX
S→aXYaX
S→aεbbbaε
S→abbbb
2. S→XYX
S→bXYaX
S→bεbbbaε
S→bbbba
3.S→XYX
S→aXYbX
S→aaXbbbbaX
S→aaεbbbbaε
S→aabbbba
L={abbbb,bbbba,aabbbba,bababbbaaab…….}
EXAMPLES
S→AbB
A→aAb|λ
B→bB|λ
1. L={an bm:n>=0,m>n}
2. L={an
bm:n>=0,m>=0}
3. L={an bm:n>=m} 4.
L={an bm:n>=m,m>0}
ANS:
S→AbB
A→aAb|λ
B→bB|λ
L={an bm:n>=0,m>n}
ISRO 2011
S→aS|bA
A→d|cA
a. bccdd
b. abbcca
c. abcabc
d. abcd
ANS:
S→aS ………..(S→bA)
S→abA…………..(A→cA)
S→abcA …………..(A→d)
S→abcd
ISRO 2011
Q.4:What is the number of steps required to derive the string ( ( () () ) () ) for the
following grammar.
S→ SS
S→ (S)
S→
a. 10
b. 15
c. 12
d. 16
ANS: We will find the solution of this grammar by drawing the Parse tree which is
a graphical representation of the grammer
Homomorphism:-
1. h(ε)=ε.
2. h(abc)=h(a).h(b).h(c).
For example:-
If L1 and L2 are two CFL. We assume CFLs are closed under complement.
But CFL is not closed under intersection, therefore we can say that CFL is not
closed under complementation.Hence our assumption is wrong.
1. Concatenation.
2. complementation.
3. Kleene star.
4. Union.
Explanation:- 1.Concatenation:-
CFL is closed under concatenation , because if we concatenate two CFLs we again
get a CFL.
For example:-
S1→ aS1a/bS1b/a/b/ε}
L2= {anbn|n>=0}
S2→aS2b/ε}
S→S1S2
S1→ aS1a/bS1b/a/b/ε}
S2→aS2b/ε}
The grammar we obtained is also context free therefore CFL is closed under
concatenation.
2. Kleene star:-
L= {anbn|n>=0}
S→S1S/ε
S1→aS1b/ε.
3.Union:-
L1= {anbn|n>=1}
S1→aS1b/ab
L2={CmDm+1|m>=1}
S2→ cS2d/d
S→S1/S2
S1→aS1b/ab
S2→ cS2d/d
4.Complementation:-
If L1 and L2 are two CFL. We assume CFLs are closed under complement.
But CFL is not closed under intersection , therefore we can say that CFL is not
closed under complementation. Hence our assumption is wrong.
Ans.
Context free languages are closed under union, kleene star and concatenation but
not under complementation.
For finding the complement of this DFA, we simple change the non-final states to final
and final state to non-final keeping the initial state as it is.
GATE CS 2019
Qno. 2
Let ∑ be the set of all bijections from {1, ..., 5} to {1, ..., 5), where id denotes
the identity function, i.e. id(j) = j, ∀j. Let。 denote composition on functions.
For a string X = X1 X2….. Xn ∈ ∑𝒏 , n ≥ 0, let π(x) = X1 。X2 。.. . 。 Xn.
Ans:. Total number of bijective from A → A where A = {1,2 3, 4, 5} is 5! = 120.
The DFA for accepting L will have 5! = 120 states, since we need one state for
every possible permutation function on 5 elements.
GATE CS 2021
Qno.3
Number of states in DFA accepting the following language is:
L = {a^n b^2m | n, m ≥ 1 }
1. n
2. 5
3. m
4. 2
It is easier to find the minimized DFA if we find the NFA first
NFA of the given language
Transition table
Hence, number of states in DFA for the language L = { a^n b^2m | n, m ≥ 1 } is 5
GATE CS 2008
Qno 4
.Let N be an NFA with n states. Let k be the number of states of a minimal DFA
which is equivalent to N. Which one of the following is necessarily true?
a) k ≥ 2^n
b) k ≥ n
c) k ≤ n^2
d) k ≤ 2^n
Correct answer is option 'D'.
Let N be an NFA with n states. Let k be the number of states The minimum
number of state in DFA will be 1 when we have only starting state and all other
states will not be reachable from stating state. The minimum number of state in
DFA will be 2^n as the number of subsets of a set with n elements in the worst
case. Therefore, k ≤ 2^n Option (D) is correct.