 # Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.

## Presentation on theme: "Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to."— Presentation transcript:

Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to an equivalent DFA.

Nondeterminism Nondeterministic machines have option to make multiple moves from a state on an input. A nondeterministic finite automaton has transition rules/possibilities like q1q1 q2q2  q1q1 q2q2 1 q3q3 1

Why non-deterministic automata? Non-determinism is a fundamental computational concept. to model rules in games: in games, there is more than one choice in a given position. Grammars and rewriting systems are non-deterministic by nature. Non-deterministic finite automata are more compact. Modeling uncertainty in nature or unknown domains:

A Nondeterministic Automaton q1q1 q2q2 q3q3 1 0,  0,1 This automaton accepts “0110”, because there is a possible path that leads to an accepting state, namely: q 1  q 1  q 2  q 3  q 4  q 4 q4q4 1 0,1

A Nondeterministic Automaton q1q1 q2q2 q3q3 1 0,  0,1 The string 1 gets rejected: on “1” the automaton can only reach: {q 1,q 2,q 3 }. q4q4 1 0,1

A Nondeterministic Automaton Designing a NFA is sometimes easier. Example: L = { x | x contains 101 or 110 as a substring } Designing a DFA for this language is tricky, but NFA design is easy.

NFA – computation tree For any (sub)string w, the nondeterministic automaton can be in a set of possible states. If the final set contains an accepting state, then the automaton accepts the string. “The automaton processes the input in a parallel fashion. Its computational path is no longer a line, but a tree.”

Nondeterministic FA (definition) A nondeterministic finite automaton (NFA) M is defined by a 5-tuple M=(Q, , ,q 0,F), with –Q: finite set of states –  : finite alphabet –  : transition function  :Q    P (Q) –q 0  Q: start state –F  Q: set of accepting states

Nondeterministic  :Q    P (Q) The function  :Q    P (Q) is the crucial difference. It means: “ When reading symbol “a” while in state q, one can go to one of the states in  (q,a)  Q.” The  in   =   {  } provides null-transitions: moves in which a state transition occurs without reading the next input symbol.

Example NFA from the text

Non-deterministic Finite Automata (NFAs) 1 1 1 0 0 0   xample 2: Does this NFA accept 11011?  

            1 1 1 0 0 0   

Equivalence of NFAs and DFAs Obvious Fact: If L is a language accepted by a DFA then there is an NFA that also accepts it. This is because every DFA is an NFA. Theorem: If L is a language accepted by an NFA then there is a DFA that also accepts it. Proof is constructive. We describe an algorithm to convert an NFA to an equivalent DFA.

Proof idea: First consider an NFA M without  - moves. We are to design a DFA M’ that simulates it. Since NFA can be one of many states after reading an input, the simulating DFA will have as its states the subsets of states of M. p q r s {p} {q, r, s} a a a a  r, x, m, p} Will be an accepting state so long as at least one of the states is an accepting state in the original NFA.

Converting an  -free NFA to a DFA: Let M = (Q, , ,q 0,F) be an NFA. The equivalent DFA is M’ = ( P (Q), ,  ’, {q 0 }, F’) where  ’ (A, a) = all states reachable from some state in A on input a. (If A = { q 1, …, q m } then,  ’ (A, a) =  (q 1, a) U  (q 2, a) U … U  (q m, a) ) F’ = { A | A F } We can show that L(M) = L(M’).

Conversion of an NFA to a DFA c b 1 1,0 1 0 0 0 NFA a Equivalent DFA {a}{b}{c} {a,b}{a,c}{b,c} {a,b,c} 0 0 0 0 11 1 0,1 1 0 1 0 1  xample 1:

Dealing with e-moves  -closure: For a set of states R,  -closure(R) is defined as the set of states reachable from states in R by a sequence of  -moves. 1 1 1 0 0 0     f R = {1, 3}, what is  -closure(R)? 

Converting an NFA M with  -moves to a DFA: Suppose we have computed  -closure of every state in M. To accept a string a 1 … a m, M can first perform a sequence of  -moves, then move on a 1, then perform a sequence of  -moves, then move on a 2, etc. Finally, after a move on a m, it can perform another sequence of  - moves and reach an accepting state. Recall the subset construction we described above to convert an  -free NFA to a DFA. What changes do we need to make it work for NFA with  -moves?

Example: 0 1 2 

Download ppt "Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to."

Similar presentations