The Wayback Machine - https://web.archive.org/web/20240922165822/https://www.geeksforgeeks.org/minimization-of-dfa/
Open In App

Minimization of DFA

Last Updated : 13 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

DFA minimization stands for converting a given DFA to its equivalent DFA with minimum number of states. DFA minimization is also called as Optimization of DFA and uses partitioning algorithm.

Minimization of DFA 
Suppose there is a DFA D < Q, Δ, q0, Δ, F > which recognizes a language L. Then the minimized DFA D < Q’, Δ, q0, Δ, F’ > can be constructed for language L as: 
Step 1: We will divide Q (set of states) into two sets. One set will contain all final states and other set will contain non-final states. This partition is called P0. 
Step 2: Initialize k = 1 
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-1, we will take all possible pair of states. If two states of a set are distinguishable, we will split the sets into different sets in Pk. 
Step 4: Stop when Pk = Pk-1 (No change in partition) 
Step 5: All states of one set are merged into one. No. of states in minimized DFA will be equal to no. of sets in Pk. 

How to find whether two states in partition Pk are distinguishable ? 
Two states ( qi, qj ) are distinguishable in partition Pk if for any input symbol a, Δ ( qi, a ) and Δ ( qj, a ) are in different sets in partition Pk-1. 
Example 
Consider the following DFA shown in figure. 
 

fig 1

Step 1. P0 will have two sets of states. One set will contain q1, q2, q4 which are final states of DFA and another set will contain remaining states. So P0 = { { q1, q2, q4 }, { q0, q3, q5 } }. 
Step 2. To calculate P1, we will check whether sets of partition P0 can be partitioned or not: 

i) For set { q1, q2, q4 } : 
Δ( q1, 0 ) = Δ ( q2, 0 ) = q2 and Δ ( q1, 1 ) = Δ( q2, 1 ) = q5, So q1 and q2 are not distinguishable. 
Similarly, Δ( q1, 0 ) = Δ ( q4, 0 ) = q2 and Δ ( q1, 1 ) = Δ ( q4, 1 ) = q5, So q1 and q4 are not distinguishable. 
Since, q1 and q2 are not distinguishable and q1 and q4 are also not distinguishable, So q2 and q4 are not distinguishable. So, { q1, q2, q4 } set will not be partitioned in P1. 

ii) For set { q0, q3, q5 } : 
Δ ( q0, 0 ) = q3 and Δ ( q3, 0 ) = q0 
Δ( q0, 1) = q1 and Δ( q3, 1 ) = q4 
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are in same set in partition P0. Similarly, Moves of q0 and q3 on input symbol 1 are q1 and q4 which are in same set in partition P0. So, q0 and q3 are not distinguishable. 

Δ( q0, 0 ) = q3 and Δ( q5, 0 ) = q5 and Δ( q0, 1 ) = q1 and Δ ( q5, 1 ) = q5 
Moves of q0 and q5 on input symbol 1 are q1 and q5 respectively which are in different set in partition P0. So, q0 and q5 are distinguishable. So, set { q0, q3, q5 } will be partitioned into { q0, q3 } and { q5 }. So, 
P1 = { { q1, q2, q4 }, { q0, q3}, { q5 } } 

To calculate P2, we will check whether sets of partition P1 can be partitioned or not: 
iii)For set { q1, q2, q4 } : 
Δ ( q1, 0 ) = Δ ( q2, 0 ) = q2 and Δ ( q1, 1 ) = Δ( q2, 1 ) = q5, So q1 and q2 are not distinguishable. 
Similarly, Δ ( q1, 0 ) = Δ ( q4, 0 ) = q2 and Δ( q1, 1 ) = Δ( q4, 1 ) = q5, So q1 and q4 are not distinguishable. 
Since, q1 and q2 are not distinguishable and q1 and q4 are also not distinguishable, So q2 and q4 are not distinguishable. So, { q1, q2, q4 } set will not be partitioned in P2. 

