- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Design a TM for an equal number of a’s and b’s must follow a

The Turing machine (TM) is more powerful than both finite automata (FA) and pushdown automata (PDA). They are as powerful as any computer we have ever built.

## Formal Definition of Turing Machine

A Turing machine 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.

A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into cells on which input is given. It consists of a head which reads the input tape. A state register stores the state of the Turing machine.

After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input string is accepted, otherwise rejected.

Turing machines have a read/write head. So we can write on the tape.

Now, let us construct a Turing machine which accepts equal number of a’s and b’s,

The language it is generated is L ={ a^{n}b^{n}| n>=1}, the strings that are accepted by the given language is −

L= {ab, aabb, aaabbb, aaaabbbb,………}

**Example**

Consider n=3 so, a^{3}b^{3} , the tape looks like -

B= blank

We need to convert every ‘a’ as X and every ‘b’ as Y. If the Turing machine contains an equal number of X and Y then it reaches the final state.

**Step 1** − Consider the initial state as q0. This state replace ‘a’ as X and move to right, now state changes for q0 toq1, so the transition function is −

δ(q0, a) = (q1,X,R)

**Step 2** − Move right until you see the blank symbol.

δ(q1, a) = (q1,a,R)

δ(q1, b) = (q1,b,R)

After reaching the blank symbol B, move left and change the state to q2, because we need to change the last ‘b’ to Y.

δ(q1, B) = (q2,B,L) //1st iteration δ(q1, Y) = (q2,Y,L) // remaining iterations

**Step 3** − When we see the symbol ‘b’, replace it as Y and change the state to q3 and move left.

δ(q2, B) = (q3,Y,L)

**Step 4** − Move to the left until reach the symbol X.

δ(q3, a) = (q3,a,L) δ(q3, b) = (q3,b,L)

When we reach X move right and change the state as q0, and the next iteration is started.

After replacing every ‘a’ and ‘b’ as X and Y by changing the states to q0 to q4.

δ(q0, Y) = (q4,Y,N)

N represents No movement.

X | X | X | Y | Y | Y | B | B | ........................... |

q4 is the final state and q0 is the initial state of the Turing Machine, the intermediate states are q1, q2, q3.

## Transition diagram

The transition diagram is as follows −

- Related Articles
- Design Turing Machine to reverse string consisting of a’s and b’s
- Design a TM that increments a binary number by 1
- Design a TM which recognizes palindromes over = {a, b}
- Design a TM to compute addition of two unary numbers
- Design a TM that perform right shift over ∑ = {0, 1}
- Construct a TM for adding 1 to a binary natural number?
- Construct a TM for a binary number as an input and replace the last digit with its Boolean complement?
- The Scrum Ceremonies – Must To Follow
- What are the Rules of Netiquette You Must Follow?
- Which of the following statement is always correct?(a) an atom has equal number of electrons and protons (b) an atom has equal number of electrons and neutrons (c) an atom has equal number of protons and neutrons (d) an atom has equal number of electrons, protons and neutrons
- Design Smiley Face Eyes that follow Mouse Cursor using CSS and JS
- Construct a TM for the language L= {ww : w ∈ {0,1}}
- How to print maximum number of A’s using given four keys
- Construct a TM performing multiplication of two unary numbers
- Construct a TM recognizing strings of the form an bn cn| n≥1 over = {a, b, c}