Download presentation
Presentation is loading. Please wait.
1
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Course: Theory of Automata Topic: Non-deterministic Finite Automata Instructor: Dr. Arif Mushtaq [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
2
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label of transitions. An NFA is a collection of 3 things: Finite many states with one initial and some final states. Finite set of input letters, say Σ={a, b, c} Finite set of transitions showing where to move if a letter is input at certain state (null is not a valid transition), there may be more than one transition for certain letters and there may not be any transition for certain letters. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
3
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Observations: It may be observed, from the definition of NFA, that the string is supposed to be accepted, if there exists at least one successful path, otherwise rejected. It is to be noted that an NFA can be considered to be an intermediate structure between FA and TG (i.e. not all relaxations of TGs is allowed in NFA and similarly we are not bound to follow the conditions of FA). The examples of NFAs can be found in the following [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
4
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example It is to be noted that the above NFA accepts the language consisting of a and ab. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
5
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example It is to be noted that the above NFA accepts the language of strings, defined over Σ={a, b}, containing aa. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
6
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Reason: An NFA helps to avoid a loop in FA. Note: It is to be noted that an NFA helps to eliminate a loop at certain state of FA. This process is done by converting a loop into circuit. But during this process the FA remains no longer FA and converted to a corresponding NFA, which is shown in the following examples: [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
7
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example: Consider a part of the following FA with an alphabet set Σ={a, b, c, d} To eliminate the loop at state 7, the corresponding NFA may be as follows [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
8
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example: To avoid the loop and to maintain the same language FA is converted to the NFA [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
9
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Note: we can build an FA to an equivalent NFA. It is to be noted that according to the Kleene’s theorem, if a language can be accepted by an FA, then there exists a TG accepting that language. Since, an NFA is a TG as well, therefore, there exists an NFA accepting the language accepted by the given FA. In this case these FA and NFA are said to be equivalent to each others. Following are the examples of FAs to be converted to NFAs. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
10
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example: Consider the FA corresponding to (a+b)*b The above FA may be equivalent to the following NFA. Can the structure of above NFA be compared with the corresponding RE? [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
11
Non-deterministic Finite Automata (NFA)
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non-deterministic Finite Automata (NFA) Example: Consider the FA The above FA may be equivalent to the following NFA. Can the structure of above NFA be compared with the corresponding RE? [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
12
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Application of an NFA There is an important application of an NFA Consider the FA in artificial intelligence, which is discussed in the following example of a maze: How many paths can be found starting from initial state to the final state? [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
13
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Application of an NFA - and + sign indicates initial and final state respectively. One can move only from a box labeled by other than L, M, N, O, P to such an another box. To determine the number of ways in which one can start from the initial state and end in the final state, the following NFA using only single letter a, can help in this regard. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
14
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Application of an NFA [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
15
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Application of an NFA It can be observed that the shortest path which leads from the initial state and ends in the final state, consists of the six steps i.e. the shortest string accepted by this machine is aaaaaa. The next larger string accepted is aaaaaaaa. Thus if this FA is considered to be a TG then the corresponding RE may be written as aaaaaa(aa)* which shows that there are finite many required ways. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
16
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Application of an NFA Note: It is to be noted that every FA can be considered to be an NFA as well, but the converse may not true. It may also be noted that every NFA can be considered to be a TG as well, but the converse may not be true. It may be observed that if the transition of null string is also allowed at any state of an NFA then what will be the behavior in the new structure. This structure is defined in the following. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
17
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA with Null String Definition: if in an NFA, ᴧ is allowed to be a label of an edge then the NFA is called NFA with null (NFA-ᴧ). An NFA-ᴧ is a collection of three things: Finite many states with one initial and some final states. Finite set of input letters say, Σ={a, b, c}. Finite set of transitions, showing where to move if a letter is input at certain state. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
18
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA with Null String There may be more than one transitions for certain letter and there may not be any transition for a letter. The transition of ᴧ string is also allowed at any state. Example: The above NFA with null string accepts the language of strings, defined over Σ={a, b}, ending in b. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
19
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA with Null String Example: The above NFA-ᴧ string accepts the language of strings, defined over Σ={a, b}, ending in a. Note: It is to be noted that every FA may be considered to be an NFA-ᴧ as well, but the converse may not true. Similarly, every NFA-ᴧ may be considered to be a TG as well, but the converse may not true. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
20
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
21
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Three methods are discussed in this regard Method 1: Since an NFA can be considered to be a TG as well, so a RE corresponding to the given NFA can be determine (using kleene’s theorem). Again using the methods discussed in the proof of kleene’s theorem, an FA can be built corresponding to that RE. Hence for a given NFA, an FA can be built equivalent to the NFA. Examples have indirectly been discussed earlier. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
22
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Method 2: Since in an NFA, there are more than one transition for a certain letter and there may not be any transition for a certain letter, so starting from the initial state corresponding to the initial state of given NFA, the transition diagram of the corresponding FA, can be built introducing an empty state for a letter having no transition at certain state and a state corresponding to the combination of states, for a letter having more than one transitions. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
23
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: Consider the following NFA Using the method discussed, the above NFA may be equivalent to the following FA. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
24
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: Consider the following NFA [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
25
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: A simple NFA that accepts the language of strings defined over Σ={a,b}, consists of bb and bbb. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
26
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
27
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Method 3: As discussed earlier that in an NFA, there may be more than one transition for a certain letter and there may not be any transition for a certain letter, so starting from the initial state corresponding to the initial state of given NFA, the transition table along with new labels of states, of the corresponding FA, can be built introducing an empty state for a letter having no transition at certain state and a state corresponding to the combination of states, for a letter having more than one transitions. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
28
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: Consider the following NFA which accepts the language of strings containing bb [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
29
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA to FA Example: [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
30
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NAF to DFA [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
31
Non Deterministic Features of NFA
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Non Deterministic Features of NFA There are three main cases of non- determinism in NFAs: Transition to a state without consuming any input. Multiple transitions on the same input symbol. No transition on an input symbol. To convert NFAs to DFAs we need to get rid of non-determinism from NFAs. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
32
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Using Subset construction method to convert NFA to DFA involves the following steps: For every state in the NFA, determine all reachable states for every input symbol. The set of reachable states constitute a single state in the converted DFA (Each state in the DFA corresponds to a subset of states in the NFA). Find reachable states for each new DFA state, until no more new states can be found. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
33
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Fig1. NFA without λ-transitions [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
34
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Fig1. NFA without λ-transitions 3 b a a a 2 a b a,b 1 5 a a,b 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
35
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Step1 Fig1. NFA without λ-transitions 3 b a a a 2 a b Construct a transition table showing all reachable states for every state for every input signal. a,b 1 5 a a,b 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
36
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Fig1. NFA without λ-transitions Fig2. Transition table 3 b a a a 2 a b a,b 1 5 a a,b 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
37
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Fig2. Transition table Fig1. NFA without λ-transitions 3 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 b a a a 2 a b a,b 1 5 a a,b 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
38
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Transition from state q with input a Fig2. Transition table Transition from state q with input b Fig1. NFA without λ-transitions 3 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 b a Starts here a a 2 a b a,b 1 5 a a,b 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
39
Subset Construction Method
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Subset Construction Method Fig2. Transition table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 Step2 The set of states resulting from every transition function constitutes a new state. Calculate all reachable states for every such state for every input signal. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
40
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 Starts with Initial state q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
41
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 Starts with Initial state q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
42
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 Starts with Initial state q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} Step3 Repeat this process(step2) until no more new states are reachable. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
43
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
44
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
45
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
46
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
47
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ We already got 4 and 5. So we don’t add them again. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
48
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ 2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
49
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ 2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
50
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ 2 3 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
51
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig2. Transition table Fig3. Subset Construction table q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} 2 {3} {5} 3 ∅ {2} 4 {4} 5 q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ 2 3 Stops here as there are no more reachable states [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
52
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad Fig4. Resulting FA after applying Subset Construction to fig1 Fig3. Subset Construction table a q δ(q,a) δ(q,b) 1 {1,2,3,4,5} {4,5} {2,4,5} 5 4 {3,5} ∅ 2 3 b a 12345 245 35 a a,b a b b ∅ a 1 3 b a,b b a 2 a 45 5 b b a 4 b [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
53
Instructor: Dr. Arif Mushtaq
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA & Kleene’s Theorem [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
54
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem It has been discussed that, by kleene’s theorem Part III, there exists an FA corresponding to a given RE. If the corresponding RE is simple, the corresponding FAs can easily be built. However, for complicated RE, using the method constructing the FAs for sum, concatenation and closure, the required FAs can also be built. It is to be noted that NFAs also help in proving kleene’s theorem Part III. Two methods are discussed: [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
55
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 1: the method is discussed considering the following example. Example: To construct the FAs for the languages L1={a}, L2={b} and L3={ᴧ} Step1: Build NFA1, NFA2 and NFA3 corresponding to L1, L2 and L3 respectively as shown in the following diagram. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
56
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 1: NFA1 NFA2 NFA3 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
57
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Step2: As discussed earlier for every NFA there is an FA equivalent to it, hence there must be FAs for the above NFAs as well. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
58
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 2: it may be observed that if an NFA can be built corresponding to union, concatenation and closure of FAs corresponding to the REs, then converting the NFA, thus, obtained into an equivalent FA, this FA will correspond to the given RE. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
59
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 2 (NFA corresponding to union of FAs): Introduce a new start state and connect it with the states originally connected with the old start state with the same transitions as the old start state, then remove the –ve sign of old start state. This creates non-determinism and hence results in an NFA. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
60
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example FA1 FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
61
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem NFA equivalent to FA1 U FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
62
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example FA1 FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
63
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem NFA equivalent to FA1 U FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
64
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 2 (NFA corresponding to concatenation of FAs): Introduce additional transitions for each letter connecting each final state of the first FA with states of second FA that are connected with the initial states of second FA corresponding to each letter of the alphabet. Remove the +ve sign of each of final states of first FA and –ve sign of initial state of second FA. It will create non-determinism at final states of first FA and hence NFA, thus obtained, will be the required NFA. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
65
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Note: It may be noted that if no FAs accepts Null string then the +ve signs of first FA will be removed, and -ve sign of 2nd FA will be removed. If first FA accepts the null string then every string accepted by 2nd FA must be accepted by the concatenation of FAs as well. This situation will automatically be accommodated using the method discussed earlier. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
66
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem However, if the 2nd FA accepts Null string, then every string accepted by first FA must be accepted by the required FA as well. This target can be achieved as, while introducing new transitions at final states of first FA, the +ve signs of these states will not be removed. Lastly, if both FAs accept the Null string, then the Null string must be accepted by the required FA. This situation will automatically be accommodated as the second FA accepts the Null string and hence the +ve signs of final states of first FA will not be removed. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
67
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example (No FA accepts Null string) FA1 FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
68
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem NFA equivalent to FA1FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
69
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example (FA2 accepts Null string) FA1 FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
70
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem NFA equivalent to FA1FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
71
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example (both FAs accept Null string) FA1 FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
72
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem NFA equivalent to FA1FA2 [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
73
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Method 2 (NFA corresponding to the closure of FA): Apparently, it seems that since closure of an FA accepts the null string, so the required NFA may be obtained considering the initial state of given FA to be final as well, but this may allow the unwanted strings to be accepted as well. For example, an FA, with two states, accepting the language of strings, defined over Σ={a, b} ending in a, will accepts all unwanted strings, if the initial state is supposed to be final as well. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
74
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Thus, to accommodate this situation, introduce an initial state which should be final as well (so that the null string is accepted) and connect it with the states originally connected with the old start state with the same transitions as the old start state, then remove the –ve sign of old start state. Introduce new transitions, for each letter at each of the final states (including new final state) with those connected with the old start state. This creates non-determinism and hence results in the required NFA. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
75
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example It may be observed that the FA* accepts only the additional string which is the null string. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
76
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Considering the state 1 to be final as well, will allow the unwanted strings to be accepted as well. Hence the required NFA is constructed introducing the new initial state. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
77
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example The required NFA is constructed introducing the new initial state. [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
78
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example Here we don’t need separate initial and final state. Hence an NFA corresponding to FA* may be [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
79
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
80
NFA and Kleene’s Theorem
bilawalsheikh333.blogspot.com Theory of Automata (BSCS)-4A Fall 2012, BU Islamabad NFA and Kleene’s Theorem Example [Week#10,11] - Non-deterministic Finite Automata (NFA) Instructor: Dr. Arif Mushtaq
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.