Skip to content
Related Articles

Related Articles

Improve Article
Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ≥ 1}
  • Difficulty Level : Expert
  • Last Updated : 23 Aug, 2018

Prerequisite – Turing Machine
In given language L = {aibjck | 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.

  1. First replace an ‘a’ with ‘X’ and move 1 step right. Then skip all the a’s and move right.
  2. 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.
  3. Now move towards left skipping all ‘Z’ and ‘b’ in the way.
  4. When pointer reach the most recent ‘Y’ move right.
  5. 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.
  6. When pointer comes to most recent ‘X’ move one step right.
  7. 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’.
  8. When $ is reached then move left. String is ACCEPTED.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :