Skip to content
Related Articles

Related Articles

Improve Article

Turing Machine for addition

  • Difficulty Level : Medium
  • Last Updated : 29 Jul, 2021

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 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 right and goto step-1. 

Step-6: End. 

 

 

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :