Finite Automata with Output (Set 3)

Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine
In this article, we will see some designing of Finite Automata with Output i.e, Moore and Mealy machines.

Problem: Construction of the machines that take set of all string over {a, b} as input and count number of substring β€˜a’.
That is here we have,
Ξ• = {a, b} and
Ξ” = {0, 1}
where Ξ• and Ξ” are the input and output alphabet respectively.
The required Moore machine is constructed below:-

Explanation:
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 β€˜1’ as the output. The state β€˜Y’ on getting β€˜a’ as the input it remains in the state of itself and prints β€˜1’ as the output and on getting β€˜b’ as the input it comes back to the state β€˜X’ and prints β€˜0’ as the output.
Thus finally above Moore machine can easily count substring β€˜a’ i.e, on getting β€˜a’ as the substring it gives β€˜1’ as the output thus on counting number of β€˜1’ we can count the number of substrings β€˜a’.

The required Mealy machine is constructed below:-

Explanation:
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 β€˜1’ as the output. The state β€˜Y’ on getting β€˜a’ as the input it remains in the state of itself and prints β€˜1’ as the output and on getting β€˜b’ as the input it comes back to the state β€˜X’ and prints β€˜0’ as the output.
Thus finally above Moore machine can easily count substring β€˜a’ i.e, on getting β€˜a’ as the substring it gives β€˜1’ as the output thus on counting number of β€˜1’ we can count the number of substrings β€˜a’.