Open In App

NPDA for L = {0i1j2k | i==j or j==k ; i , j , k >= 1}

Last Updated : 31 Aug, 2018
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite – Pushdown automata, Pushdown automata acceptance by final state
The language L = {0i1j2k | i==j or j==k ; i , j , k >= 1} tells that every string of ‘0’, ‘1’ and ‘2’ have certain number of 0’s, then certain number of 1’s and then certain number of 2’s. The condition is that count of each of these 3 symbols should be atleast 1. Two important conditions for this language are that either count of 0 should be equal to count of 1 OR count of 1 should be equal to count of 2. Assume that string is ending with ‘$’.

Examples:

Input: 0 0 0 1 1 1 2 2 2 2 2  
        Here 0's = 3, 1's  = 3 so i = j, 2's = 5 
Output: Accepted 
          
Input: 0 0 1 1 1 2 2 2
        Here 0's = 2, 1's = 3, 2's = 3 so j = k
Output: Accepted

Input : 0 0 1 1 1 2 2 2 2
        Here 0's = 2, 1's = 3, 2's = 4 
Output: Not accepted 

There are 2 approaches for the solution. First is for i==j and second is for j==k. These are:

Aiming for a top All India Rank in GATE CS & IT 2025 exam, but not sure where you stand?

We’ve got you covered! FREE GATE CS & IT Test Series - 2025 is designed to give you the edge you need. With previous year questions, subject-wise and full-length mock tests, and All India Mock Test, you can get a real feel of the exam. Plus, get our live mentorship classes with experts and attend live doubt-solving sessions to clear all your queries. 

Steps for i == j :

  1. Input all 0’s in the stack
  2. When we get 1 as input pop a 0 from stack and goto next state.
  3. If input is 1 then pop 0 from stack.
  4. If stack becomes empty (i.e., every 0 corresponding to a 1 has been popped so i = j) and input is 2 then ignore it and goto next state.
  5. If input is 2 then ignore it . If input is finished and $ is received then goto final state.

Steps for j == k :

  1. Input all 0’s in the stack
  2. When we get 1 as input push it onto stack and goto next state.
  3. If input is 1 then push it onto stack.
  4. If input is 2 pop a 1 from stack and goto next state.
  5. If input is 2 then pop 1 from stack. If input is finished and $ is received then pop a 0 from stack.
  6. Pop all remaining 0’s from the stack. If stack becomes empty then goto final state .



Next Article

Similar Reads

