Open In App

Mealy and Moore Machines in TOC

Last Updated : 29 Feb, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

Moore Machines are finite state machines with output value and its output depends only on the present state. It can be defined as (Q, q0, ∑, O, δ, λ) where:

  • Q is a finite set of states.
  • q0 is the initial state.
  • ∑ is the input alphabet.
  • O is the output alphabet.
  • δ is the transition function which maps Q×∑ → Q.
  • λ is the output function which maps Q → O.
Figure 1: Moore Machines

Figure 1: Moore Machines

In the Moore machine shown in Figure 1, the output is represented with each input state separated by /. The length of output for a Moore Machine is greater than input by 1.

  • Input: 1,1
  • Transition: δ (q0,1,1)=> δ(q2,1)=>q2
  • Output: 000 (0 for q0, 0 for q2 and again 0 for q2)

Mealy Machines

Mealy machines are also finite state machines with output value and their output depends on the present state and current input symbol. It can be defined as (Q, q0, ∑, O, δ, λ’) where:

  • Q is a finite set of states.
  • q0 is the initial state.
  • ∑ is the input alphabet.
  • O is the output alphabet.
  • δ is the transition function which maps Q×∑ → Q.
  • ‘λ’ is the output function that maps Q×→ O.
Figure 2:Mealy Machines

Figure 2:Mealy Machines

In the mealy machine shown in Figure 1, the output is represented with each input symbol for each state separated by /.  The length of output for a mealy machine is equal to the length of input.

  • Input:1,1
  • Transition: δ (q0,1,1)=> δ(q2,1)=>q2
  • Output: 00 (q0 to q2 transition has Output 0 and q2 to q2 transition also has Output 0)

NOTE: If there are n inputs in the Mealy machine then it generates n outputs while if there are n inputs in the Moore machine then it generates n + 1 outputs. 

Moore Machines vs Mealy Machines

Aspect

Moore Machines

Mealy Machines

Output

Outputs depend only on the current state.

Outputs depend on the current state and input.

Number of States

Tends to require more states due to separate output behavior.

Might require fewer states as outputs are tied to transitions.

Response Time

Slower response to input changes as outputs update on state changes.

Faster response to input changes due to immediate output updates.

Complexity

Can be simpler due to separation of output behavior.

Can be more complex due to combined state-input cases.

For more differences, refer to Difference Between Moore and Mealy Machines.

Conversion From Mealy to Moore Machine

Let us take the transition table of the mealy machine shown in Figure 2.

  Input=0 Input=1
Present State Next State Output Next State Output
q0 q1 0 q2 0
q1 q1 0 q2 1
q2 q1 1 q2 0

Table 1

Step 1. First, find out those states which have more than 1 output associated with them. q1 and q2 are the states which have both output 0 and 1 associated with them.

Step 2 Create two states for these states. For q1, two states will be q10 (a state with output 0) and q11 (a state with output 1). Similarly, for q2, two states will be q20 and q21.

Step 3: Create an empty Moore machine with a newly generated state. For more machines, Output will be associated with each state irrespective of inputs.

  Input=0 Input=1  
Present State Next State Next State Output
q0      
q10      
q11      
q20      
q21      

Table 2

Step 4: Fill in the entries of the next state using the mealy machine transition table shown in Table 1. For q0 on input 0, the next state is q10 (q1 with output 0). Similarly, for q0 on input 1, the next state is q20 (q2 with output 0). For q1 (both q10 and q11) on input 0, the next state is q10. Similarly, for q1(both q10 and q11), next state is q21.  For q10, the output will be 0 and for q11, the output will be 1. Similarly, other entries can be filled.

  Input=0 Input=1  
Present State Next State Next State Output
q0 q10 q20 0
q10 q10 q21 0
q11 q10 q21 1
q20 q11 q20 0
q21 q11 q20 1

Table 3

This is the transition table of the Moore machine shown in Figure 1.

Conversion From Moore Machine to Mealy Machine

Let us take the Moore machine of Figure 1 and its transition table is shown in Table 3.

Step 1. Construct an empty mealy machine using all states of the Moore machine as shown in Table 4.

  Input=0 Input=1
Present State Next State Output Next State Output
q0        
q10        
q11        
q20        
q21        

Table 4

Step 2: Next state for each state can also be directly found from Moore machine transition Table as:

  Input=0 Input=1
Present State Next State Output Next State Output
q0 q10   q20  
q10 q10   q21  
q11 q10   q21  
q20 q11   q20  
q21 q11   q20  

Table 5

Step 3: As we can see output corresponds to each input in the Moore machine transition table. Use this to fill the Output entries. 

