Design Turing Machine to reverse string consisting of a’s and b’s

Data Structure AlgorithmsComputer ScienceComputers

Our aim is to design a Turing machine (TM) to reverse a string consisting of a’s and b’s over an alphabet {a,b}.


Input − aabbab

Output − babbaa


Step 1: Move to the last symbol, replace x for a or x for b and move right to convert the corresponding B to          „a‟ or „b‟ accordingly.
Step 2: Move left until the symbol left to x is reached.
Step 3: Perform step 1 and step 2 until „B‟ is reached while traversing left.
Step 4: Replace every x to B to make the cells empty since the reverse of the string is performed by the             previous steps.

The transition diagram for Turing Machine (TM) is as follows −

Let us consider an example to check whether the given input is getting reverse or not 

Input string - abb.

Expected output - {bba}

Therefore, the TM is as follows −

Updated on 14-Jun-2021 16:05:02