# 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 q2 1 q1 q2 q1 q3 1

A Nondeterministic Automaton
0,1 0,1 1 0,  1 q1 q2 q3 q4 This automaton accepts “0110”, because there is a possible path that leads to an accepting state, namely: q1  q1  q2  q3  q4  q4

A Nondeterministic Automaton
0,1 0,1 1 0,  1 q1 q2 q3 q4 The string 1 gets rejected: on “1” the automaton can only reach: {q1,q2,q3}.

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,,,q0,F), with Q: finite set of states : finite alphabet : transition function :QP (Q) q0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.

Non-deterministic Finite Automata (NFAs)
Example 2: 1 1 2 1 1 Does this NFA accept ? 3 13

1 1 2 1 1 1 1 e 3 2 3 e 3 3 2 1 1 1 1

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. 17

Proof idea: First consider an NFA M without e-moves
Proof idea: First consider an NFA M without e-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. q a p a r a {p} {q, r, s} a s Will be an accepting state so long as at least one of the states is an accepting state in the original NFA. { r, x, m, p}

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

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

Dealing with e-moves e-closure: For a set of states R, e-closure(R) is defined as the set of states reachable from states in R by a sequence of e-moves. 1 1 2 e 1 1 If R = {1, 3}, what is e-closure(R)? 3

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

Example: e e

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