Open In App

Moore and Mealy machines to count number of substring ‘ab’

Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine
Problem: Construction of the machines that take set of all string over {a, b} as input and count number of substring ‘ab’
Assume,

Ε = {a, b} and 
Δ = {0, 1} 

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



Explanation:
The required Moore machine is constructed below.



In the above diagram, the initial state ‘X’ on getting ‘b’ as the input it remains in the state of itself and print ‘0’ as the output and on getting ‘a’ as the input it transits to a state ‘Y’ and prints ‘0’ as the output.

The state ‘Y’ on getting ‘a’ as the input it remains in the state of itself and prints ‘0’ as the output and on getting ‘b’ as the input it transmits to the state ‘Z’ and prints ‘1’ as the output. The state ‘Z’ on getting ‘a’ as the input it transmits to the state ‘Y’ and prints ‘0’ as the output and on getting ‘b’ as the input it transmits to the state ‘X’ and prints ‘0’ as the output.

Thus finally above Moore machine can easily count the number of substring ‘ab’ i.e, on getting ‘ab’ as the input it gives ‘1’ as the output thus on counting the outputs ‘1’, we can easily count substring ‘ab’.

Conversion of Moore machine to Mealy machine:
Above Moore machine takes set of all string over {a, b} as input and prints ‘1’ as the output for every occurrence of ‘ab’ as substring. Now we need to transform the above transition diagram of Moore machine to equivalent Mealy machine transition diagram.

Steps for the required conversion are given below:

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 do not give same number of states.

Article Tags :