# TOC | Construction of the machines that produce ‘A’, ‘B’, or ‘C’ if input ends with ‘1’, ‘0’, or nothing

Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine

**Problem:** Construction of the machines that take set of all string over {0, 1} as input and produce ‘A’ as output if the input ends with ‘1’ or produce ‘B’ as output if the input ends with ‘0’ otherwise produce ‘C’ as the output.

Assume,

Ε = {0, 1, 2} and Δ = {A, B, C}

where Ε and Δ are the input and output alphabet respectively.

**Explanation:**

The required Moore machine is constructed below:

In the above diagram, the initial state ‘w’ on getting ‘2’ as the input it remains in the state of itself and prints ‘C’ as the output, on getting ‘1’ as the input it transmits to a state ‘Y’ and prints ‘A’ as the output and on getting ‘0’ as the input it transmits to a state ‘X’ and prints ‘B’ as the output and so on for the remaining states.

Thus finally above Moore machine can easily produce ‘A’ as output if the input ends with ‘1’ or produce ‘B’ as output if the input ends with ‘0’ otherwise produce ‘C’

Above Moore machine takes set of all string over {0, 1} as input and produce ‘A’ as output if the input ends with ‘1’ or produce ‘B’ as output if the input ends with ‘0’ otherwise produce ‘C’ as the output.

Now we need to transform the above transition diagram of Moore machine to equivalent Mealy machine transition diagram.

**Conversion from Moore machine to Mealy machine:**

Steps for the required conversion are given below:-

**Step-1:**Formation of State Transition Table of the above Moore machine-

In the above transition table, States ‘W’, ‘X’ and ‘Y’ are kept in the first column which on getting ‘0’ as the input it transits to ‘X’, ‘X’ and ‘X’ states respectively, kept in the second column and on getting ‘1’ as the input it transits to ‘Y’, ‘Y’ and ‘Y’ states respectively, kept in the third column and on getting ‘2’ as the input it transits to ‘W’, ‘W’ and ‘W’ states respectively, kept in the fourth column and In the fifth column under Δ, there are corresponding outputs of the first column states. In the table, An arrow (→) indicates the initial state.**Step-2:**Formation of Transition Table for Mealy machine from above Transition Table of Moore machine-

Below transition table is going to be formed with the help of the above table and its entries just by using the corresponding output of the states of the first column and placing them in the second and third column accordingly.

In the above table, the states in the first column like ‘W’ on getting ‘0’ as the input it goes to a state ‘X’ and gives ‘B’ as the output and on getting ‘1’ as the input it goes to the state ‘Y’ and gives ‘A’ as the output and on getting ‘2’ as the input it goes to the state ‘W’ and gives ‘C’ as the output and so on for the remaining states in the first column. In the table, An arrow (→) indicates the initial state.**Step-3:**Then finally we can form the state trasition diagram of Mealy machine with help of it’s above transition table.

The required diagram is shown below-

Above Mealy machine takes set of all string over {0, 1} as input and produce ‘A’ as output if the input ends with ‘1’ or produce ‘B’ as output if the input ends with ‘0’ otherwise produce ‘C’ as the output.- Mealy and Moore Machines
- DFA machines accepting odd number of 0’s or/and even number of 1’s
- TOC | Construction of the machines to produce residue modulo ‘2’ of binary numbers
- TOC | Moore and Mealy machines to count number of substring ‘ab’
- TOC | Moore and Mealy machines to produce 'A', 'B', 'C' depends on inputs that end with ’10’ or with ’11’ else other
- TOC | Construction of finite machines to prints ‘1’ as the output for every occurrence of ‘a’ as a substring
- NFA machines accepting all strings that ends or not ends with substring 'ab'
- DFA (Recognizer) for valid Pascal identifiers
- Multitape Nondeterministic Turing Machine simulator
- NFA machines accepting all strings that ends or not ends with substring 'ab'
- Construct a DFA which accept the language L = {w | w ∈ {a,b}* and Na(w) mod 3 = Nb (w) mod 3}
- Construct a DFA which accept the language L = {a
^{n}b^{m}| n > =1, (m) mod 3 = 1} - NPDA for accepting the language L = {wwR | w ∈ (a,b)*}
- Program for Gauss Siedel Method (Computational Mathematics)

**Note:** While converting from Moore to Mealy machine the number of states remains same for both Moore and Mealy machine but in case of Mealy to Moore conversion it does not give the same number of states.

## Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.