0% found this document useful (0 votes)
28 views

Toc Assignments

Uploaded by

oumiarashid6812
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Toc Assignments

Uploaded by

oumiarashid6812
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Department of

Computer Science,

University of
Kashmir.

Introduction

GROUP NUMBER: 06 ▪
Submitted By:
1. Shaista Nazir 22045110009
2. Oumia Rashid 22045110014
3. Salma Shabir 22045110015

4. Munaza Bashir 22045110018


22045110019
5. Insha Arshad

▪ Topic: Push Down Automata (PDA).

▪ Teacher In-charge: Dr Faheem Masoodi


PUSHDOWN AUTOMATA :-
Pushdown Automata is like a finite automata but it has an extra component that
is stack. PDA is used in situations where we need to store data. For storing it uses
stack , which uses LAST IN FIRST OUT(LIFO) order. We can perform push (insert)
and pop (delete) operations on the stack.

PDA accepts all languages accepted by finite automata. In addition to that it


also accepts the languages which are not accepted by finite automata. Thus PDA
is more powerful than Finite automata.

For example, the finite automata is unable to recognize the language


L={0^n1^n|n>=0} because it has no memory. But PDA can recognize this language.

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.

PDA= {Q, Σ, Γ, δ, q0, z0 ,F}

Q is a finite non empty set of states.

Σ is a finite set of input symbols called the input alphabet. Γ is a

finite set of symbols to be pushed or popped from the stack. δ is

a transition function which maps Qx(ΣU{ε})xΓ QxΓ*.

q0 ε Q is a set the initial state.

z0 ε Γ is the start symbol of the stack.

F Q is a set of final states.

Transition function:-
Q x (ΣU{ε})x Γ Q x Γ*.

The transition function δ takes three arguments δ (q, a, x) where

1. Here q denotes any state which belongs to the set Q.

2. a means input symbol to be read. It can be any symbol from alphabet Σ


or it can be ε.

3. x denotes the symbol on top of stack and it belongs to Γ.

The output of transition function δ is a finite set of pairs(p, y) where:-

1. p is the new state resulting after transition from q.

2. y denotes string of symbols which are pushes on top of stack.

The value of y denotes the following operations:-

If y=ε it means the symbol on top of stack is popped.

If y=x it means nothing is pushed or popped from stack.


If y=YZ then x is replaced by Z and Y is pushed on to the stack.

E. g, if y= ab , then x is replaced by b and then a is pushed on stack.

String acceptability by push down automata.


The PDA accepts the string if any of the following two conditions are satisfied.

1. Acceptance by final state:-

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.

2. Acceptance by empty stack:-

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}

Ans: L= {aabc, aaabbc, aaaabbcc….}

Suppose we take m=2 and n=1 == aaabbc^


(a,a/aa)

(a,z0/az0) (b,a/ε) (c,a/ε)

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.

The different transitions perform the following operation:

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.

There are 4 types of grammars in theory of computation .


Unrestricted grammar, context sensitive, context free and regular
grammar. There are more restrictions in regular grammar as compared to other
three types. The languages generated by each type of grammar are accepted by
its corresponding machine. For example, for accepting a language generated by
regular grammar, we have finite automata. Likewise, for context free languages
we have pushdown automata.

In TOC grammar is generating a language from collection of strings.

Context Free Grammar:


A Context Free Grammar ‘G’ is define as quadtuples:

G = {NT, T, P, S}

NT: finite set of variable (Non-terminal) represented by capital letters (A B C…..).

T: finite set of Terminals represented by small letters . Terminal symbols cannot


be replaced by any other symbol. They are used to terminate the derivation.
Terminal symbols represent the leaf nodes of the parse tree.

S: Start symbol in productions. It belongs to the set of non-terminals. When


using a parse tree, the start symbol becomes the root node of the parse tree.

P: Production Rule.

Production Rule of the form

A→α

Where, α = {NT U T}* and A NT where A and α are a set

of terminals and non-terminals.

We can differentiate between different types of grammars in TOC based on type


of their productions. In the case of context free grammar, the productions are of
the form A→ α . Here in the right hand side we can have only one non-terminal
symbol. It cannot have any other terminal or non-terminal symbol. The name is
context free because in order to derive a string from CFG, there is not any other
symbol attached to the non-terminal on the right hand side of production. α can
be , terminals, string of terminals and non-terminals.

Example:
Q: Construct a CFG for the language L= {a2n bn|n>=0}

Ans: We take the language L= a2n bn where n>=0 .

L={ ,aab,aaaabb,aaaaaabbb……}

If the value of “b” increases “a”gets doubled .

i.e S→aaSb ……(1)

S→ ….(2)

Suppose we have to derive the string let say “aaaabb”

S→aaSb……..rule(1)

S→aaaaSbb…..rule(1)

S→ aaaabb…..rule(2)

a a S b

a a S b

Closure Properties Of Regular Language:


A language is said to be a Regular Language if and only if some finite state
machine recoginizes it.

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.

A closure property ascertains that “an operation on languages that belong to a


class (e.g Regualar languages), produces a result that is also in that same class”

For regular language , we can use any of its representation (FA or Re) to prove a
closure property.

The various closure properties of regular language are:

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:

If L1 is a regular language over alphabet , then its complement

̅ ̅1̅= *- L1 is also a regular language.The state statement says that if L1 is a


𝐿̅
regular language, then so is ̅𝐿̅̅1̅.

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:

• By DeMorgan’s law L1∩L2 =̅̅𝐿̅̅̅1̅∪