iv)For set { q0, q3 } : 
Δ ( q0, 0 ) = q3 and Δ( q3, 0 ) = q0 
Δ ( q0, 1 ) = q1 and Δ ( q3, 1 ) = q4 
Moves of q0 and q3 on input symbol 0 are q3 and q0 respectively which are in same set in partition P1. Similarly, Moves of q0 and q3 on input symbol 1 are q1 and q4 which are in same set in partition P1. So, q0 and q3 are not distinguishable. 

v) For set { q5 }: 
Since we have only one state in this set, it can’t be further partitioned. So, 
P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } } 
Since, P1=P2. So, this is the final partition. Partition P2 means that q1, q2 and q4 states are merged into one. Similarly, q0 and q3 are merged into one. Minimized DFA corresponding to DFA of Figure 1 is shown in Figure 2 as: 
 

fig 2

  

Question : Consider the given DFA. Which of the following is false? 
1. Complement of L(A) is context-free. 
2. L(A) = L ( ( 11 * 0 + 0 ) ( 0 + 1 )* 0* 1* ) 
3. For the language accepted by A, A is the minimal DFA. 
4. A accepts all strings over { 0, 1 } of length atleast two. 
 

example

A. 1 and 3 only 
B. 2 and 4 only 
C. 2 and 3 only 
D. 3 and 4 only 

Solution : Statement 4 says, it will accept all strings of length atleast 2. But it accepts 0 which is of length 1. So, 4 is false. 
Statement 3 says that the DFA is minimal. We will check using the algorithm discussed above. 
P0 = { { q2 }, { q0, q1 } } 
P1 = { q2 }, { q0, q1 } }. Since, P0 = P1, P1 is the final DFA. q0 and q1 can be merged. So minimal DFA will have two states. Therefore, statement 3 is also false. 
So correct option is (D). 

This article has been contributed by Sonal Tuteja. 

 

Advantages:

Reduced Complexity: Minimizing a DFA reduces its complexity by eliminating redundant states and transitions. The resulting minimized DFA is typically smaller and simpler, making it easier to understand, analyze, and modify. Minimization improves the efficiency of executing the DFA and reduces the resources required for its implementation.

Optimal Space Utilization: A minimized DFA occupies less memory and storage space compared to the original DFA. By eliminating redundant states, the minimized DFA requires fewer resources to store and represent its states and transitions. This is advantageous when working with large DFAs or limited memory environments.

Improved Performance: Minimizing a DFA can significantly improve its performance in terms of speed and efficiency. With fewer states and transitions, the minimized DFA requires fewer computations and memory accesses, resulting in faster execution. This is particularly beneficial when processing large input strings or handling real-time applications.

Language Equivalence: Minimization ensures that the resulting DFA is language equivalent to the original DFA. That is, it recognizes the same language, accepting the same valid strings and rejecting the same invalid strings. Minimization preserves the language semantics while improving the DFA’s structure.

Disadvantages:

Increased Computational Complexity: Minimizing a DFA involves performing state equivalence calculations and merging equivalent states. The computational complexity of the minimization process can be significant, especially for large DFAs. As the DFA’s size grows, the time and computational resources required for minimization increase, making it computationally expensive in some cases.

Additional Design and Analysis Effort: Minimization requires additional design and analysis effort compared to working with the original DFA. Determining state equivalence and merging equivalent states often involves careful analysis of the DFA’s structure and transition patterns. This process can be time-consuming and error-prone, requiring attention to detail.

Loss of Readability: In some cases, the minimized DFA may become less readable and intuitive compared to the original DFA. The merging of equivalent states may result in complex state representations, making it more challenging to interpret the DFA’s behavior or understand its structure.

Limited to Deterministic Automata: Minimization techniques are applicable only to deterministic automata like DFAs. Non-deterministic automata, such as NFAs, cannot be directly minimized. Converting an NFA to a DFA before minimizing it adds an additional step and may lead to an increase in the DFA’s size.



