Open In App

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

Last Updated : 20 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:

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

    In the above transition table, States ‘X’, ‘Y’ and ‘Z’ are kept in the first column which on getting ‘a’ as the input it transits to ‘Y’, ‘Y’ and ‘Y’ states respectively, kept in the second column and on getting ‘b’ as the input it transits to ‘X’, ‘Z’ and ‘X’ states respectively, kept in the third column. In the fourth 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 ‘X’ on getting ‘a’ as the input it goes to a state ‘Y’ and gives ‘0’ as the output and on getting ‘b’ as the input it goes to the state ‘X’ and gives ‘0’ 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 transition 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 {a, b} as input and prints ‘1’ as the output for every occurrence of ‘ab’ as a substring.

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.


Similar Reads

Moore and Mealy machines to produce 'A', 'B', 'C' depends on inputs that end with ’10’ or with ’11’ else other
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 '10' or produce 'B' as output if the input ends with '11' otherwise produce 'C' as the output. Assume, Ε = {0, 1} and Δ = {
3 min read
Mealy and Moore Machines in TOC
Moore and Mealy Machines are Transducers that help in producing outputs based on the input of the current state or previous state. In this article we are going to discuss Moore Machines and Mealy Machines, the difference between these two machines as well as Conversion from Moore to Mealy and Conversion from Mealy to Moore Machines. Moore Machines
2 min read
Difference between Mealy machine and Moore machine
Mealy Machine is defined as a machine in the theory of computation whose output values are determined by both its current state and current inputs. In this machine at most one transition is possible. It has 6 tuples: (Q, q0, ∑, ▲, δ, λ’)  Q is a finite set of states q0 is the initial state ∑ is the input alphabet ▲ is the output alphabet δ is the t
2 min read
Conversion of Moore to Mealy machine (Set 4)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we shall see a conversion of Moore to Mealy machine- State Transition Diagram of a Moore machine:- Above Moore machine takes set of all string over {a, b} as input and count the number of substrings as 'ab' i.e, on getting 'ab' as the input s
3 min read
Conversion of Moore to Mealy machine (Set 10)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we shall see a conversion of Moore to Mealy machine- State Transition Diagram of a Moore machine:- Above Moore machine takes the binary number {0, 1} as input and produce residue modulo '3' as output i.e, when the equivalent decimal number of
3 min read
Conversion of Moore to Mealy machine (Set 9)
Prerequisite: Mealy and Moore Machines, Difference between Mealy machine and Moore machine In this article, we shall see a conversion of Moore to Mealy machine- State Transition Diagram of a Moore machine:- Above Moore machine takes the binary number {0, 1} as input and produce residue modulo '2' as output i.e, when the equivalent decimal number of
3 min read
Moore Machines implementation in C++
Moore Machines: A Moore Machine is basically a DFA with an output associated with every state. These machines can be used for a wide variety of tasks such as counting occurrences of a particular substring in a given string, finding 2's complement of a binary number, etc. Working of Moore Machine: It has an output associated with each state.On takin
9 min read
Construction of finite machines to prints ‘1’ as the output for every occurrence of ‘a’ as a substring
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 prints '1' as the output for every occurrence of 'a' as a subs
4 min read
NFA machines accepting all strings that ends or not ends with substring 'ab'
Prerequisite: Finite Automata Introduction Problem-1: Construction of a minimal NFA accepting a set of strings over {a, b} in which each string of the language ends with 'ab'. Explanation: The desired language will be like: L1 = {ab, abbab, abaab, ...........} Here as we can see that each string of the above language ends with 'ab' but the below la
2 min read
Design a mealy machine for 2's complement
Mealy machine is a finite-state machine, its current state and the current inputs determines the output of this machine. There is no final state in Mealy Machine . Here we are going to design a Mealy Machine for 2's Complement Σ = { 0 , 1 } 2's complement : It is the mathematical operation on binary numbers. It is used for computation as a method o
2 min read