Converting a Regular Expression to an equivalent NFA

A regular expression expresses a language that can be modelled by a NFA. This article lists the procedure to follow to convert a regular expression to an equivalent NFA. A regular expression can be one of the following 6 cases.

\emptyset

This expression means the empty set. No string is in the language of this expression. An equivalent NFA will be

Rendered by QuickLaTeX.com

\epsilon

This expression means the empty string. The difference between the empty string and the empty set is discussed in detail here. An equivalent NFA which accepts the empty string, \epsilon will be

Rendered by QuickLaTeX.com

a

This expression means a single symbol in the alphabet \Sigma. An equivalent NFA which accepts the string, a will be

Rendered by QuickLaTeX.com

R_1 \cup R_2

This expression is the union of two regular expressions. The NFAs for R_1 and R_2 are shown in two different colors. An equivalent NFA which accepts the union of the two expressions is given below.

Rendered by QuickLaTeX.com

R_1 \cdot R_2

This expression is the concatenation of two regular expressions. The NFAs for R_1 and R_2 are shown in two different colors. An equivalent NFA which accepts the concatenation of the two expressions is given below.

Rendered by QuickLaTeX.com

R_1^*

This expression is the Kleene star of a regular expression. The NFA for R_1 is shown in color. An equivalent NFA which accepts the Kleene star of this expression is given below

Rendered by QuickLaTeX.com

Example

Here is an example showing how to build an NFA for the following complex expression.

    \begin{equation*} (aab^*b \cup b)^*(b \cup bab) \end{equation*}

The changes in the NFA for each expression are indicated with a color.

a

Rendered by QuickLaTeX.com

aa

Rendered by QuickLaTeX.com

aab^*

Rendered by QuickLaTeX.com

aab^*b

Rendered by QuickLaTeX.com

aab^*b \cup b

Rendered by QuickLaTeX.com

(aab^*b \cup b)^*

Rendered by QuickLaTeX.com

This can be simplified to

Rendered by QuickLaTeX.com

b

Rendered by QuickLaTeX.com

ba

Rendered by QuickLaTeX.com

bab

Rendered by QuickLaTeX.com

b \cup bab

Rendered by QuickLaTeX.com

This can be simplified to

Rendered by QuickLaTeX.com

Concatenating the two simplifications, the final NFA is given below

Rendered by QuickLaTeX.com


References

Leave a Reply

Your email address will not be published. Required fields are marked *