TCS Tutorial Solution_Acceptor
10 May 2025 14:25
Turing Machine as an Acceptor
Q1. Design Turing Machine to accept {a n bn | n >= 0). Simulate for string "aabb"
Ans: Approach:
Step 1: Replace the first a by Blank
Step 2: Move right till last non-Blank symbol.
Step3: Replace last b by Blank.
Step 4: Move left till first non-Blank symbol of tape.
Step 5: Repeat from Step 1.
7-tuple representation of TM
New Section 4 Page 1
Simulation for "aabb"
Ⴡ q0 a a b b B Ⴡ B q1 a b b B Ⴡ B a q1 b b B Ⴡ B a b q1 b B
Ⴡ B a b b q1 B Ⴡ B a b q2 b B Ⴡ B a q3 b B B Ⴡ B q3 a b B B
Ⴡ q3 B a b B B Ⴡ B q0 a b B B Ⴡ B B q1 b B B Ⴡ B B b q1 B B
Ⴡ B B q2 b B B Ⴡ B q3 B B B B Ⴡ B B q0 B B B Ⴡ B B q4 B B B
Q2. Design Turing Machine to accept {w c w| w є (a+b)*).
Ans: Approach:
Step 1: Replace the first symbol by Blank. For input a, go to Step 2 and for input b, go to Step 3.
Step 2: Move right till input is c and go to Step 4 (with memory of leftmost as a)
Step 3: Move right till input is c and go to Step 5 (with memory of leftmost as b)
Step 4: Replace the symbol after c by Blank, if the symbol is a (Skip X, if any) and go to Step 6.
Step 5: Replace the symbol after c by Blank, if the symbol is b (Skip X, if any) and go to Step 6.
Step 6: Move left till first non-Blank symbol of tape.
Step 7: Repeat from Step 1.
7-tuple representation of TM
New Section 4 Page 2
New Section 4 Page 3
TCS Tutorial Solution_Generator
10 May 2025 16:20
Turing Machine as an Generator
Q1. Design Turing Machine to add 2 binary numbers.
Ans:
Assume 2 way infinite model of TM.
Assume input in form "m + n", where m is first number and n is second number (both in Binary representation)
Approach:
Step 1: Move right till last non-Blank symbol (i.e. LSB of n).
Step 2: Decrement n by 1. If n is 0, go to Step 6
Step 3: Move left till LSB of m (i.e. left of +).
Step 4: Increment m by 1.
Step 5: Repeat from step 1.
Step 6: Blank all symbols from last non-Blank symbol on right till + (plus) and stop/ halt.
m has been replaced by m + n
Graphical representation:
Q2. Design Turing Machine to compute a2.
Ans:
Assume input is a, followed by infinite Blank symbols.
Assume that a is represented in Unary where alphabet set is {1}
Approach:
Step 1: Decrement a by 1 (replace by B) and for that add a * and 1 at the end.
Step 2: Repeatedly decrement a by 1 (replace 1 by X) and add 1 after *.
When no more 1s in a, tape has (a-1)-times X, followed by *, followed by a-times 1.
Step 3: Replace all X by 1 to get (a-1) times 1, followed by *, followed by a-times 1.
Now, follow method of multiplication of 2 numbers to get a2
Graphical representation of TM:
New Section 4 Page 4
New Section 4 Page 5