Found 349 Articles for Data Structure Algorithms

Construct a Turing machine for adding 2 to the binary natural number?

Bhanu Priya
Updated on 16-Jun-2021 12:15:53

489 Views

A Turing machine (TM) can be formally described as seven tuples −(Q, X, ∑, δ, q0, B, F)Where, Q is a finite set of states.X is the tape alphabet.∑ is the input alphabet.δ is a transition function:δ:QxX->QxXx{left shift, right shift}.q0 is the initial state.B is the blank symbol.F is the final state.Input − n a natural numberOutput − n + 2Let’s represent natural numbers in unary form (e.g. 3 = 111, 5 = 11111) and 0 will be represented by the empty symbol.AlgorithmMove the tape head to the left of the first 1 (if it exists).Change that empty cell to ... Read More

Construct Turing machine for subtraction

Bhanu Priya
Updated on 15-Jun-2021 15:38:47

6K+ Views

A Turing machine is a seven tuples(Q, Σ, Γ, δ, q0, qacc, qrej)Where, Q is finite number of statesΣ is the input alphabet does not contain the blank symbol t;Γ is the tape alphabet, where t ε Γ and Σ ⊆ Γ;δ: (Q × Γ) → (Q × Γ × {L, R}) is the transition function;q0 ε Q is the start state;qacc ε Q is the accept state;qrej ε Q is the reject state, where qrej ≠qacc.ProblemConstruct a Turing machine (TM) for subtraction of two unary integers.SolutionSubtraction of two unary integers3-2=1In Turing Machine 3 represents − 111       2 ... Read More

Construct Turing machine for addition

Bhanu Priya
Updated on 15-Jun-2021 15:36:09

7K+ Views

Generally in different finite automata a number is represented in binary format.Example − 2- 010     3- 011     4- 100But in case of addition using the Turing machine the system follows a unary format.Example − 2- 11 or 00     3- 111 or 000     4- 1111 or 0000In unary format a number is representedSo, let’s consider zero’s to represent any number in the Turing machine for doing addition.ExampleInputs 4 and 54=00005=00000Then 4+5= 0000c00000Both numbers are separated by a temporary variable c for representing the two numbersOutput: 000000000 =9The Turing Machine (TM) is as follows −ExplanationStep 1 − convert ... Read More

Draw a Turing machine to find 2’s complement of a binary number

Bhanu Priya
Updated on 15-Jun-2021 15:33:34

5K+ Views

2’s complement of binary numbers can be done by using two approaches.Adding 1’s complement+1Traverse bits from left to right, find the 1st 1 bit then reverse all the bits after the 1 bit.ExampleLet the input be 1110010Thus, after performing 2’s complement, the output will be as follows −Output − 0001110Coming to the Turing machine to find 2’s complement, If input is as follows −B010000100The output is as follows −B101111100ExplanationStep 1 − Here, we need to start from the rightmost ends.Step 2 − We will move the R/W head all the way to the right, skipping all the 0s and 1s.Step ... Read More

Draw a Turing machine to find 1’s complement of a binary number

Bhanu Priya
Updated on 15-Jun-2021 15:24:58

3K+ Views

1’s complement means transforming the 0 bit to 1 and the 1 bit to 0.Let the input be −B00101110BThe output is as follows −B11010001BConceptThe concept is explained below −Step 1 − Start scanning the input from left to right.Step 2 − If the R/W is at 1, then make it 0 and move right.Step 3 − If the R/W is at 0, then make it 1 and move right.Step 4 − Repeat the steps given above and we will reach B (blank).Step 5 − Then move the R/W head all the way to the left without changing anything until it ... Read More

Construct a TM for the language L= {ww : w ∈ {0,1}}

Bhanu Priya
Updated on 15-Jun-2021 15:12:46

855 Views

ProblemThe language L = {ww | w ε {0, 1}} having the string of 0’s and 1’s which is followed by itselfL={00, 11, 1100, 0011, …..}SolutionThe logic for solving the problem is as follows −Find the midpoint of the string.Then match the symbols.ExplanationStep 1 − First, we need to find the midpoint of the string.Step 2 − We will make the first 0 to X or 1 to Y and then move R/W head to the right until the last character is found.Step 3 − Then make this 0 to X or 1 to Y.Step 4 − Now, we will ... Read More

Construct PDA for accepting L = {anb(2n) | n>=1} U {anbn | n>=1}

Bhanu Priya
Updated on 15-Jun-2021 15:07:47

1K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting statesProblemConstruct PDA for L = {anb(2n) | n>=1} ∪ {anbn | n>=1}SolutionLetL = {anb(2n) | n>=1}{anbn | n>=1}Construct PDA for L= L1 U L2So, the strings which are generated by the given language L1 are as follows−L1={abb, aabbbb, aaabbbbbb, ….} andL2= {ab, aabb, aaabbb, ….}L= L1 ... Read More

Construct a DPDA for anb2n n ≥ 1 in TOC

Bhanu Priya
Updated on 15-Jun-2021 15:05:23

14K+ Views

A deterministic finite automata (DFA) can remember a finite amount of information but A push down automata (PDA) can remember an infinite amount of information.Basically a PDA is as follows −“Finite state machine+ a stack”PDA has three components, which is as follows −An Input tapeA control unitA Stack with infinite sizeA PDA can be formally described as seven tuples (Q, Σ, S, δ, q0, I, F)Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of ... Read More

Construct PDA for L = {0n1m2(n+m) | m,n >=1}

Bhanu Priya
Updated on 15-Jun-2021 15:03:33

2K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting states(F belongs to Q)ProblemConstruct PDA for 0n1m2(n+m) where n, m>=1.SolutionSo, the strings which are generated by the given language are as follows −L={0122, 001222, 000112222, ….}That is to add the number of 0's and 1's, and that will equal the number of 2's.So for every 0's ... Read More

Construct a PDA for language L = {0n 1m2m3n | n>=1, m>=1}

Bhanu Priya
Updated on 15-Jun-2021 15:01:45

4K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting states(F belongs to Q)ProblemConstruct PDA for 0n1m2m3n where n, m≥1.SolutionSo, the strings which are generated by the given language are −L={0123, 011223, 001233….}The number of 1’s and 3’s are same and number of 2’s and 1’s are sameConstruction of PDA for given problemThe PDA is as ... Read More

Previous 1 ... 4 5 6 7 8 ... 35 Next
Advertisements