How do you draw a DFA from a regular expression?

11.9k Views Asked by At

I want to draw a DFA from the below language:

The set of strings in $\{a, b\}$ where every $a$ is immediately followed by $b$

I can write the regular expression for this language as so:

$$((b^*)(ab)(b^*))^*$$

How do I draw the DFA for this expression?

2

There are 2 best solutions below

2
On BEST ANSWER

I hope it can help you

Language consist of :

  • $\epsilon$
  • strings of just b's
  • and strings such that every a is immediately followed by b $$L=\{\epsilon,b,bb,bbb,...,ab,abb,....,bab,bbababb,.... \}$$ Regular expression: $(b^*\,ab\, b^*)^*+b^*$

DFA that accepts L :

enter image description here

1
On

You can do it on-line using https://cyberzhg.github.io/toolbox/nfa2dfa easily. For your particular example, it gives

enter image description here

You can find a more precise algorithm in the chapter 2 of Modern Compiler Implementation in C, which includes this figure:

enter image description here

How you convert your obtained NFA into a DFA is then fairly standard.