Example: Output corresponding to q10, q11, q20 and q21 are 0, 1, 0 and 1 respectively.   

  Input=0 Input=1
Present State Next State Output Next State Output
q0 q10 0 q20 0
q10 q10 0 q21 1
q11 q10 0 q21 1
q20 q11 1 q20 0
q21 q11 1 q20 0

Table 6

Step 4:  As we can see from Table 6, q10 and q11 are similar to each other (same value of next state and Output for different Inputs). Similarly, q20 and q21 are also similar. So, q11 and q21 can be eliminated.

  Input=0 Input=1
Present State Next State Output Next State Output
q0 q10 0 q20 0
q10 q10 0 q21 1
q20 q11 1 q20 0

Table 7

This is the same mealy machine shown in Table 1. So we have converted Mealy to Moore machine and converted back Moore to Mealy.

Note: Number of statAes in the mealy machine can’t be greater than number  of states in moore machine.

Example: The Finite state machine is described by the following state diagram with A as starting state, where an arc label is x / y and x stands for 1-bit input and y stands for 2-bit output.

Moore to Mealy Machines

Outputs the sum of the present and the previous bits of the input.

  1. Outputs 01 whenever the input sequence contains 11.
  2. Outputs 00 whenever the input sequence contains 10.
  3. None of these.

Solution: Let us take different inputs and its output and check which option works:

Input: 01

Output: 00 01  (For 0, Output is 00 and state is A. Then, for 1, Output is 01 and state will be B)

Input: 11

Output: 01 10 (For 1, Output is 01 and state is B. Then, for 1, Output is 10 and state is C)

As we can see, it is giving the binary sum of the present and previous bit. For the first bit, the previous bit is taken as 0.

FAQs on Mealy and Moore Machines

1. Amongst Moore and Mealy Machine, which is easier to design?

Answer:

In general, Moore Machines are simpler to design because of seperation from output from its input.

2. Can Moore and Melay Machines can be used together in a system?

Answer:

Yes, Moore and Mealy can be combinely used easily. It is used as per choice determined by any specefic system.



Previous Article
Next Article

