0

I've made the following diagram to accept a, ad, abc, abd but I don't it to accept e, abcd, how can I limit that?

State Diagram

Updated I modified the diagram in another attempt:

State Diagram v2

Django
  • 1
  • 1
  • 3

3 Answers3

2

Your automaton has loops so it accepts an infinite language.

For finite languages $\{w_1, \dots, w_n\}$, it's easy to write them as regular expression

$\qquad w_1 \mid \ldots \mid w_k$

and apply Thompson's construction. If the resulting automaton is too ugly for your taste, determinize and minimize according to the canonical textbooks.

Warning: Determinizing automata for finite languages can blow up automaton size exponentially.

Note how this approach scales neatly to more concise representations of finite languages and even infinite languages -- all you need is a regular expression. Or any other formalism equivalent to finite automata, as the proofs of equivalence are usually constructive.

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • I need to do it without regular expressions and I'm not familiar with Thompson's Construction. I've updated the question with another diagram which I think could be the correct answer now. – Django Apr 16 '16 at 11:33
  • 1
  • Thompson's construction is elementary; you should understand it from the Wikipedia article. 2) That one still has a loop, and it still accepts $abcd$. You can easily check that yourself. (Maybe we need to adjust your expectations: this is not a homework-solving or -grading site. I gave you a structured approach to solve your problem -- the work is yours.)
  • – Raphael Apr 16 '16 at 11:35
  • This is not a homework assignment, it is an exercise I found and I'm unable to solve it correctly, I already mentioned that I don't want to use regular expressions because I haven't studied regular expressions yet. Thompson's Construction technique is not what I'm looking for because I'm not trying to transform regular expressions into NFAs. I'm just trying to design an NFA that accepts the specified strings. I'm trying to understand what is it that I'm doing wrong or what is it that I am missing so I can do it right if you wanna help me with that I'll be grateful. – Django Apr 16 '16 at 11:42
  • As I said: don't create loops. Don't try to create a small automaton. Don't try to be clever. – Raphael Apr 16 '16 at 12:36
  • 3
    (By the way, "I don't want to learn about X because I have not yet learned about X" is a weird way to argue for a learner.) – Raphael Apr 16 '16 at 12:37
  • I strongly disagree that Thompson's construction from a regular expression is the easiest way to produce an automaton for a finite language. It's easy to produce an NFA that accepts a single string, so produce a bunch of those and then add a new start state that has $\varepsilon$-transitions to each of their start states. – David Richerby Apr 16 '16 at 16:14
  • @DavidRicherby Isn't that exactly what Thompson's construction does? (Okay, maybe not if you apply binary alternative many times, but who does that?) That said, even if it is not strictly the easiest construction it's a structured approach that scales. – Raphael Apr 16 '16 at 16:24
  • @Raphael You're right. I misremembered Thompson as using a more complex construction for concatenation that would have introduced a whole pile of epsilons. – David Richerby Apr 16 '16 at 17:30
  • @DavidRicherby Right, there are probably different flavors. The one with all the epsilons is not what you want to use here. – Raphael Apr 16 '16 at 18:27