1

I am trying to create a DFA and a regex for this kind of exercise:

$A = \{w ∈ \{0, 1\}^* |\text{length of w is a multiple of 2 or 3}\}$. I tried to do one for $2$ and one for $3$ and then combine them, but it didn't seem to work cause I miss some cases for example $6,7$ or so. Any help would be gratefully received :D

Raphael
  • 72,336
  • 29
  • 179
  • 389
user44849
  • 19
  • 1
  • 1
  • 2
  • 3
    How did you try that? The standard constructions should work along the route you outline. (I'm sure we have a duplicate somewhere...) – Raphael Jan 13 '16 at 15:16

3 Answers3

0

Creating a state machine for each and combining the two is not a bad idea. To create a state machine accepting words having length N you can have each state represent the current length mod N.

After creating the two machines you can add a state having two epsilon transitions to the starting states of both machines. This gives a NFA accepting your language.

In a final stage you use the subset construction algorithm to convert the NFA you got into a DFA.

mrk
  • 3,688
  • 22
  • 35
  • The second paragraph references the standard constructions for getting an NFA for the union of two languages you already have automata for. It's part of the proof for the fact that regular expressions and finite automata are equally expressive. 2) Isn't it called powerset construction?
  • – Raphael Jan 13 '16 at 15:18
  • It's also known as subset construction (check the Wikipedia article). – mrk Jan 13 '16 at 16:59
  • If you have two deterministic automata the product-construction (usually used for intersection) also works directly for the union of the languages: just change the accepting states. – Hendrik Jan Jan 13 '16 at 23:04