Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Complementation Process in DFA



In this chapter, we will first provide a brief introduction on deterministic finite automata (DFA) before moving on to explain the complementation in DFA with steps and examples.

Complementation plays a great role in compiler design and other applications. We will highlight some important points on complemented DFAs.

Deterministic Finite Automata

Before understanding the complementation of DFA, we must recap the concept of DFA a little. In the following table we will see the components of DFA in automata.

Components Description
States A DFA is a set of states that represent the various configurations an automaton can be in at any given time.
Alphabet The input symbols that a DFA can process, such as in a binary DFA, are represented by the alphabet {0, 1}.
Transition Function The function outlines the DFA's transition from one state to another upon reading an input symbol, specifying one next state for each state and input symbol.
Initial State This is the state in which the DFA begins processing input.
Final State Accepting states refer to the states where the DFA will be if it has successfully recognized a string in its language.

The finite automata, more precisely a DFA recognizes or accepts a string, starting from the initial state and processing the string symbol by symbol, then it ends up in one of its final states after consuming all input. And the set of all strings that is accepted by a DFA is called the language of the DFA. It is important to understand the language in DFA on which the complementation is works on. Let us understand the complementation here.

Complement Language

The complement of a language L, denoted as Lc. It is the set of all strings over the same alphabet that are not in L. (If Σ* represents all possible strings over the alphabet Σ, then Lc = Σ* − L).

Let us understand through an example. If L is the language of all binary strings ending in '0' over the alphabet {0, 1}, then Lc is the language of all binary strings ending with '1', along with an empty string.

Now let us see the steps involved to complement a DFA that will accept the complemented language.

Complementation Steps for DFA

Suppose we have a DFA,

$$\mathrm{M \:=\: (Q,\: \Sigma,\: \delta,\: q0,\: F)}$$

Its complement DFA,

$$\mathrm{M' \:=\: (Q,\: \Sigma,\: \delta,\: q0,\: F')}$$

Here F' = Q - F. So, it is clear that, the complement DFA has the same states, alphabet, transition function, and initial state as the original DFA, but the set of final states is replaced with its complement within the set of all states.

The steps are simple −

  • The first step is to identify all states in the original DFA that are not final states.
  • Swap the final and non-final states of the original DFA, so that all non-final states of the original DFA are included in the new DFA.
  • The transition function remains unchanged in the original DFA, preserving the automaton's structure but altering which states are accepted.

Examples of Complementation in DFA

Let us see some examples. Consider the first DFA, D1

Complementation in DFA

The complemented DFA, D1c is as follows.

Complementation in DFA D1

See another example, where L1: that is the set of all strings over {0, 1} starting with '0'., for example {0, 00, 01, 000, 001, 010, 011,…} the DFA is like below −

Complementation in DFA L1

Now the complemented machine, L2: that is the set of all strings over {0, 1} not starting with '0'. L2 = { ε, 1, 10, 11, 101, 100, 110, ...}, the DFA is looking like:

Complementation in DFA L2

Important Facts on DFA

Make a note of the following important facts on DFA −

  • Enables the implementation of the "not" operator in regular expressions, for complex pattern matching by allowing the exclusion of certain patterns.
  • It proves regular languages are closed under complementation, also helps to prove other closure properties like intersection and set difference.

Conclusion

In finite automata, closure properties are important factors. We know that the regular expressions are closed under complementation. Here we discussed the complementation concepts for DFA with steps and two different examples in action.

Advertisements