0% found this document useful (0 votes)
21 views10 pages

ToC Notes - Unit 3

Uploaded by

shani123890
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
21 views10 pages

ToC Notes - Unit 3

Uploaded by

shani123890
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

UNIT: 3

Pushdown Automata

3.1. Formal definition of PDA:


• Basically a pushdown automaton is −
"Finite state machine" + "a stack"
• Pushdown automata is a way to implement a CFG in the same way we design DFA for a
regular grammar. A DFA can remember a finite amount of information, but a PDA can
remember an infinite amount of information.
• Pushdown automata is simply an NFA augmented with an "external stack memory". The
addition of stack is used to provide a last-in-first-out memory management capability to
Pushdown automata.
• Pushdown automata can store an unbounded amount of information on the stack. It can
access a limited amount of information on the stack. A PDA can push an element onto
the top of the stack and pop off an element from the top of the stack. To read an element
into the stack, the top elements must be popped off and are lost.
• A PDA is more powerful than FA. Any language which can be acceptable by FA can also
be acceptable by PDA. PDA also accepts a class of language which even cannot be
accepted by FA. Thus PDA is much more superior to FA.
3.2 PDA Components:

Input tape: The input tape is divided in many cells or symbols. The input head is read-only and
may only move from left to right, one symbol at a time.

Finite control: The finite control has some pointer which points the current symbol which is to
be read.

Stack: The stack is a structure in which we can push and remove the items from one end only. It
has an infinite size. In PDA, the stack is used to store the items temporarily.

3.3 Basic Structure of PDA:

The PDA can be defined as a collection of 7 components:

Q: the finite set of states


∑: the input set
Γ: a stack symbol which can be pushed and popped from the stack
q0: the initial state
Z: a start symbol which is in Γ.
F: a set of final states
δ: mapping function which is used for moving from current state to next state.

3.4 Terminologies Related to PDA:

Instantaneous Description (ID) - ID is an informal notation of how a PDA computes an input


string and makes a decision that string is accepted or rejected. An instantaneous description is a
triple (q, w, α) where:

• q Describes the current state.


• w describes the remaining input.
• α describes the stack contents, top at the left.

Turnstile Notation- The "turnstile" notation is used for connecting pairs of ID's that represent
one or many moves of a PDA. The process of transition is denoted by the turnstile symbol " ⊢".

⊢ sign describes the turnstile notation and represents one move.


⊢* sign describes a sequence of moves.

For example,

(p, b, T) ⊢ (q, w, α)
In the above example, while taking a transition from state p to q, the input symbol 'b' is
consumed, and the top of the stack 'T' is represented by a new string α.

Example: Design a PDA for accepting a language {0n1m0n | m, n>=1}.

Solution: In this PDA, n number of 0's are followed by any number of 1's followed n number of
0's. Hence the logic for design of such PDA will be as follows:

Push all 0's onto the stack on encountering first 0's. Then if we read 1, just do nothing. Then read
0, and on each read of 0, pop one 0 from the stack.

For instance:

This scenario can be written in the ID form as:

1. δ(q0, 0, Z) = δ(q0, 0Z)


2. δ(q0, 0, 0) = δ(q0, 00)
3. δ(q0, 1, 0) = δ(q1, 0)
4. δ(q0, 1, 0) = δ(q1, 0)
5. δ(q1, 0, 0) = δ(q1, ε)
6. δ(q0, ε, Z) = δ(q2, Z) (ACCEPT state)

Now we will simulate this PDA for the input string "0011100".
1. δ(q0, 0011100, Z) ⊢ δ(q0, 011100, 0Z)
2. ⊢ δ(q0, 11100, 00Z)
3. ⊢ δ(q0, 1100, 00Z)
4. ⊢ δ(q1, 100, 00Z)
5. ⊢ δ(q1, 00, 00Z)
6. ⊢ δ(q1, 0, 0Z)
7. ⊢δ(q1, ε, Z)
8. ⊢δ(q2, Z)
9. ACCEPT

3.5 PDA Acceptance- A language can be accepted by Pushdown automata using two
approaches:

3.5.1. Acceptance by Final State: The PDA is said to accept its input by the final state if it
enters any final state in zero or more moves after reading the entire input.

Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by the final state can be defined
as:

