lecture # 12. nondeterministic finite automaton (nfa) definition: an nfa is a tg with a unique start...
TRANSCRIPT
Lecture # 12Lecture # 12
Nondeterministic Finite Nondeterministic Finite Automaton (NFA) Automaton (NFA)
DefinitionDefinition:: An NFA is a TG with a unique start An NFA is a TG with a unique start state and a property of having single letter as state and a property of having single letter as label of transitions. An NFA is a collection of label of transitions. An NFA is a collection of three things three things
1)1) Finite many states with one initial and some Finite many states with one initial and some final states final states
2)2) Finite set of input letters, say, Finite set of input letters, say, ΣΣ ={a, b, c} ={a, b, c} 3)3) Finite set of transitions, showing where to Finite set of transitions, showing where to
move if a letter is input at certain state (move if a letter is input at certain state (ΛΛ is not is not a valid transition), there may be more than one a valid transition), there may be more than one transition for certain letters and there may not transition for certain letters and there may not be any transition for certain letters.be any transition for certain letters.
Observations Observations
It may be observed, from the definition of It may be observed, from the definition of NFA, that the string is supposed to be NFA, that the string is supposed to be accepted, if there exists accepted, if there exists at least one at least one successful pathsuccessful path, , otherwise rejectedotherwise rejected. .
It is to be noted that an NFA can be It is to be noted that an NFA can be considered to be an intermediate structure considered to be an intermediate structure between FA and TG. between FA and TG.
The examples of NFAs can be found in the The examples of NFAs can be found in the following following
Example Example
It is to be noted that the above NFA It is to be noted that the above NFA accepts the language consisting of accepts the language consisting of aa and and abab. .
Example Example
It is to be noted that the above NFA It is to be noted that the above NFA accepts the language of strings, defined accepts the language of strings, defined over over ΣΣ = {a, b}, containing = {a, b}, containing aaaa..
Note Note
It is to be noted that It is to be noted that NFANFA helps to helps to eliminate a loopeliminate a loop at certain state of an at certain state of an FAFA..
This process is done converting the loop This process is done converting the loop into a circuit. But during this process the into a circuit. But during this process the FA remains no longer FA and is converted FA remains no longer FA and is converted to a corresponding NFA, which is shown in to a corresponding NFA, which is shown in the following example. the following example.
Example Example Consider a part of the following Consider a part of the following FAFA with an with an
alphabet alphabet ΣΣ={={a,b,c,da,b,c,d} }
To eliminate the loop at state 7, the To eliminate the loop at state 7, the corresponding corresponding NFANFA may be as follows may be as follows
Example continued ... Example continued ...
Converting an Converting an FAFA to an equivalent to an equivalent NFANFA
It is to be noted that according to the It is to be noted that according to the Kleene’s theorem, if a language can be Kleene’s theorem, if a language can be accepted by an FA, then there exists a TG accepted by an FA, then there exists a TG accepting that language. Since, an NFA is a accepting that language. Since, an NFA is a TG as well, therefore there exists an NFA TG as well, therefore there exists an NFA accepting the language accepted by the accepting the language accepted by the given FA.given FA.
In this case these In this case these FAFA and and NFANFA are said to be are said to be equivalentequivalent to each others. to each others. Following are Following are the examples of FAs to be converted to the the examples of FAs to be converted to the equivalent NFAsequivalent NFAs
Example Example Consider the following FA corresponding to Consider the following FA corresponding to
(a+b)*b (a+b)*b
The above FA may be equivalent to the The above FA may be equivalent to the following NFA following NFA
Can the structure of above NFA be Can the structure of above NFA be compared with the corresponding RE ? compared with the corresponding RE ?
Example Example Consider the following FAConsider the following FA
The above FA The above FA may bemay be equivalent to the equivalent to the following NFA following NFA
Can the structure of above NFA be compared Can the structure of above NFA be compared with the corresponding RE ? with the corresponding RE ?
TaskTask
Build an Build an NFANFA equivalent to the following equivalent to the following FAFA
Note Note It is to be noted that every FA can be It is to be noted that every FA can be
considered to be an NFA as well , but the considered to be an NFA as well , but the converse may not true. converse may not true.
It may also be noted that every NFA can be It may also be noted that every NFA can be considered to be a TG as well, but the considered to be a TG as well, but the converse may not true. converse may not true.
It may be observed that if the transition of It may be observed that if the transition of null string is also allowed at any state of an null string is also allowed at any state of an NFA then what will be the behavior in the NFA then what will be the behavior in the new structure. This structure is defined in new structure. This structure is defined in the followingthe following
NFA with Null String NFA with Null String DefinitionDefinition:: If in an NFA, If in an NFA, ΛΛ is allowed to be a label is allowed to be a label
of an edge then the NFA is called NFA with of an edge then the NFA is called NFA with ΛΛ (NFA- (NFA- ΛΛ ). An NFA- ). An NFA- ΛΛ is a collection of three thingsis a collection of three things
(1)(1) Finite many states with one initial and some Finite many states with one initial and some final states.final states.
(2)(2) Finite set of input letters, say, Finite set of input letters, say, ΣΣ ={a, b, c}. ={a, b, c}. (3)(3) Finite set of transitions, showing where to Finite set of transitions, showing where to
move if a letter is input at certain state. There move if a letter is input at certain state. There may be more than one transitions for certain may be more than one transitions for certain letter and there may not be any transition for a letter and there may not be any transition for a certain letter. The transition of certain letter. The transition of ΛΛ is also allowed at is also allowed at any state.any state.
Example Example
Consider the following NFA with Null string Consider the following NFA with Null string
The above NFA with Null string accepts the The above NFA with Null string accepts the language of strings, defined over language of strings, defined over ΣΣ = {a, = {a, b}, b}, ending in bending in b. .
Example Example
Consider the following NFA with Null string Consider the following NFA with Null string
The above NFA with Null string accepts the The above NFA with Null string accepts the language of strings, defined over language of strings, defined over ΣΣ = {a, = {a, b}, b}, ending in aending in a. .
Task Task
Determine the regular expression of the Determine the regular expression of the following following NFA-NFA-ΛΛ
Note Note
It is to be noted that every FA may be It is to be noted that every FA may be considered to be an NFA- considered to be an NFA- ΛΛ as well, but the as well, but the converse may not true.converse may not true.
Similarly every NFA- Similarly every NFA- ΛΛ may be considered may be considered to be a TG as well, but the converse may to be a TG as well, but the converse may not true.not true.
NFA to FA NFA to FA Two methods are discussed in this regard. Two methods are discussed in this regard.
Method 1Method 1: Since an NFA can be considered to : Since an NFA can be considered to be a TG as well, so a RE corresponding to be a TG as well, so a RE corresponding to the given NFA can be determined (using the given NFA can be determined (using Kleene’s theorem). Again using the methods Kleene’s theorem). Again using the methods discussed in the proof of Kleene’s theorem, discussed in the proof of Kleene’s theorem, an FA can be built corresponding to that RE. an FA can be built corresponding to that RE. Hence for a given NFA, an FA can be built Hence for a given NFA, an FA can be built equivalent to the NFA. Examples have, equivalent to the NFA. Examples have, indirectly, been discussed earlier.indirectly, been discussed earlier.
NFA to FA continued … NFA to FA continued … Method 2Method 2:: Since in an NFA, there more than Since in an NFA, there more than
one transition for a certain letter and there one transition for a certain letter and there may not be any transition for certain letter, may not be any transition for certain letter, so starting from the initial state so starting from the initial state corresponding to the initial state of given corresponding to the initial state of given NFA, the transition diagram of the NFA, the transition diagram of the corresponding FA, can be built introducing an corresponding FA, can be built introducing an empty state for a letter having no transition empty state for a letter having no transition at certain state and a state corresponding to at certain state and a state corresponding to the combination of states, for a letter having the combination of states, for a letter having more than one transitions. Following are the more than one transitions. Following are the examples examples
Example Example
Consider the following Consider the following NFANFA
Using the method discussed earlier, the Using the method discussed earlier, the above NFA may be equivalent to the above NFA may be equivalent to the following FA following FA
Example Continued ... Example Continued ...
Example Example
A simple NFA that accepts the language of A simple NFA that accepts the language of strings defined over strings defined over ΣΣ ={a,b}, ={a,b}, consists of consists of bbbb and and bbbbbb
The above NFA can be converted to the The above NFA can be converted to the following FA following FA
Example Continued ... Example Continued ...
NFA to FA continued … NFA to FA continued … Method 3Method 3:: As discussed earlier that in an As discussed earlier that in an
NFA, there may be more than one transition NFA, there may be more than one transition for a certain letter and there may not be any for a certain letter and there may not be any transition for certain letter, so starting from transition for certain letter, so starting from the initial state corresponding to the initial the initial state corresponding to the initial state of given NFA, the transition table along state of given NFA, the transition table along with new labels of states, of the with new labels of states, of the corresponding FA, can be built introducing corresponding FA, can be built introducing an empty state for a letter having no an empty state for a letter having no transition at certain state and a state transition at certain state and a state corresponding to the combination of states, corresponding to the combination of states, for a letter having more than one for a letter having more than one transitions. Following are the examples transitions. Following are the examples
Example Example
Example continued … Example continued …
The corresponding transition diagram follows as The corresponding transition diagram follows as
Old statesOld statesNew states after readingNew states after reading
a a b b
ZZ1 1 __ x x11 xx11 z z11 (x(x11, x, x22) ) z z22
zz2 2 (x (x11, x, x22)) (x(x11, , ΛΛ) ) x x11 z z11 (x(x11, x, x22, x, x33) ) z z33
zz33 + + (x (x11, x, x22, , xx33))
(x(x11,x,x33) ) z z44 (x(x1 1 ,x,x22,x,x33) ) z z33
zz44+ + (x (x11,x,x33) ) (x(x11,x,x33) ) z z44 (x(x1 1 ,x,x22,x,x33) ) z z33
Example continued … Example continued …