NPDA for accepting the language L = {am bn cp dq | m+n=p+q ; m,n,p,q>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m[/Tex] [Tex]b^n[/Tex] [Tex]c^p[/Tex] [Tex]d^q[/Tex] | m + n = p + q : m, n, p, q>=1}, i.e., L = {abcd, abbcdd, abbccd, abbbccdd, ......} In each of the string, the total number of 'a' and
2 min read
NPDA for accepting the language L = {aibjckdl | i==k or j==l,i>=1,j>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^i[/Tex] [Tex]b^j[/Tex] [Tex]c^k[/Tex] [Tex]d^l[/Tex] : i==k or j==l, i>=1, j>=1}, i.e., L = {abcd, aabccd, aaabcccd, abbcdd, aabbccdd, aabbbccddd, ......} In each string, the number of a
3 min read
NPDA for accepting the language L = {an bn cm | m,n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem – Design a non deterministic PDA for accepting the language L = {[Tex]a^n[/Tex] [Tex]b^n[/Tex] [Tex]c^m[/Tex] | m, n>=1}, i.e., L = { abc, abcc, abccc, aabbc, aaabbbcc, aaaabbbbccccc, ...... } In each of the string, the number of a's is equal to number of b's.
2 min read
Construct Pushdown automata for L = {0n1m2m3n | m,n ≥ 0}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Pushdown automata (PDA) plays a significant role in compiler design. Therefore there is a need to have a good hands on PDA. Our aim is to construct a PDA for L = {0n1m2m3n | m,n ≥ 0} Examples - Input : 00011112222333 Output : Accepted Input : 0001122233 Output : Not Accep
3 min read
NPDA for accepting the language L = {a2mb3m | m ≥ 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem – Design a non deterministic PDA for accepting the language L = {a2mb3m | m ≥ 1}, i.e., L = {aabbb, aaaabbbbbb, aaaaaabbbbbbbbb, aaaaaaaabbbbbbbbbbbb, ......} In each of the string, for every 2 'a's there is 3 'b'. Explanation – Here, we need to maintain the or
2 min read
NPDA for accepting the language L = {anbm | n,m ≥ 1 and n ≠ m}
Prerequisite – Pushdown automata, Pushdown automata acceptance by final state Problem – Design a non deterministic PDA for accepting the language [Tex]L = \{a^n b^m | n, m \geq 1 \text{and n!=m}\}[/Tex], i.e., L = {aab, abb, aaab, abbb, aaaab, aaabb, aabbb, abbbb ......} In each of the string, the number of a’s are followed by unequal number of b’s
2 min read
Construct Turing machine for L = {an bm a(n+m) | n,m≥1}
L = {an bm a(n+m) | n,m≥1} represents a kind of language where we use only 2 character, i.e., a and b. The first part of language can be any number of "a" (at least 1). The second part be any number of "b" (at least 1). The third part of language is a number of "a" whose count is sum of count of a's in first part of string and count of b's in secon
3 min read
Construct a Turing Machine for language L = {0n1n2n | n≥1}
Prerequisite - Turing Machine The language L = {0n1n2n | n≥1} represents a kind of language where we use only 3 character, i.e., 0, 1 and 2. In the beginning language has some number of 0's followed by equal number of 1's and then followed by equal number of 2's. Any such string which falls in this category will be accepted by this language. The be
3 min read
Construct a Turing machine for L = {aibjck | i< j< k; i ≥ 1}
Prerequisite – Turing Machine In given language L = {aibjck | i< j< k; i≥ 1}, every string of ‘a’, ‘b’ and ‘c’ have certain number of a’s, then certain number of b’s and then certain number of c’s. The condition is that count of 1st symbols should be atleast 1. ‘b’ and ‘c’ can have thereafter be as many but count of a is less than count of
3 min read
Construct a Turing machine for L = {aibjck | i < j < k or i > j > k}
Prerequisite – Turing Machine The language L = {aibjck | i < j < k or i > j > k} is same as the union of two languages L1={aibjck | i < j < k } and L2={aibjck | i > j > k } In this language, every string of ‘a’, ‘b’ and ‘c’ have certain number of a’s, then certain number of b’s and then certain number of c’s. The condition i
5 min read
Construct Pushdown automata for L = {0m1(n+m)2n | m,n ≥ 0}
Prerequisite – Pushdown automata, NPDA for accepting the language L = {amb(n+m)cm | m, n >= 1} Problem: Construct Pushdown automata for L = {0m1(n+m)2n | m,n ≥ 0} Example: Input: 011122 Output: Accepted Input: 00000112222 Output: Not Accepted Approach used in this PDA – There can be four cases while processing the given input string. Case 1-
2 min read
Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0}
Prerequisite – Pushdown automata Problem: Construct Pushdown automata for L = {0(n+m)1m2n | m, n ≥ 0} Similar PDA's- This PDA seems to be similar to PDA of S2 = {0m1(n+m)2n} but the production is different. S2 will produce output which have no of 1's equal to the sum of no of 0's and 2's, while S1 does not. This PDA seems to be similar to PDA of
3 min read
Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ≥ 1}
Prerequisite – Turing Machine In a given language, L = {aibjck | i*j = k; i, j, k ≥ 1}, where every string of 'a', 'b' and 'c' has a certain number of a's, then a certain number of b's and then a certain number of c's. The condition is that each of these 3 symbols should occur at least once. 'a' and 'b' can occur however many times, but the occurre
2 min read
Program to construct a DFA which accept the language L = {anbm | n mod 2=0, m≥1}
Prerequisite - Finite Automata Introduction Problem: Design a deterministic finite automata (DFA) for accepting the language [Tex]L = \{a^nb^m | n\mod 2=0, m \geq 1\}[/Tex] Regular expression for above language L is, L = (aa)*.b+ Examples: Input: a a b b b Output: ACCEPTED // n = 2 (even) m=3 (>=1) Input: a a a b b b Output: NOT ACCEPTED // n =
10 min read
Construct a Turing Machine for language L = {02n1n | n>=0}
Prerequisite - Turing Machine The language L = {02n1n | n >= 0} represents a kind of language where we use only 2 symbols, i.e., 0 and 1. In the beginning language has some number of 0's followed by exactly half number of 1's . Any such string which falls in this category will be accepted by this language. Examples : Input : 001 Output : YES Inp
2 min read
Construct a DFA which accept the language L = {anbm | n > =1, (m) mod 3 = 1}
Problem: Construct a DFA which accept the language L = {anbm | n > =1, (m) mod 3 = 1}. Explanation: For constructing the DFA, the following things to be remember: [Tex](element)^*[/Tex] which means any no of elements, and [Tex](element)^+[/Tex] = [Tex](element).(element)^*[/Tex] which means any no of elements greater than 1. Examples: Input: a a
9 min read
NPDA for accepting the language L = {an bm cn | m,n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - – Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^m [/Tex][Tex]c^n [/Tex]| m, n>=1}, i.e., L = { abc, abbc, abbbc, aabbcc, aaabccc, aaaabbbcccc, ...... } In each of the string, the number of a's is equal to number of c's.
2 min read
NPDA for accepting the language L = {ambnc(m+n) | m,n ≥ 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m b^n c^{(m+n)} [/Tex]| m,n ≥ 1}, i.e., L = {abcc, aabccc, abbbcccc, aaabbccccc, ......} In each of the string, the total sum of the number of 'a’ and 'b' is equal to the number of c’s. And al
2 min read
NPDA for the language L ={w∈ {a,b}*| w contains equal no. of a's and b's}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L ={w?{a,b}* | w contains equal no. of a's and b's}, i.e., L = {ab, aabb, abba, aababb, bbabaa, baaababb, .......} The number of a's and b's are same in all the strings. Explanation - Here, we need not to
3 min read
NPDA for accepting the language L = {an bn | n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^n [/Tex]| n>=1}, i.e., L = {ab, aabb, aaabbb, aaaabbbb, ......} In each of the string, the number of a's are followed by equal number of b's. Explanation - Here, we need to m
2 min read
NPDA for accepting the language L = {am b(2m) | m>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m [/Tex][Tex]b^{2m} [/Tex]: m>=1}, i.e., L = {abb, aabbbb, aaabbbbbb, aaaabbbbbbbb, ......} In each of the string, the number of a's are followed by double number of b's. Explanation - Here
2 min read
NPDA for accepting the language L = {amb(m+n)cn | m,n ≥ 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^m b^{(m+n)} c^n [/Tex]| m,n ≥ 1} The strings of given language will be: L = {abbc, abbbcc, abbbcc, aabbbbcc, ......} In each of the string, the total sum of the number of 'a’ and 'c' is equal
2 min read
NPDA for accepting the language L = {amb(2m+1) | m ≥ 1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^{m} b^{2m+1} [/Tex]| m ≥ 1}, or,L = {[Tex]a^{m} b b^{2m} [/Tex]| m ≥ 1}, i.e., L = {abbb, aabbbbb, aaabbbbbbb, aaaabbbbbbbbb, ......} In each of the string, the number of 'b' is one more than
2 min read
NPDA for accepting the language L = {anb(2n) | n>=1} U {anbn | n>=1}
Prerequisite - Pushdown automata, Pushdown automata acceptance by final state Problem - Design a non deterministic PDA for accepting the language L = {[Tex]a^n [/Tex][Tex]b^{2n} [/Tex]: n>=1} U {[Tex]a^n [/Tex][Tex]b^{n} [/Tex]: n>=1}, i.e., L = {abb, aabbbb, aaabbbbbb, aaaabbbbbbbb, ......} U {ab, aabb, aaabbb, aaaabbbb, ......} In each stri
2 min read
NPDA for accepting the language L = {a(m+n)bmcn | m,n ≥ 1}
Prerequisite – Pushdown automata, Pushdown automata acceptance by final stateProblem – Design a non deterministic PDA for accepting the language [Tex]L = \{a^{(m+n)} b^m c^n| m, n \geq 1\} [/Tex]The strings of given language will be: L = {aabc, aaabcc, aaabbc, aaaabbcc, ......} In each of the string, the total sum of the number of ‘b’ and ‘c’ is eq
2 min read
NPDA for accepting the language L = {ambncn | m,n ≥ 1}
Prerequisite – Pushdown automata, Pushdown Automata Acceptance by Final State Problem: Design a non deterministic PDA for accepting the language [Tex]L = \{a^m b^n c^n | m, n \geq 1\} [/Tex], i.e., L = {abc, aabc, aabbcc, abbbccc, aabbbccc ...... } The following DFA must contain: The number of a’s is equal to number of c’s.The number of b’s is inde
2 min read
NPDA for accepting the language L = {wwR | w ∈ (a,b)*}
Problem: Design a non deterministic PDA for accepting the language L = {wwR w ∈ (a, b)+}, i.e., L = {aa, bb, abba, aabbaa, abaaba, ......} Prerequisite - Pushdown Automata, Pushdown Automata Acceptance by Final State Explanation: In this type of input string, one input has more than one transition states, hence it is called non-deterministic PDA, a
5 min read
Difference Between NPDA and DPDA
A Pushdown Automata (PDA) is a way to implement context-free Grammar in a similar way. We design Finite Automata for Regular Grammar. It is more powerful than FSM.FSM has very limited memory but PDA has more memory.PDA= Finite State Machine + StackThis stack has infinite memory and that facilitates the higher power of Pushdown automata. This helps
4 min read
Program to construct a DFA which accepts the language L = {aN | N ≥ 1}
Prerequisite: Finite Automata Given a string S of size N, the task is to design a Deterministic Finite Automata (DFA) for accepting the language L = {aN | N ? 1}. The regular language L is {a, aa, aaa, aaaaaaa..., }. If the given string follows the given language L, then print "Accepted". Otherwise, print "Not Accepted". Examples: Input: S = "aaabb
5 min read
What is OSI Model? - Layers of OSI Model
The OSI (Open Systems Interconnection) Model is a set of rules that explains how different computer systems communicate over a network. OSI Model was developed by the International Organization for Standardization (ISO). The OSI Model consists of 7 layers and each layer has specific functions and responsibilities. This layered approach makes it eas
14 min read
  翻译: