Turing Machine for addition

Prerequisite – Turing Machine
A number is represented in binary format in different finite automatas like 5 is represented as (101) but in case of addition using a turing machine unary format is followed. In unary format a number is represented by either all ones or all zeroes. For example, 5 will be represented by a sequence of five zeroes or five ones. 5 = 1 1 1 1 1 or 0 0 0 0 0. Lets use zeroes for representation.

For adding 2 numbers using a Turing machine, both these numbers are given as input to the Turing machine separated by a “c”.

Examples – (2 + 3) will be given as 0 0 c 0 0 0:

Input  :  0 0 c 0 0 0    // 2 + 3
Output :  0 0 0 0 0      // 5

Input  :  0 0 0 0 c 0 0 0  // 4 + 3
Output :  0 0 0 0 0 0 0    // 7

Approach used –
Convert a 0 in the the first number in to X and then traverse entire input and convert the first blank encountered into 0. Then move towards left ignoring all 0’s and “c”. Come the position just next to X and then repeat the same procedure till the time we get a “c” instead of X on returning. Convert the c into blank and addition is completed.

Steps –

Step-1: Convert 0 into X and goto step 2. If symbol is “c” then convert it into blank(B), move right and goto step-6.

Step-2: Keep ignoring 0’s and move towards right. Ignore “c”, move right and goto step-3.

Step-3: Keep ignoring 0’s and move towards right. Convert a blank(B) into 0, move left and goto step-4.

Step-4: Keep ignoring 0’s and move towards left. Ignore “c”, move left and goto step-3.

Step-5: Keep ignoring 0’s and move towards left. Ignore an X, move left and goto step-1.

Step-6: End.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.