Lecture 4 - DFA/NFA/RegEx equivalence and grammars

Date Pre-lecture slides Post-lecture scribbles Lecture recording
September 05 2023 Lecture 4 - DFA/NFA/RegEx equivalence and grammars Lecture 4 - DFA/NFA/RegEx equivalence and grammars Lecture 4 - DFA/NFA/RegEx equivalence and grammars


Equivalence diagram

1. DFA → NFA

All DFAs can represent any languages that are represented by NFAs. All DFAs by definition are NFAs.

2. NFA → DFA

Consider any non-deterministic finite automata (NFA) N = $(Q, \Sigma, \delta, s, A)$ where :

• Q is a finite set whose elements are called states,
• $\Sigma$ is a finite set called the input alphabet,
• $\delta$ : Q × $\Sigma$ $\cup$ {$\epsilon$} → P(Q) is the transition function (here P(Q) is the power set of Q),
• s ∈ Q is the start state,
• A ⊆ Q is the set of accepting/final states.

$\delta$(q, a) for a $\in$ $\Sigma$ $\cup$ {$\epsilon$} is a subset of Q — a set of states.

An equivalent DFA D = $(Q’, \Sigma, \delta’, s’, A’)$ can be constructed using the Subset State Construction such that:

• $Q’ = P(Q)$
• \(s' = \epsilon reach(s) = \delta^{*}(s,\epsilon)\)
• $A’ = { X \subseteq Q | X \cap A \neq \emptyset}$
• $\delta’(X, a) = \bigcup\limits_{q \in X} \delta^{*} (q,a) for each X \subseteq Q , a \in \Sigma$

3. Regular Expressions → NFA

Any regular expression can be converted to an NFA using the Thompson’s Algorithm as follows:

Union Concatenation Kleene star

Example: Construct a NFA for (101 + 010)

4. DFA → Regular Expressions

A Regular expression can be obtained from a DFA using two methods.

A. State Removal Method

If q1 = $\delta$(q0, x) and q2 = $\delta$(q1, y), then q2 = $\delta$(q1, y) = $\delta$($\delta$(q0, x), y) = $\delta$(q0, xy). This way, we can eliminate state q1.

State removal method illustration


State removal method example

Therefore, the resulting regular expression for the given DFA is $(01 + (1 + 00)(10)^{∗}(0 + 11))^{∗}$

B. Algebraic Method

This method involves treating transition functions as algebraic expressions. That is, $q_1 = \delta(q_0, x)$ can be written as $q_1 = q_0x$ and the resulting expressions can be solved for the accepting state.

Example: Convert the following DFA to regular expression using Algebraic Method.

Algebraic method example

Writing down transitions as algebraic functions :
• $q_{0} = \epsilon + q_{1}1 + q_{2}0$
• $q_{1} = q_{0}0$
• $q_{2} = q_{0}1$
• $q_{3} = q_{1}0 + q_{2}1 + q_{3}(0 + 1)$

Now we simple solve the system of equations for $q_{0}$:
• $q_{0} = \epsilon + q_{1}1 + q_{2}0$
=> $q_{0} = \epsilon + q_{0}01 + q_{0}10$
=> $q_{0} = \epsilon + q_{0}(01 + 10)$

Make use of Theorem (Arden’s Theorem) that states $R = Q + RP = QP^{∗}$

=> $q_{0} = \epsilon(01 + 10)^{∗} = (01 + 10)^{∗}$

5. NFA → Regular Expressions

Any NFA can be converted to regular expressions using the same two methods as listed above :

• Algebraic Method - Treat transition functions as algebraic functions and solve for accepting state.

• State Removal Method - Normalize the NFA to have an isolated starting and ending state and then follow the same process as listed above.


State removal method illustration- NFA pt1 State removal method illustration- NFA pt2

6. Regular Expressions → DFA

To convert Regular Expressions to DFA we can make use of the Brzozowski derivative, where ($u^{−1}$ S) of a set S of strings and a string u is the set of strings obtainable from a string in S by cutting of the prefix u.

Example: To construct language $R = (ab + c)^{*}$


$q_0 = \epsilon^{-1}R = (ab+c)^{*}$
$b(ab + c)^{*}$
$(ab + c)^{*}$
$q_1 = b(ab + c)^{*}$
$(ab + c)^{*}$
$q_2 = \emptyset$

Additional Resources


Sandhya Perumenki