# Construct a Turing machine for L = {a^{i}b^{j}c^{k} | i*j = k; i, j, k ≥ 1}

Prerequisite – Turing Machine

In given language L = {a^{i}b^{j}c^{k} | i*j = k; i, j, k ≥ 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 each of these 3 symbols should be atleast 1. ‘a’ and ‘b’ can have thereafter be as many but count of c is equal to the product of count of ‘a’ and count of ‘b’. Assume that string is ending with ‘$’.

**Examples –**

Input: a a b b b c c c c c c Here a = 2, b = 3, c = 2 * 3 = 6 Output: ACCEPTED Input: a a b b c c c Here a = 2, b = 2, c = 3 but c should be 4 Output: NOT ACCEPTED

**Approach used –** Scan the input from left.

- First replace an ‘a’ with ‘X’ and move 1 step right. Then skip all the a’s and move right.
- When pointer reach to the first ‘b’ stop. Replace one ‘b’ with ‘Y’, then move right skipping all intermediate b’s and corresponding to the replaced ‘b’ now replace one ‘c’ with ‘Z’ and move left.
- Now move towards left skipping all ‘Z’ and ‘b’ in the way.
- When pointer reach the most recent ‘Y’ move right.
- If the pointer is pointing at ‘b’ then repeat steps 2 to 4, else if pointer is pointing at ‘Z’ then move towards left while replacing all ‘Y’ to ‘b’ and skipping all a’s.
- When pointer comes to most recent ‘X’ move one step right.
- If pointer is still pointing to ‘a’ then repeat all above steps, else if pointer is at ‘Y’ then move towards right skipping all ‘Y’ and ‘Z’.
- When $ is reached then move left. String is ACCEPTED.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Turing Machine in TOC
- Turing Machine for subtraction | Set 2
- Construct Pushdown Automata for given languages
- Construct Turing machine for L = {a
^{n}b^{m}a^{(n+m)}| n,m≥1} - Design 101 sequence detector (Mealy machine)
- Construct Pushdown Automata for all length palindrome
- Construct a Turing Machine for language L = {0
^{n}1^{n}2^{n}| n≥1} - Construct a Turing Machine for language L = {ww
^{r}| w ∈ {0, 1}} - Construct a Turing Machine for language L = {ww | w ∈ {0,1}}
- Construct a Turing machine for L = {a
^{i}b^{j}c^{k}| i>j>k; k ≥ 1} - Turing Machine for addition
- Turing machine for multiplication
- Turing machine for subtraction | Set 1
- Difference between Mealy machine and Moore machine
- Turing machine for copying data
- Construct Pushdown automata for L = {0
^{n}1^{m}2^{m}3^{n}| m,n ≥ 0} - Construct Pushdown automata for L = {a
^{(2*m)}c^{(4*n)}d^{n}b^{m}| m,n ≥ 0} - Construct Pushdown automata for L = {0
^{n}1^{m}2^{(n+m)}| m,n ≥ 0} - Turing machine for 1's and 2’s complement
- Turing Machine as Comparator

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.