Previous Article
Next Article

Similar Reads

Minimization of DFA using Myhill-Nerode Theorem
Minimization of DFA using Myhill-Nerode Theorem :Minimization of DFA is Required to obtain the minimal and equivalent version of any DFA which consists of minimum number of states possible. Myhill-Nerode theorem can be used to convert a DFA to its equivalent DFA with minimum no of states. This method of minimization is also called Table filling met
5 min read
DFA for accepting the language L = { anbm | n+m=even }
Design a deterministic finite automata(DFA) for accepting the language L =[Tex] {a^n b^{m} | m+n=even} [/Tex]For creating DFA for language, L = { a^n b^m ; n+m=even } use elementary mathematics, which says- even + even = even and odd + odd = even Examples: Input: a a b b // n = 2, m = 2, 2 + 2 = 4 (even) Output: ACCEPTED Input: a a a b b b b // n =
15 min read
DFA in LEX code which accepts even number of zeros and even number of ones
Lex is a computer program that generates lexical analyzers, which is commonly used with the YACC parser generator. Lex, originally written by Mike Lesk and Eric Schmidt and described in 1975, is the standard lexical analyzer generator on many Unix systems, and an equivalent tool is specified as part of the POSIX standard. Lex reads an input stream
6 min read
DFA for Strings not ending with "THE"
Problem - Accept Strings that not ending with substring "THE". Check if a given string is ending with "the" or not. The different forms of "the" which are avoided in the end of the string are: "THE", "ThE", "THe", "tHE", "thE", "The", "tHe" and "the" All those strings that are ending with any of the above mentioned forms of "the" are not accepted.
12 min read
DFA of a string with at least two 0’s and at least two 1’s
Problem - Draw deterministic finite automata (DFA) of a string with at least two 0’s and at least two 1’s. The first thing that come to mind after reading this question us that we count the number of 1's and 0's. Thereafter if they both are at least 2 the string is accepted else not accepted. But we do not have any concept of memory in a DFA so we
3 min read
Union process in DFA
Prerequisite - Designing finite automata To perform the union operation on two deterministic finite automata (DFAs), the following steps can be taken: Create a new DFA with a new set of states, consisting of all the states from both original DFAs.Define the initial state of the new DFA to be the tuple (q1, q2), where q1 and q2 are the initial state
5 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
Concatenation process in DFA
Prerequisite - Designing finite automata Designing a DFA for the set of string over {a, b} such that string of the language start with "a" and end with "b". There two desired language will be formed: L1 = {a, aab, aabab, .......} L2 = {b, bbab, bbabab, .......} In L1, starting element is "a" and in L2, ending element is b. State Transition Diagram
2 min read
Program to construct a DFA which accepts the language having all 'a' before all 'b'
Given a string S, the task is to design a Deterministic Finite Automata (DFA) for accepting the language L = {aNbM | N ≥ 0, M ≥ 0, N+M ≥ 1}. , i.e., a regular language L such that all 'a' occur before the first occurrence of 'b' {a, ab, aab, bb..., }. If the given string follows the given language L, then print “Accepted”. Otherwise, print “Not Acc
8 min read
Complementation process in DFA
Prerequisite – Design a Finite automata Suppose we have a DFA that is defined by ( Q, [Tex]\Sigma [/Tex], [Tex]\delta [/Tex], q0, F ) and it accepts the language L1. Then, the DFA which accepts the language L2 where L2 = ̅L1', will be defined as below: ( Q, [Tex]\Sigma[/Tex], [Tex]\delta[/Tex], q0, Q-F ) The complement of a DFA can be obtained by m
2 min read
DFA for accepting the language L = {an bm | n+m=odd}
Design a deterministic finite automata (DFA) for accepting the language [Tex]L = \{a^nb^m | \text{m+n=odd}\} [/Tex]For creating DFA for language L = {an bm | n+m=odd} use elementary mathematics which says, odd + even = odd, and even+odd = odd Examples: Input: a a b b b Output: ACCEPTED // n = 2, m = 3, 2 + 3 = 5 (odd) Input: a a a b b b Output: NOT
14 min read
Cross Product Operation in DFA
Prerequisite: Designing finite automata Let’s understand the cross product operation in Deterministic Finite Automata (DFA) with help of the below example- Designing a DFA for the set of string over {a, b} such that string of the language contains even number of a's and b's then desired language will be like below- L = {&epsilon;, aa, bb, abab, aab
2 min read
DFA of a string in which 3rd symbol from RHS is ‘a’
Prerequisite – Finite Automata Introduction, DFA of a string in which 2nd symbol from RHS is ‘a’ Problem – Draw deterministic finite automata (DFA) of the language containing the set of all strings over {a, b} in which the 3rd symbol from RHS is ‘a’. The strings in which 3rd last symbol is “a” are: aaa, aab, aaab, aaaa, aabbaaa, bbbaba etc The DFA
2 min read
Program to construct a DFA which accept the language L = {a<sup>n</sup>b<sup>m</sup> | n mod 2=0, m&ge;1}
Prerequisite - Finite Automata Introduction Problem: Design a deterministic finite automata (DFA) for accepting the language [Tex]L = \{a^nb^m | n\mod 2=0, m \geq 1\}[/Tex] Regular expression for above language L is, L = (aa)*.b+ Examples: Input: a a b b b Output: ACCEPTED // n = 2 (even) m=3 (&gt;=1) Input: a a a b b b Output: NOT ACCEPTED // n =
10 min read
DFA for strings not containing consecutive two a's and starting with 'a'
Prerequisite - Finite Automata Introduction Problem: Construct deterministic finite automata (DFA) for strings not containing consecutive two a's and starting with a. Explanation: Accept Strings that not contain consecutive two a's. Check if a given string contain consecutive two a's or not. The any occurrence of (b-z) should not affect the scenari
11 min read
Construct DFA with Σ = {0, 1} and Accept All String of Length at Least 2
Construct a DFA for a language accepting strings of length at least two, over input alphabets Σ = {0,1}. So that means in DFA, language consists of a string of length of at least 2 and can be greater than two. That means if DFA got the string of Length 0 or 1 then it will not accept it. A string of length zero means when the machine doesn't get any
5 min read
Construct DFA which interpreted as binary number is divisible by 2, 3, 4
Prerequisite: Finite Automata Introduction, Designing Finite Automata Problem-1: Construct DFA, which accepts set of all strings over {0, 1} which interpreted as a binary number is divisible by 2. Explanation: Consider the following inputs, {0, 01, 10, 11, 100, 101, 110........} The state transition diagram of the language will be like this: In thi
4 min read
Construct a DFA which accept the language L = {a<sup>n</sup>b<sup>m</sup> | n &gt; =1, (m) mod 3 = 1}
Problem: Construct a DFA which accept the language L = {anbm | n &gt; =1, (m) mod 3 = 1}. Explanation: For constructing the DFA, the following things to be remember: [Tex](element)^*[/Tex] which means any no of elements, and [Tex](element)^+[/Tex] = [Tex](element).(element)^*[/Tex] which means any no of elements greater than 1. Examples: Input: a a
9 min read
DFA (Recognizer) for valid Pascal identifiers
Problem - Implement a recognizer for pascal identifiers based on a DFA that accepts strings belonging to the definition of the language of the same. Here is a regular definition for the set of Pascal identifiers that are defined as the set of strings of letters and digits beginning with a letter. letter : A | B | . . . | Z | a | b | . . . | z digit
6 min read
Program to build a DFA that accepts strings starting and ending with different character
Prerequisite: Deterministic Finite Automata Given a string, str consists of characters 'a' &amp; 'b'. The task is to check whether string str starts and ends with different characters or not. If it does, print 'YES' with state transitions, else print 'NO'. Examples: Input: ababab Output: YES Explanation: The string "ababab" is starting with 'a' and
12 min read
Program to build a DFA to accept strings that start and end with same character
Given a string consisting of characters a and b, check if the string starts and ends with the same character or not. If it does, print 'Yes' else print 'No'.Examples: Input: str = "abbaaba" Output: Yes Explanation: The given input string starts and ends with same character 'a' So the states of the below DFA Machine will be q0-&gt;q1-&gt;q2-&gt;q2-
12 min read
Difference between DFA and NFA
1. DFA: DFA refers to Deterministic Finite Automaton. A Finite Automata(FA) is said to be deterministic if corresponding to an input symbol, there is a single resultant state i.e. there is only one transition. A deterministic finite automata is set of five tuples represented as, Where, Q: A non-empty finite set of states in the finite control(qo, q
3 min read
DFA for exactly one of a and at least one of b
Deterministic Finite Automata (DFA) is defined as an abstract mathematical concept which is used to solve various specific problems in different software and hardware.In this type of problems we have some given parameters according to which we should design DFA. In this article,two instructions are given: DFA should have one of a DFA should have at
2 min read
Design a DFA that every 00 is immediately followed by 1
DFA machines are designed to accept the specific kind of input whose output is generated by the transition of input alphabet from each state. Approach : In this situation, strings all strings are acceptable except more than 3 zeros. In this kind of string no three continuous zeros are acceptable. Create initial state and start with minimum length o
2 min read
Build a DFA to accept a binary string containing "01" i times and "1" 2j times
Given a binary string str, the task is to build a DFA that accepts given binary string if it contains "01" i times and "1" 2j times, i.e., [Tex]L={(01)^i (1)^{2j} \text{ where }i\geq1\text{ and }j\geq1} [/Tex] Examples: Input: str = "011111" Output: Accepted Explanation: The string follows the language as: (01)1(1)2*2 Input: str = "01111" Output: N
9 min read
DFA that recognizes number of 0 is multiple of 3 on input {0,1}
Finite Automata is known as a finite state machine that are acceptable otherwise not acceptable. on the input alphabet '0' and 1'. Determine the initial state.The transition occurs on every input alphabet.Determine whether the self-loop should apply or not.Mark's final state. Designing DFA step by step :Step-1: Make initial state “A” then it is the
5 min read
DFA that begins with 'a' but does not contain substring 'aab'
Prerequisite: Introduction to Deterministic Finite Automata Construct a DFA that accepts string str starting with input alphabet 'a' but does not contain 'aab' as a substring over input {a, b}. Examples: Input: str = "babba" Output: Not Accepted Explanation: The given string doesn't start with 'a'. Input: str = "abbaaaaa" Output: Accepted Explanati
10 min read
Design a DFA that accepts a string containing 3 a's and 3 b's
Problem Statement: Design a Definite Finite Automata for accepting the permutation of Three a's and Three b's over the input {a, b} Input: S = "aaabbb" Output: Accepted Explanation: The input has three a and three b. Input: S = "abababa" Output: Accepted Explanation: The input has three a and three b. To design a DFA we need to check the input char
15+ min read
Implementing DFA for no runs of length less than 4 for input (a,b)
DFA or Deterministic Finite Automata is a finite state machine, in which on every input alphabet a transition is done from one state to another state according to set of defined rules as per the need of string acceptance.In this particular problem, runs of length is the factor to think about.The input alphabets are {a, b}. No runs of length less th
15 min read
DFA of Regular Language L ={w ∈ {a,b}* : Na(w) mod 3 > Nb(w) mod 3}
In this article, we will design the Deterministic Finite Automata of the Regular Language L ={w ∈ {a, b}* : Na(w) mod 3 > Nb(w) mod 3}. Regular Expression can be anything from a terminal symbol, ∅, to union of two regular expressions (R1 + R2 ), their intersection (R1 + R2) or the regular expression’s closure (R1*) or a ∈ Σ, where Σ is the finite s
2 min read
Article Tags :