Open In App

Turing Machine as Comparator

Prerequisite – Turing Machine

Problem : Draw a turing machine which compare two numbers. Using unary format to represent the number. For example, 4 is represented by 
 



4 = 1 1 1 1  or 0 0 0 0 

Lets use one’s for representation. 

Example: 



 

Approach: 
 

  1. Comparing two numbers by comparing number of ‘1’s.
  2. Comparing ‘1’s by marking them ‘X’.
  3. If ‘1’s are remaining in left of ‘0’, then first number is greater.
  4. If ‘1’s are remaining in right of ‘0’, then second number is greater.
  5. If both ‘1’ are finished then both numbers are equal.

Steps: 
 

State transition diagram : 
 

Here, Q0 shows the initial state and Q2, Q3, Q4, Q5 shows the transition state and (A < B), (A = B)and (A > B) shows the final state. 0, 1 are the variables used and R, L shows right and left. 

Explanation: 
 

 

Article Tags :