6

So I am learning about DFA and NFA, and I need some clarification for it.

DFA

  • accept empty set
  • transition for every element in the alphabet
  • path are deterministic

NFA

  • accept the empty set and empty string
  • path are not deterministic

My question is does NFA need a transition for every element in the alphabet? If not, then let say the alphabet is {0. 1} and I am at a state without the transition for 1, do I go to the empty state or something?

Raphael
  • 73,212
  • 30
  • 182
  • 400
holidayeveryday
  • 61
  • 1
  • 1
  • 2

2 Answers2

12

In a DFA, if you are in state $p$ and see an input character $c$, one of three things may happen:

  1. You can consume that character (i.e., read it) and change to state $q$ ($q$ may be $p$ or not).
  2. There may not be a move defined for the pair $(p, c)$ in which case the DFA halts and rejects the input string.
  3. If the DFA is in a final state after having read all the input, it accepts the input, otherwise it rejects the input.

For an NFA, you have more possibilities:

  1. In state $p$ with input $c$ you can consume the input and change to several states $q_1, q_2, \dotsc$ .
  2. In state $p$ you can elect not to consume the input and change to several states $q_1, q_2, \dotsc$. This is called an epsilon move. In essence, your machine may change state without reading any input.
  3. As with a DFA, there may not be any move defined for the pair $(p, c)$ or $(p, \epsilon)$ in which case the NFA halts that branch of execution.
  4. If the NFA is in a final state in any particular branch of its execution and has consumed all the input, it accepts the input. If it hasn't reached any accept state after having read all the input, it rejects.

In either a DFA or an NFA, you don't need to have moves defined for all possible (state, character) pairs. If you're in state $p$ and there is no move defined for an input character, the machine (or that branch) halts and rejects.

Some people don't like this behavior and complete the automaton by creating what you apparently call an empty state and defining transitions to that state on those missing inputs. Once you're in that state (also known as a dead or error state), you never leave, no matter what the input is.

Rick Decker
  • 15,016
  • 5
  • 43
  • 54
3

No, NFAs can have any number of transitions for a given symbol1 from a state. If the NFA gets into the situation where the current symbol from the input has no transition from the current state, then the current path fails. If every possible path fails (in this way, or if it fails to reach an accept state at the end of the input) the NFA rejects the input.

  1. Any sensible number of course; being an integer in the range 0 to the number of states inclusive.
Luke Mathieson
  • 18,373
  • 4
  • 60
  • 87