L(PDA) = {w | (q0, w, Z) ⊢ * (p, ε, ε), q ∈ F}

3.5.2. Acceptance by Empty Stack: On reading the input string from the initial configuration
for some PDA, the stack of PDA gets empty.

Let P =(Q, ∑, Γ, δ, q0, Z, F) be a PDA. The language acceptable by empty stack can be defined
as:

N(PDA) = {w | (q0, w, Z) ⊢* (p, ε, ε), q ∈ Q}

3.5.3 Equivalence of Acceptance by Final State and Empty Stack


• If L = N(P1) for some PDA P1, then there is a PDA P2 such that L = L(P2). That
means the language accepted by empty stack PDA will also be accepted by final state
PDA.
• If there is a language L = L (P1) for some PDA P1 then there is a PDA P2 such that L
= N(P2). That means language accepted by final state PDA is also acceptable by
empty stack PDA.

Example: Construct a PDA that accepts the language L over {0, 1} by empty stack which
accepts all the string of 0's and 1's in which a number of 0's are twice of number of 1's.

Solution: There are two parts for designing this PDA:


• If 1 comes before any 0's
• If 0 comes before any 1's.

We are going to design the first part i.e. 1 comes before 0's. The logic is that read single 1 and
push two 1's onto the stack. Thereafter on reading two 0's, POP two 1's from the stack. The δ can
be

1. δ(q0, 1, Z) = (q0, 11, Z) Here Z represents that stack is empty


2. δ(q0, 0, 1) = (q0, ε)

Now, consider the second part i.e. if 0 comes before 1's. The logic is that read first 0, push it onto
the stack and change state from q0 to q1. [Note that state q1 indicates that first 0 is read and still
second 0 has yet to read].

Being in q1, if 1 is encountered then POP 0. Being in q1, if 0 is read then simply read that second
0 and move ahead. The δ will be:

1. δ(q0, 0, Z) = (q1, 0Z)


2. δ(q1, 0, 0) = (q1, 0)
3. δ(q1, 0, Z) = (q0, ε) (indicate that one 0 and one 1 is already read, so simply read the second 0)
4. δ(q1, 1, 0) = (q1, ε)

Now, summarize the complete PDA for given L is:

1. δ(q0, 1, Z) = (q0, 11Z)


2. δ(q0, 0, 1) = (q1, ε)
3. δ(q0, 0, Z) = (q1, 0Z)
4. δ(q1, 0, 0) = (q1, 0)
5. δ(q1, 0, Z) = (q0, ε)
6. δ(q0, ε, Z) = (q0, ε) ACCEPT state

3.6 Non-deterministic Pushdown Automata- The non-deterministic pushdown


automata is very much similar to NFA. We will discuss some CFGs which accepts NPDA.

The CFG which accepts deterministic PDA accepts non-deterministic PDAs as well. Similarly,
there are some CFGs which can be accepted only by NPDA and not by DPDA. Thus NPDA is
more powerful than DPDA.

Example: Design PDA for Palindrome strips.

Solution: Suppose the language consists of string L = {aba, aa, bb, bab, bbabb, aabaa, ......]. The
string can be odd palindrome or even palindrome. The logic for constructing PDA is that we will
push a symbol onto the stack till half of the string then we will read each symbol and then
perform the pop operation. We will compare to see whether the symbol which is popped is
similar to the symbol which is read. Whether we reach to end of the input, we expect the stack to
be empty.

This PDA is a non-deterministic PDA because finding the mid for the given string and reading
the string from left and matching it with from right (reverse) direction leads to non-deterministic
moves. Here is the ID.

Simulation of abaaba

1. δ(q1, abaaba, Z) Apply rule 1


2. ⊢δ(q1, baaba, aZ) Apply rule 5
3. ⊢δ(q1, aaba, baZ) Apply rule 4
4. ⊢δ(q1, aba, abaZ) Apply rule 7
5. ⊢δ(q2, ba, baZ) Apply rule 8
6. ⊢δ(q2, a, aZ) Apply rule 7
7. ⊢δ(q2, ε, Z) Apply rule 11
8. ⊢δ(q2, ε) Accept
3.7 CFG to PDA Conversion- The first symbol on R.H.S. production must be a terminal
symbol. The following steps are used to obtain PDA from CFG is:

