The Wayback Machine - https://web.archive.org/web/20240607080326/https://www.geeksforgeeks.org/construct-turing-machine-l-bm-anm-nm%e2%89%a51/
Open In App

Construct Turing machine for L = {an bm a(n+m) | n,m≥1}

Last Updated : 31 May, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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 second part of string . Any such string which falls in this category will be accepted by this language. The beginning and end of string is marked by $ sign.

Examples:

Input  : a a b b b a a a a a  // n=2, m=3 
Output : Accepted

Input  : a a b a a a a       // n=2, m=1 
Output : Not accepted

Approach used –

  1. Convert “a” in first part into “X” and then move right ignoring all intermediate symbols. When “a” is encountered just after “b” then convert it into “Z” and move left and stop at the position just next to “X”. Repeat the above procedure.
  2. When all a’s in first part have been converted then apply the same process on second part. Convert “b” into “Y” and “a” into “Z” in the third part.
  3. When entire first and second part has been converted and if third part is also converted then string will be accepted else not.

    Steps –

    Step-0: Convert “a” into “X”, move right and go to state 1. If symbol is “b”, ignore it, move right and go to state-4.

    Step-1: If symbol is “a”, ignore it and move right, remain on same state. If symbol is “b”, ignore it, move right and go to state-2.

    Step-2: If symbol is “Z”, ignore it and move right, remain on same state. If symbol is “b”, ignore it and move right, remain on same state and if symbol is “a”, convert it into “Z”, move left and go to state-3.

    Step-3: If symbol is “Z”, ignore it and move left, remain on same state. If symbol is “b”, ignore it and move left, remain on same state. If symbol is “a”, ignore it and move left, remain on same state, and if symbol is “X”, ignore it and move right, go to state-0.

    Step-4: If symbol is “b”, ignore it and move left, go to state 5, and if symbol is “Z”, ignore it and move left, go to state-5.

    Step-5: Convert “b” into “Y”, move right and go to state 6, and if symbol is “Z”, ignore it and move right, go to state-8.

    Step-6: If symbol is “Z”, ignore it and move right, remain on same state. If symbol is “b”, ignore it and move right, remain on same state, and if symbol is “a”, convert it into “Z”, move left and go to state-7.

    Step-7: If symbol is “Z”, ignore it and move left, remain on same state. If symbol is “b”, ignore it and move left, remain on same state, and if symbol is “Y”, ignore it and move right, go to state-5.

    Step-8: If symbol is “Z”, ignore it and move right, remain on same state, and if symbol is “$”, ignore it and move left, go to state-9.

    Step-9: String ACCEPTED


    Previous Article
    Next Article

Similar Reads

Construct a Turing Machine for language L = {0<sup>n</sup>1<sup>n</sup>2<sup>n</sup> | 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 = {a<sup>i</sup>b<sup>j</sup>c<sup>k</sup> | i&lt; j&lt; k; i &ge; 1}
Prerequisite – Turing Machine In given language L = {aibjck | i&lt; j&lt; k; i&ge; 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 = {a<sup>i</sup>b<sup>j</sup>c<sup>k</sup> | i &lt; j &lt; k or i &gt; j &gt; k}
Prerequisite – Turing Machine The language L = {aibjck | i &lt; j &lt; k or i &gt; j &gt; k} is same as the union of two languages L1={aibjck | i &lt; j &lt; k } and L2={aibjck | i &gt; j &gt; 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 a Turing machine for L = {a<sup>i</sup>b<sup>j</sup>c<sup>k</sup> | 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
Construct Pushdown automata for L = {0<sup>n</sup>1<sup>m</sup>2<sup>m</sup>3<sup>n</sup> | 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 = {a<sup>m</sup> b<sup>n</sup> c<sup>p</sup> d<sup>q</sup> | m+n=p+q ; m,n,p,q&gt;=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&gt;=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 = {a<sup>i</sup>b<sup>j</sup>c<sup>k</sup>d<sup>l</sup> | i==k or j==l,i&gt;=1,j&gt;=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&gt;=1, j&gt;=1}, i.e., L = {abcd, aabccd, aaabcccd, abbcdd, aabbccdd, aabbbccddd, ......} In each string, the number of a
3 min read
Construct a Turing Machine for language L = {0<sup>2n</sup>1<sup>n</sup> | n&gt;=0}
Prerequisite - Turing Machine The language L = {02n1n | n &gt;= 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 Pushdown automata for L = {0<sup>m</sup>1<sup>(n+m)</sup>2<sup>n</sup> | m,n &ge; 0}
Prerequisite – Pushdown automata, NPDA for accepting the language L = {amb(n+m)cm | m, n &gt;= 1} Problem: Construct Pushdown automata for L = {0m1(n+m)2n | m,n &ge; 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<sup>(n+m)</sup>1<sup>m</sup>2<sup>n</sup> | m, n &ge; 0}
Prerequisite – Pushdown automata Problem: Construct Pushdown automata for L = {0(n+m)1m2n | m, n &ge; 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