Similar Reads

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:
3 min read
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
Difference Between Mealy Machine and Moore Machine
In theory of computation and automata, there are two machines: Mealy Machine and Moore Machine which is used to show the model and behavior of circuits and diagrams of a computer. Both of them have transition functions and the nature of taking output on same input is different for both. In this article, we will learn about Mealy and Moore Machines
4 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
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
Mealy Machine for 1's Complement
After converting a number to its binary form, replace every one of the number with 0 and every 0 with 1, then the resulting number will be known as 1, s complement of that binary number. Input-1 : 101010 Output-1 : 010101 Input-2 : 1110100 Output-2 : 0001011 Approach : First make a initial state. Then convert each 0 to 1 and each 1 to 0, and reach
1 min read
Boyer-Moore Majority Voting Algorithm
The Boyer-Moore voting algorithm is one of the popular optimal algorithms which is used to find the majority element among the given elements that have more than N/ 2 occurrences. This works perfectly fine for finding the majority element which takes 2 traversals over the given elements, which works in O(N) time complexity and O(1) space complexity
7 min read
DFA machines accepting odd number of 0’s or/and even number of 1’s
Prerequisite - Designing finite automata Problem - Construct a DFA machine over input alphabet [Tex]\sum_[/Tex]= {0, 1}, that accepts: Odd number of 0’s or even number of 1’s Odd number of 0’s and even number of 1’s Either odd number of 0’s or even number of 1’s but not the both together Solution - Let first design two separate machines for the two
3 min read
L-graphs and what they represent in TOC
Prerequisite - Finite automata introduction All programming languages can be represented as a finite automata. C, Paskal, Haskell, C++, all of them have a specific structure, grammar, that can be represented by a simple graph. Most of the graphs are NFA’s or DFA’s. But NFA’s and DFA’s determine the simplest possible language group: group of regular
5 min read
Hypothesis (language regularity) and algorithm (L-graph to NFA) in TOC
Prerequisite - Finite automata, L-graphs and what they represent L-graphs can generate context sensitive languages, but it’s much harder to program a context sensitive language over programming a regular one. This is why I’ve came up with a hypothesis about what kind of L-graphs can generate a regular language. But first, I need to introduce you to
7 min read
Computable and non-computable problems in TOC
Computable Problems - You are familiar with many problems (or functions) that are computable (or decidable), meaning there exists some algorithm that computes an answer (or output) to any instance of the problem (or for any input to the function) in a finite number of simple steps. A simple example is the integer increment operation: f(x) = x + 1 I
6 min read
Decidability, Semi-Decidability, and Undecidability in TOC
We know about Decidable, Semi-decidable, and Undecidable problems and in this article, we will briefly define these problems and provide the most commonly asked questions on these problems and classify them accordingly. Prerequisite - https://www.geeksforgeeks.org/decidable-and-undecidable-problems-in-theory-of-computation/ Introduction :Identifyin
3 min read
Recursive and Recursive Enumerable Languages in TOC
Recursive Enumerable (RE) or Type -0 Language RE languages or type-0 languages are generated by type-0 grammars. An RE language can be accepted or recognized by Turing machine which means it will enter into final state for the strings of language and may or may not enter into rejecting state for the strings which are not part of the language. It me
5 min read
Decidability and Undecidability in TOC
Identifying languages (or problems*) as decidable, undecidable or partially decidable is a very common question in GATE. With correct knowledge and ample experience, this question becomes very easy to solve. Lets start with some definitions:- Decidable language -A decision problem P is said to be decidable (i.e., have an algorithm) if the language
5 min read
Undecidability and Reducibility in TOC
Decidable Problems A problem is decidable if we can construct a Turing machine which will halt in finite amount of time for every input and give answer as ‘yes’ or ‘no’. A decidable problem has an algorithm to determine the answer for a given input. Examples Equivalence of two regular languages: Given two regular languages, there is an algorithm an
5 min read
Construction of the machines to produce residue modulo ‘2’ of binary numbers
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 the binary number {0, 1} as input and produce residue modulo '2' as output i.e, when the equivalent decim
2 min read
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 Δ =
4 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
Restricted Turing Machines
In this article, we are going to describe the basics concepts of the restricted Turing machine and for basic understanding, you can first read the pre-requisite which will help you to understand the topic clearly. Prerequisite - Turing Machine Turing Machine accepts the recursively enumerable language. It is more powerful than any other automata su
2 min read
Dovetailing in Turing Machines
In the carpentry industry, dovetailing is a technique of joining two pieces of wood together by interleaving them. Similarly in the case of Turing Machines dovetailing is the technique by which we can simulate multiple Turing Machines, in some cases an infinite number of Turing Machines together. This technique can be very useful in determining the
4 min read
Kleene's Theorem in TOC | Part-1
A language is said to be regular if it can be represented by using Finite Automata or if a Regular Expression can be generated for it. This definition leads us to the general definition that; For every Regular Expression corresponding to the language, a Finite Automata can be generated. For certain expressions like:- (a+b), ab, (a+b)*; It's fairly
4 min read
Determining Countability in TOC
Countable Set is a set having cardinality same as that of some subset of N the set of natural numbers . A countable set is the one which is listable. Cardinality of a countable set can be a finite number. For example, B: {1, 5, 4}, |B| = 3, in this case its termed countably finite or the cardinality of countable set can be infinite. For example, A:
3 min read
Closure properties Table in TOC
The Below Table shows the Closure Properties of Formal Languages : REG = Regular LanguageDCFL = deterministic context-free languages, CFL = context-free languages,CSL = context-sensitive languages,RC = Recursive.RE = Recursive Enumerable Consider L and M are regular languages : The Kleene star - ∑*, is a unary operator on a set of symbols or string
3 min read
Reduction Theorem in TOC
Reduction Theorem :A reduction from A to B is a function f : Σ1* → Σ2* such that For any w ∈ Σ1*, w ∈ A if f(w) ∈ B Every w ∈ A maps to some f(w) ∈ B.Every w ∉ A maps to some f(w) ∉ B.f does not have to be injective or surjective. Why Reductions Matter?If language A reduces to language B, we can use a recognizer / co-recognizer / decider for B to r
5 min read
Ladner's theorem in TOC
Ladner's theorem in TOC :As you presumably know, regardless of whether P = NP is a significant perplexing issue in field of Computer Science. In computational complexity, those problems which belongs to NP- problems but can't belong to P or NP-complete are known as NP-intermediate problems. Taking into account NP-complete issues, it is normal to ke
5 min read
Basic Theorems in TOC (Myhill nerode theorem)
The Myhill Nerode theorem is a fundamental result coming down to the theory of languages. This theory was proven by John Myhill and Anil Nerode in 1958. It is used to prove whether or not a language L is regular and it is also used for minimization of states in DFA( Deterministic Finite Automata). To understand this theorem, first we need to unders
3 min read
Turing Machine in TOC
Turing Machine was invented by Alan Turing in 1936 and it is used to accept Recursive Enumerable Languages (generated by Type-0 Grammar).  Turing machines are a fundamental concept in the theory of computation and play an important role in the field of computer science. They were first described by the mathematician and computer scientist Alan Turi
6 min read