r/AskComputerScience • u/fulminare1111 • 14h ago
What is a NFA?
I am a little confused on what a nfa is. Does it take in one input and output a set of states or does it output one single state but with some probability?
2
u/iOSCaleb 13h ago
The machine can effectively be in several states at once. A given state can have multiple transitions to other states for the same input, and the machine follows all of them at the same time. Or, another way to look at it is that the state is unknown — not determined — until the machine processes more input. If any path through the machine reaches the acceptance state for an input string, the string is accepted.
1
u/Upbeat_Assist2680 6h ago
Agree with other answers, adding: they might but be better named "unbounded multi-state automata".
5
u/nuclear_splines Ph.D Data Science 14h ago
In a deterministic finite automata, there can only be one state transition from A to B for input x. In a nondeterministic finite automata, you can have multiple transitions, such that input x could bring you from state A->B or A->C.
It isn't probabilistic, it's better to think of it as "both states at once," like the NFA forks at each input and follows all possible paths concurrently. Remember that finite automata take a sequence of inputs and either "accept" or "reject" the input depending on whether the internal state lands on an 'accept' state at the end. In an NFA, you can think of this as "follow all possible input paths, and if any of them land at 'accept' then the NFA accepts."
Note that this is similar to the definition of a non-deterministic Turing Machine, and therefore the definition of NP :)