Search code examples
finite-automatadfanfa

How to determine if my NFA is correct?


The obvious choice is to exhaust all possible inputs. I think I did. But I am not very sure whether it's valid and I didn't break any rules of non-deterministic finite automata.

My NFA is given by: (ab u aab u aba)* and below is my diagram.

enter image description here

Have I missed something?


Solution

  • You aren't missing anything, but the NFA could be simplified considerably by collapsing paths and eliminating λ-rules. In order to determine whether your NFA decides the language denoted by the regular expression, you can argue informally by chasing states in the transition graph. In order to talk about the NFA, I'll use the following definition of the δ function with final states {q0,q3,q4} and initial state q0

    • δ(q0,a) = {q1,q2}
    • δ(q1,a) = {q2}
    • δ(q2,b) = {q3}
    • δ(q3,a) = {q4}
    • δ(q3,λ) = {q0}
    • δ(q4,λ) = {q-}

    The goal is to show that the NFA accepts precisely the language (ab U aab U aba)*. To this end, we can consider the strings accepted by beginning with λ at q0 and exhausting all possible transitions through the graph, recording the strings built by concatenating the symbols transitioned on, and noting whether such a string is accepted or not. Paths in the graph indicate concatenation; final states indicate acceptance or disjunction; loops indicate Kleene star.

    From q0 and λ we can transition on a to q1 or q2. On q1 and a we can transition to q2. Hence, on q2 we have either a or aa and nothing else. From q2 and a or aa we can transition to q3 on b. Hence, at q3 we have either ab or aab and nothing else. From q3 and ab or aab we can transition to q0 on λ or q4 on a. Hence, on q3 and ab or aab we have either ab or aab or aba and nothing else. Finally, on q4 and aba we can transition to q0 on λ. Since we have ab or aab or aba and transitioned to the start state, meaning our derivation can repeat itself zero or more times, and we have exhausted the possible transitions, we conclude that the NFA decides the Kleene closure of ab or aab or aba.

    There are more formal methods of showing that a given NFA decides a language. But the easiest way is to exhaust all possible paths through the NFA, introducing Kleene closures on cycles. An example of a formal method would be to convert the NFA to a regular expression, then derive the equality of the obtained expression and the target expression axiomatically. This is largely unnecessary.

    You probably have done precisely what I just wrote, however, making this entire post unnecessary. If not, I hope it shows the kind of informal reasoning you can use to convince yourself that an NFA decides a language.