1.1. Non-Deterministic Finite Acceptor¶
1.1.1. Non-Deterministic Finite Acceptor (1)¶
Define a NFA (or NDFA) as (Q,Σ,δ,q0,F) where
Q is a finite set of states
Σ is the input alphabet (a finite set)
q0 is the initial state (q0∈Q)
F⊆Q is a set of final states
δ:Q×(Σ∪{λ})→2Q (2Q here means the power set of Q)
<<Hmmm… How is this different from a DFA?>>
1.1.2. Non-Deterministic Finite Acceptor (2)¶
The specific difference from a DFA is that, while the result of δ for the DFA is some state q∈Q, the result of δ for the NFA is any subset of Q.
Transitions to a null subset is a failed path.Non-deterministic means that it allows choices. From a state on input b, δ might include transitions to more than one state.
Another difference:We allow λ transitions (a free ride to another state).
1.1.3. NFA Example 1¶
q0q1q3q2abbaaIn this example, δ(q0,a)= << ?? >>.(So, δ is no longer meets the mathematical definition of a function!)Hopefully this one is easy to understand: Two disjoint paths, effectively giving us the union of two languages: L= << ?? >>.
1.1.4. NFA Example 2¶
L={(ab)n∣n>0}∪{anb∣n>0}.
q0q1q3q5q2q4q6λabbaaλλA simple “go this way or go the other way”.Unfortunately, they are not always so simple to understand!
1.1.5. Accepting a String¶
Definition: qj∈δ∗(qi,w) if/only if there exists some walk from qi to qj labeled w.
From previous example:δ∗(q0,ab)= << ?? >>.δ∗(q0,aba)= << ?? >>.For an NFA M, L(M)={w∈Σ∗∣δ∗(q0,w)∩F≠∅}. << What does this mean? >>
NFA accepts a string if it completes processing in a final state. However for an NFA, the string is accepted if any processing path gets us to end in a final state. It does not matter that there are paths where w can go wrong. What matters is that there is at least one way for w to be right.
1.1.6. Why nondeterminism?¶
It makes it “easier” to describe a FA.<< What might “easier” mean? >>From a performance point of view, to determine if a string is accepted can take a LONG time to try out all possibilities. But, all that we care about right now is existance, not performance.
Hypothesis: Nondeterminism allows us to accept more languages.
1.1.7. Which is more powerful?¶
q0q2q1babaCan this NFA be converted to a DFA?
q0q1,q2q0,q2aba
1.1.8. Key Question¶
Does non-determinism increase the collection of languages that can be accepted? That is, can any language be accepted by an NFA that has no DFA that accepts it?
Here is a bit of intution that might give some insight:
Nondeterminism gives branches. If we are trying to create a non-determinism simulator in a computer, we can simulate it by alternating between all of the branches, pushing each branch forward by a step. This will eventually terminate.
1.1.9. Key Theorem¶
Theorem: Given an NFA MN=(QN,Σ,δN,q0,FN), there exists a DFA MD=(QD,Σ,δD,q0,FD) such that L(MN)=L(MD).
1.1.10. Class(DFA) == Class(NFA) Proof¶
We can use an algorithm to convert MN to MD.
QD=2QN << What does this mean? How big is this set of states? >>
[Right here, this is what I consider the key insight. Given a state in MN and a symbol ∈Σ, you can get to some subset of the states in MN. Consider THAT to be a state in MD.]
FD={Q∈QD∣∃ qi∈Q with qi∈FN} << What does this mean?? >>
δD:QD×Σ→QD << What does this mean?? >>
Of course this begs the question: HOW?
1.1.11. Algorithm to construct MD (1)¶
Start state is {q0}∪closure(q0)
What does closure(q) mean?
The set of states reachable from q with λ transitions.
1.1.12. Algorithm to construct MD (2)¶
Start state is {q0}∪closure(q0)
While missing a transition in δD:
Choose a state A={qi,qj,...,qk} with missing edge for a∈Σ
Compute B=δ∗(qi,a)∪δ∗(qj,a)∪…∪δ∗(qk,a)
Add state B if it doesn’t exist
Add edge from A to B with label a
Identify final states
If λ∈L(MN), then make the start state final.
1.1.13. Example: NFA to DFA¶
1.1.14. So, why NFA?¶
Conclusion: NFA adds no new capability. So why bother with the idea?
First, it wasn’t obvious that they are the same. NFA is a useful concept.
NFA tend to be “smaller” and “simpler” than the equivalent DFA. (At least morphologically, but perhaps the language of a NFA is hard to grasp.)
We will see times when it is easier to see a conversion from something to a NFA, and we know that this can always be converted in turn to a DFA.