0

It feels like this should be easier than it is, but I am having an issue with it. Here is what is asked:

Construct a NFA for the following language L = {ab,ba}*. So, I understand that I can have any combination of ab or ba in the string, but do I need a dead state if say I get two a's in a row, or does it just start over? Here are the two graphs that I have: g1 g2

Are either of these correct? And since they are NFAs vs DFA do I need a lambda edge somewhere on here?

Edit: Would this third one be correct because I need two final states? g3

Nick
  • 25
  • 8
  • 1
    All of your examples are DFAs (and so are NFAs trivially). Your first example is not correct, because it accepts strings outside the language (such as `aab`). Your second and third examples are almost correct but not minimal. Neither DFA accepts the empty string, which is in the language. A minimal DFA with 3 states (or 4 with an explicit dead state) is possible. States `{q1, q2, q3}`, `q1` being the starting and accepting state. Transitions: `q1,a,q2, q1,b,q3, q2,b,q1, q3,a,q1`. – Welbog Sep 26 '18 at 13:14

1 Answers1

1

If you're making an NFA, you don't need dead states; you can just let the NFA crash. DFAs probably do need dead states for completeness, depending on your definitions.

Here is an NFA (q0 is the initial state and the only accepting state):

         b
      +------+
      |      |
      V  a   |    
  +->q0 ---> q1
  |   |
a |   | b
  |   V
  +--q2

To make this a DFA you can add a dead state q3 and make all transitions not otherwise defined above terminate in q3.

Patrick87
  • 27,682
  • 3
  • 38
  • 73