Step 1: Convert the given productions of CFG into GNF.

Step 2: The PDA will only have one state {q}.

Step 3: The initial symbol of CFG will be the initial symbol in the PDA.

Step 4: For non-terminal symbol, add the following rule:

δ(q, ε, A) = (q, α)

Where the production rule is A → α

Step 5: For each terminal symbols, add the following rule:

δ(q, a, a) = (q, ε) for every terminal symbol

Example 1: Convert the following grammar to a PDA that accepts the same language.
S → 0S1 | A
A → 1A0 | S | ε

Solution: The CFG can be first simplified by eliminating unit productions:

S → 0S1 | 1S0 | ε

Now we will convert this CFG to GNF:

S → 0SX | 1SY | ε
X→1
Y→0

The PDA can be:

R1: δ(q, ε, S) = {(q, 0SX) | (q, 1SY) | (q, ε)}


R2: δ(q, ε, X) = {(q, 1)}
R3: δ(q, ε, Y) = {(q, 0)}
R4: δ(q, 0, 0) = {(q, ε)}
R5: δ(q, 1, 1) = {(q, ε)}
Example 2: Draw a PDA for the CFG given below:
S → aSb
S→a|b|ε

Solution: The PDA can be given as:

P = {(q), (a, b), (S, a, b, z0), δ, q, z0, q}

The mapping function δ will be:

R1: δ(q, ε, S) = {(q, aSb)}


R2: δ(q, ε, S) = {(q, a) | (q, b) | (q, ε)}
R3: δ(q, a, a) = {(q, ε)}
R4: δ(q, b, b) = {(q, ε)}
R5: δ(q, ε, z0) = {(q, ε)}

Simulation: Consider the string aaabb

1. δ(q, εaaabb, S) ⊢ δ(q, aaabb, aSb) R3


2. ⊢δ(q, εaabb, Sb) R1
3. ⊢ δ(q, aabb, aSbb) R3
4. ⊢δ(q, εabb, Sbb) R2
5. ⊢δ(q, abb, abb) R3
6. ⊢δ(q, bb, bb) R4
7. ⊢ δ(q, b, b) R4
8. ⊢ δ(q, ε, z0) R5
9. ⊢ δ(q, ε)
10. ACCEPT

3.8 Closure Properties of Context Free Languages:-

Context Free languages (CFG) are accepted by pushdown automata (PDA) but not by finite
automata (FA). Context free grammar generates the Context free languages. Let discuss
some Closure Properties of CFG.

3.8.1. CFG Closure Properties-

Union: If L1 and L2 are two context free languages, their union L1 ∪ L2 will also be context
free. For example,
L1 = { anbncm | m >= 0 and n >= 0 } and L2 = { anbmcm | n >= 0 and m >= 0 }
L3 = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also context free.

L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be
equal to number of c’s. Their union says either of two conditions to be true. So it is also context
free language.

Concatenation: If L1 and If L2 are two context free languages, their concatenation L1.L2 will
also be context free. For example,
L1 = { anbn | n >= 0 } and L2 = { cmdm | m >= 0 }
L3 = L1.L2 = { anbncmdm | m >= 0 and n >= 0} is also context free.
L1 says number of a’s should be equal to number of b’s and L2 says number of c’s should be
equal to number of d’s. Their concatenation says first number of a’s should be equal to number
of b’s, then number of c’s should be equal to number of d’s. So, we can create a PDA which will
first push for a’s, pop for b’s, push for c’s then pop for d’s. So it can be accepted by pushdown
automata, hence context free.

Kleene Closure: If L1 is context free, its Kleene closure L1* will also be context free. For
example,
L1 = { anbn | n >= 0 }
L1* = { anbn | n >= 0 }* is also context free.

Intersection and complementation: If L1 and If L2 are two context free languages, their
intersection L1 ∩ L2 need not be context free. For example,
L1 = { anbncm | n >= 0 and m >= 0 } and L2 = (ambncn | n >= 0 and m >= 0 }
L3 = L1 ∩ L2 = { anbncn | n >= 0 } need not be context free.

You might also like