The Wayback Machine - https://web.archive.org/web/20240607080326/https://www.geeksforgeeks.org/turing-machine-for-subtraction-set-2/
Open In App

Turing Machine for subtraction | Set 2

Last Updated : 29 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Turing Machine, Turing machine for subtraction | Set 1 A number is represented in binary format in different finite automatas like 5 is represented as (101) but in case of subtraction Turing Machine unary format is followed . In unary format a number is represented by either all ones or all zeros. For example, 5 will be represented by a sequence of five ones 5 = 1 1 1 1 1 or 0 0 0 0 0. Lets use zeros for representation. For subtraction of numbers using a Turing Machine, both these numbers are given as input to the Turing machine separated by a “c”. Example – (3 – 4) or (4 – 3) will be given as 0 0 0 c 0 0 0 0

Input:  0 0 0 c 0 0 0 0  // (3 - 4) or (4 - 3)
Output:  0              // (1)

Approach used – Convert a 0 in the first number into X and then move to the right, keep ignoring 0’s and “c” then make the first 0 as X and move to the left . Now keep ignoring 0’s, X’s and “c” and after finding the second zero repeat the same procedure till all the zeros on the left hand side becomes X .Now move right and convert the last X encountered into B(Blank). Steps – Step 1 – Convert 0 into X and move right then goto step2 . If symbol is “c” then ignore it with moving to the right and go to step 6 . Step 2 – Keep ignoring 0’s and move right . Ignore “c”, move right and goto step 3 . Step 3 – Keep ignoring X and move right . Convert the first 0 encountered as X and move left and goto step 4 . Step 4 – Keep ignoring all X’s and “c” to the left and goto step 5 . Step 5 – Keep moving left with ignoring 0’s and when the first X is found then ignore it and move right, and goto step 1 . Step 6 – Keep ignoring all the X’s and move to the right . Ignore the first 0 encountered and move to the left then goto step 7 . Step 7 – Convert the X into B ( Blank ) and goto step 8 . Step 8 – End .


Previous Article
Next Article

Similar Reads

Turing machine for subtraction | Set 1
Prerequisite - Turing Machine Problem-1: Draw a Turing machine which subtract two numbers. Example: Steps: Step-1. If 0 found convert 0 into X and go right then convert all 0's into 0's and go right.Step-2. Then convert C into C and go right then convert all X into X and go right.Step-3. Then convert 0 into X and go left then convert all X into X a
2 min read
Turing machine for multiplication
Prerequisite - Turing Machine Problem: Draw a turing machine which multiply two numbers. Example: Steps: Step-1. First ignore 0's, C and go to right & then if B found convert it into C and go to left. Step-2. Then ignore 0's and go left & then convert C into C and go right. Step-3. Then convert all X into X and go right if 0 found convert i
2 min read
Turing machine for copying data
Prerequisite - Turing Machine Problem - Draw a Turing machine which copy data. Example - Steps: Step-1. First convert all 0's, 1's into 0's, 1's and go right then B into C and go left Step-2. Then convert all 0's, 1's into 0's, 1's and go left then Step-3. If 1 convert it into X and go right convert all 0's, 1's into 0's, 1's and go right then conv
2 min read
Why only subtraction of addresses allowed and not division/addition/multiplication
Why Subtraction is allowed? Two addresses can be subtracted because the memory between the two addresses will be valid memory. Let's assume memory Ptr_1 and ptr_2 valid addresses. It is obvious that memory between these two addresses is valid. Pointer ptr_1 is pointing to 0x1cb0010 memory location and ptr_2 is pointing to 0x1cb0030 memory location.
2 min read
Virtualization | A Machine Reference Model
Prerequisite: Introduction to Virtualization When an execution environment is virtualized at unlike levels of the stack of computation then it requires a reference model which defines the interfaces within the level of abstractions, and this level of abstraction hides the details of implementations. This projects an idea that, virtualization techni
3 min read
Relationship between Data Mining and Machine Learning
There is no universal agreement on what "Data Mining" suggests that. The focus on the prediction of data is not always right with machine learning, although the emphasis on the discovery of properties of data can be undoubtedly applied to Data Mining always. So, let's begin with that: data processing may be a cross-disciplinary field that focuses o
3 min read
Create Free Windows Virtual Machine in Azure
A virtual machine may be a file, typically called an image, which behaves like an actual computer. The top user has an equivalent experience on a virtual machine as they might have on dedicated hardware. But in a cloud virtual machine is an operating system image running on the server, we can use a cloud virtual machine in many ways - Development,
2 min read
Print Binary Tree levels in sorted order | Set 2 (Using set)
Given a tree, print the level order traversal in sorted order. Examples : Input : 7 / \ 6 5 / \ / \ 4 3 2 1 Output : 7 5 6 1 2 3 4 Input : 7 / \ 16 1 / \ 4 13 Output : 7 1 16 4 13 We have discussed a priority queue based solution in below post.Print Binary Tree levels in sorted order | Set 1 (Using Priority Queue) In this post, a set (which is impl
5 min read
Check whether the number has only first and last bits set | Set 2
Given a positive integer n, check whether only the first and last bits are set in the binary representation of n. Print 'Yes' or 'No'.Examples: Input: 9 Output: Yes (9)10 = (1001)2, only the first and last bits are set. Input: 15 Output: No (15)10 = (1111)2, except first and last there are other bits also which are set. We have already discussed a
4 min read
Frequent Item set in Data set (Association Rule Mining)
INTRODUCTION:Frequent item sets, also known as association rules, are a fundamental concept in association rule mining, which is a technique used in data mining to discover relationships between items in a dataset. The goal of association rule mining is to identify relationships between items in a dataset that occur frequently together.A frequent i
6 min read
Article Tags :
Practice Tags :