The Wayback Machine - https://web.archive.org/web/20240607081828/https://www.geeksforgeeks.org/complementation-process-in-dfa/
Open In App

Complementation process in DFA

Last Updated : 26 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Design a Finite automata 
Suppose we have a DFA that is defined by ( Q, \Sigma  , \delta  , 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, \Sigma, \delta, q0, Q-F )



The complement of a DFA can be obtained by making the non-final states as final states and vice-versa. The language accepted by the complemented DFA L2 is the complement of the language L1. 

Example-1: 
L1: set of all strings over {a, b} of even length 
 

L1 = {\epsilon, ab, aa, abaa, aaba, ....} 


L2: set of all strings over {a, b} of odd length 
 

L2 = { a, b, aab, aaa, bba, bbb, ...} 


Here, we can see that L2 = Ė…L1 

Lets first draw the DFA for L1 that accepts the strings of even length. 

 



Now, for designing the DFA for L2, we just need to complement the above DFA. We will change the non-final states as final state and the final states as non-final states. 

 



This is our required complemented DFA. 

Example-2: 
L1: set of all strings over {a, b} starting with ‘a’. 
 

L1 ={ a, ab, aa, aba, aaa, aab, ..} 


L2: set of all strings over {a, b} not starting with ‘a’. 
 

L2 ={ \epsilon, b, ba, bb, bab, baa, bba, ...} 


Here, we can see that L2 = Ė…L1 

Lets first draw the DFA for L1 that accepts the set of all strings over {a, b} starting with ‘a’ 

 



Now, for designing the DFA for L2, we just need to complement the above DFA. We will change the non-final states as final state and the final states as non-final states. 

 



This is our required complemented DFA that accepts the strings that are not starting with ‘a’. 
Note: Regular languages are closed under complement (i.e Complement of regular language will also be regular).
 


Previous Article
Next Article

Similar Reads

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
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
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
Program to construct DFA for Regular Expression C( A + B)+
Given a string S, the task is to design a Deterministic Finite Automata (DFA) for accepting the language L = C (A + B)+. If the given string is accepted by DFA, then print "Yes". Otherwise, print "No". Examples: Input: S = "CABABABAB"Output: YesExplanation: The given string is of the form C(A + B)+ as the first character is C and it is followed by
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
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
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
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