̅ ̅̅𝐿̅̅2
̅ ̅̅
• We already know that regular languages are closed under complement
and union.
• So, L1∩L2 is regular when L1 and L2 are regular.

6. DIFFERENCE:
If L1 and L2 are regular languages, then L1-L2 is regular.
Proof:

• We can observe that L1 – L2 = L1 ∩̅𝐿̅̅2̅.

• By closure under complement, ̅𝐿̅̅2̅ is regular.

• By closure under intersection, L ∩ ̅𝐿̅̅2̅ is regular.


• Thus, L1-L2 is regular.

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’.

•Reverse the direction of edges of M to make M’.


•No change in loop and remove unnecessary states.

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.

Closure properties of context free languages


1. Union:-
If L1 and L2 are two context free languages and if we perform union of L1 and L2
denoted as L1UL2, then L1UL2 will also belong to the class of context free
languages.

Example:-
L1={anbn|n>=1}

L1={ab,aabb,aaabbb,aaaabbbb,……}

L2={cmdm+1|n>=1}
L2={cdd,ccddd,cccdddd,……}

L1UL2={ ab,aabb,aaabbb,aaaabbbb, 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

Q.1 The context free grammar given by:-

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:-

The language generated by this grammar is

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…….}

So option (c) is the correct answer.

EXAMPLES

NET june 2022


Q.2:Consider the production rules of grammar G:

S→AbB

A→aAb|λ

B→bB|λ

Which of the following language is generated by grammar G?

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:

1. L={an bm:n>=0,m>n} Is Correct Explanation:

S→AbB

A→aAb|λ
B→bB|λ

Language L is generated by grammar G is :

L={an bm:n>=0,m>n}

String can be generated by grammar G is:

{b,bb,abb,abbb…} here an:n>=0 and bm:m>n

2. L={an bm:n>=0,m>=0} Is False


String can be generated by grammar G is:
{ , a, b,ab,aab,abb……} here an:n>=0 and bm:m>=0

3. L={an bm:n>=m} Is False


String can be generated by grammar G is:
{ , a,ab,aab,aaab……} here an:n>=m which means if m is 0 then n can be 0
or greater than 0.

4. L={an bm:n>=m,m>0} Is False


String can be generated by grammar G is:
{ , ab,aab,aabb,aaab……} here an:n>=m and bm:m>0

ISRO 2011

Q.3: Which of the following sentences can be generated by

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

So correct option is (d)

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

Correct answer is (a)

NET June 2022

Q.5:Consider the following statements about the context free languages:-

S1. CFL is closed under homomorphism.

S2. CFL is closed under complement.

Which of the following is correct:-

(i). s1 is true and s2 is false.

(ii). s2 is true and s1 is false.

(iii). Both statement s1 and s2 are true.

(iv). Both s1 and s2 are false.

Homomorphism:-

Let Σ and Γ be two alphabets then homomorphism is a function or mapping h


which maps h: Σ* Γ*.

The function h map assigns a string from Γ* to alphabet of Σ.

1. h(ε)=ε.

2. h(abc)=h(a).h(b).h(c).

For example:-

If we are given the following alphabets:

Σ={a,b} Γ={0,1,2} h(a)=010

h(b)=11 then h(abb)=0101111.

CFLs are closed under homomorphism.


Given a grammar G with productions S→0S1/01.

H is defined as h(0)=ab ,h(1)=ε.

Then after assignment of these values the productions are:- S→abS/ab.

Which also belongs to the set of context free languages.

Therefore we can conclude that CFL is closed under homomorphism.

Complement:-CFL is not closed under complement

We use proof by contradiction to prove the statement,

If L1 and L2 are two CFL. We assume CFLs are closed under complement.

Therefore L1’ and L2’ are CFL.

(L1’U L2’) is a CFL(because CFLs are closed under union).

(L1’ U L2’)’ = CFL (using initial assumption).

(L1’ U L2’)’= L1 ∩ L2 is a CFL.

But CFL is not closed under intersection, therefore we can say that CFL is not
closed under complementation.Hence our assumption is wrong.

ANS= s1 is true and s2 is false.

NET November 2017 Paper III

Q.6: Context free grammar is not closed under:

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:-

If we are given L1= {palindrome}

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:-

Context free languages are closed under Kleene closure.

Given a context free language:

L= {anbn|n>=0}

L*={ anbn, anbn anbn, anbn anbn anbn…}

We can construct context free grammar for this.

S→S1S/ε

S1→aS1b/ε.

3.Union:-

Context free languages are closed under union operation.

L1= {anbn|n>=1}
S1→aS1b/ab

L2={CmDm+1|m>=1}

S2→ cS2d/d

After union operation

S→S1/S2

S1→aS1b/ab

S2→ cS2d/d

4.Complementation:-

We use proof by contradiction to prove the statement,

If L1 and L2 are two CFL. We assume CFLs are closed under complement.

Therefore L1’ and L2’ are CFL.

(L1’U L2’) is a CFL(because CFLs are closed under union).

(L1’ U L2’)’ = CFL (using initial assumption).

(L1’ U L2’)’= L1 ∩ L2 is a CFL.

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.

Five competitive questions on DFA


ISRO 2020
Qno. 1
Minimum number of states required in DFA accepting binary strings
not ending in "101" is
(a) 3
(b) 4
(c) 5
(d) 6
Correct Answer: 2. 4
Binary strings not ending in 101 is a set that is complement to binary strings ending in
101.
Since, regular languages are closed under complement, we can first design a DFA that
accept strings that surely end in 101.

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.

Hence, 4 states will be required.

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

Converting this NFA into minimized DFA

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.

You might also like