Skip to content
Related Articles

Related Articles

Improve Article

NPDA for accepting the language L = {wwR | w ∈ (a,b)*}

  • Difficulty Level : Expert
  • Last Updated : 01 Jun, 2021

Prerequisite – Pushdown Automata, Pushdown Automata Acceptance by Final State 
Problem: Design a non deterministic PDA for accepting the language L = {wwR w ∈ (a, b)*}, i.e., 
 

L = {aa, bb, abba, aabbaa, abaaba, ......} 

Explanation: 
In this type of input string, at one input has more than one transition states, hence it is called non deterministic PDA and input string contain any order of ‘a’ and ‘b’. Each input alphabet has more than one possibility to move next state. And finally when stack is empty then the string is accepted by the NPDA. In this NPDA we used some symbol which are given below: 
 

Γ = { a, b, z }

Where, Γ = set of all the stack alphabet 
z = stack start symbol 
a = input alphabet 
b = input alphabet 

Approach used in the construction of PDA – 
As we want to design a NPDA, thus every times ‘a’ or ‘b’ comes then either push into the stack or move into the next state. It is dependent on a string.When we see the input alphabet which is equal to the top of stack then that time pop operation apply on the stack and move to next step. 
So, at the end if the stack becomes empty then we can say that the string is accepted by the PDA. 

STACK Transiton Function 
 



\delta(q0, a, z) \vdash (q0, az)

\delta(q0, a, a) \vdash (q0, aa)

\delta(q0, b, z) \vdash (q0, bz)

\delta(q0, b, b) \vdash (q0, bb)

\delta(q0, a, b) \vdash (q0, ab)

\delta(q0, b, a) \vdash (q0, ba)



\delta(q0, a, a) \vdash (q1, ∈)

\delta(q0, b, b) \vdash (q1, ∈)

\delta(q1, a, a) \vdash (q1, ∈)

\delta(q1, b, b) \vdash (q1, ∈)



\delta(q1, ∈, z) \vdash (qf, z)

Where, q0 = Initial state 
qf = Final state 
∈ = indicates pop operation 

 

So, this is our required non deterministic PDA for accepting the language L = {wwR w ∈ (a, b)*} 

Example: 
We will take one input string: “abbbba”. 
 

  • Scan string from left to right
  • First input is ‘a’ and follow the rule:
  • on input ‘a’ and STACK alphabet Z, push the two ‘a’s into STACK as : (a, Z/aZ) and state will be q0
  • on input ‘b’ and STACK alphabet ‘a’, push the ‘b’ into STACK as : (b, a/ba) and state will be q0
  • on input ‘b’ and STACK alphabet ‘b’, push the ‘b’ into STACK as : (b, b/bb) and state will be q0
  • on input ‘b’ and STACK alphabet ‘b’ (state is q1), pop one ‘b’ from STACK as : (b, b/∈) and state will be q1
  • on input ‘b’ and STACK alphabet ‘b’ (state is q1), pop one ‘b’ from STACK as : (b, b/∈) and state will be q1
  • on input ‘a’ and STACK alphabet ‘a’ and state q1, pop one ‘a’ from STACK as : (a, a/∈) and state will remain q1
  • on input ∈ and STACK alphabet Z, go to final state(qf) as : (∈, Z/Z)

So, at the end the stack becomes empty then we can say that the string is accepted by the PDA. 

Problem: 
Design a deterministic PDA for accepting the language L = { wcwR w ∈ (a, b)*}, i.e., 
 

{aca, bcb, abcba, abacaba, aacaa, bbcbb, .......}

In each of string, sub string which are present in left side of c is reverse of sub string which is present right side of c. 



Explanation : 
Here we need to maintain string in such way that, substring which is present in the left side of c is exactly reverse substring which is the right side of c. For doing this we used a stack.In string ‘a’ and ‘b’ are present any order and ‘c’ is comes only one times. When ‘c’ comes then after pop operation is start into the stack. And when a stack is empty then language is accepted. 

 

Γ = {a, b, z} 

Where, Γ = set of all the stack alphabet 
z = stack start symbol 
a = input alphabet 
b = input alphabet 

Approach used in the construction of PDA: 
As we want to design PDA In every time when ‘a’ or ‘b’ comes we push into the stack and stay on same state q0. And when ‘c’ comes then we move to the next state q1 without pushing ‘c’ into the stack. And after when comes an input which is the same as the top of the stack then pop from the stack and stay on the same state. POP operation is performed until the input string is end. Finally when the input is ∈ then move to the final state qf. 
When if the stack will become empty then language is accepted. 

Where, q0 = Initial state 
qf = Final state 
z = stack start symbol 
∈= indicates pop operation 

Stack transition functions: 
 

\delta(q0, a, z) \vdash (q0, az)

\delta(q0, a, a) \vdash (q0, aa)

\delta(q0, b, z) \vdash (q0, bz)

\delta(q0, b, b) \vdash (q0, bb)

\delta(q0, a, b) \vdash (q0, ab)

\delta(q0, b, a) \vdash (q0, ba)



\delta(q0, c, a) \vdash (q1, a)

\delta(q0, c, b) \vdash (q1, b)

\delta(q1, a, a) \vdash (q1, ∈)

\delta(q1, b, b) \vdash (q1, ∈)



\delta(q1, ∈, z) \vdash (qf, z) 

Where, q0 = Initial state 
qf = Final state 
∈ = indicates pop operation 

 

So, this is our required deterministic PDA for accepting the language, 
 

L = { wcwR w ∈ (a, b)*} 

 

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.




My Personal Notes arrow_drop_up
Recommended Articles
Page :