# Convert regular expression to DFA

How do you construct a DFA from a language that has a + sign? e.g. $L = \{(a+b)\}*$

## migrated from cstheory.stackexchange.comAug 4 '13 at 19:03

This question came from our site for theoretical computer scientists and researchers in related fields.

• Did you mean the language $(a+b)*$, rather than $\{(a+b)\}*$? – D.W. Aug 5 '13 at 4:13
• There is a standard construction; have you read any material on the topic before posting here? What have you tried? – Raphael Aug 5 '13 at 8:26

In this case + stands for the OR-operation. So the automaton is indifferent using an $a$ transition or a $b$ transition.

It's sufficient to construct an automaton with one state which is initial and final state and having one transition labeled with a, b.

• If your alphabet is larger than just $\{a,b\}$, you should also add a garbage state with all letters other than $a$ and $b$ making a transition from the main state to the garbage state and all letters (including $a$ and $b$) sending the garbage state to itself. – minar Aug 6 '13 at 11:39

It looks like your language is specified as a regular expression. (Regular expressions are allowed to contain the + and * operators.)

So, in general, you can use the following procedure:

1. Convert the regular expression to a NFA. There are standard methods for this; for instance, Thompson's algorithm is perhaps the best-known. See Russ Cox's explanation for a great tutorial.

2. Convert the NFA to a DFA. Again, there are standard algorithms for this task as well: namely, the subset construction, where you have one state in the DFA for each possible subset of states of the NFA.

All of this should be covered in standard sources, e.g., Wikipedia or an automata theory book. In the future, please go check those standard sources and do a bit of research on your own before asking here, to comply with this sites' expectations.