Lecture 08
Lecture 08
Lecture 08
Q P(Q)
(q,)={q}
(q,ua) is the union of the sets
(p,a), where p varies over all states in
(q,u),
i.e.,
p (q,u) (p,a),
2. NFA Language Acceptance
1
(q0,000) = (x,0)
x(q0,00)
(q0,00) = (y,0)
y(q0,0)
(q0,0) = (q0,0) = {q0,q1}
(q0,00) = (y,0)
y{q0,q1}
(q0,00) = {q0,q1} {q2} = {q0,q1,q2}
(q0,000)= (x,0)
x{q0,q1,q2}
(q0,000)={q0,q1} {q2} {q3}
(q0,000)={q0,q1,q2,q3}
(qo,w) F = {q0,q1,q2,q3} {q3}
3. NFA- Examples
Example 1 Note that below NFA accepts language
of strings, defined over Σ = {a, b}, containing ‘aa’.
a,b a,b
1- a 2 a 3+
3
a b 5+
3. Examples: FA to NFA
Example 1
• Consider following FA corresponding to (a + b)*b
a b b
- +
a
– b +
3. Examples: FA to NFA
Example 2
Consider the following FA
b a a,b
a
– 1 +
b
a, b a, b
– a 1 a +
3. Relationship between NFA, FA and TG
a a a a
a a a
6 8 7 9 +
a a a
5. NFA- Λ
• In NFA, if Λ is allowed to be a label of an edge
then the NFA is called NFA with Λ (NFA-Λ ).
• An NFA is a collection of
1. Finite many states
2. Unique initial state
3. Some final states
4. Finite set of input letters, e.g., Σ = {a, b, c}
5. Finite set of transitions as in NFA. In addition
null (Λ) transitions are allowed
5. NFA- Λ
Example
• NFA with Null string which accepts the language of
strings, defined over Σ = {a, b}, ending in b.
a, b
b Λ
– 1 +
1- a
2
2
b
a b
b 4+ a
1- 4+ a a, b
b a
3 b
3 a, b
6. NFA to FA
Example 2 (Method 2)
b
b b
1- b 2 3 4+
b b
1- 2 b
(3,4)+
a 4+
a a a,b
a, b
6. Transition Table: NFA to FA
a, b a, b
b x2 b x3 +
x1 -
z1 - = x 1 x1 = z 1 (x1 ,x2 ) = z2
b a
a b a
z1 - z2 b z3 + z4 +
a b
7. Construction of FA from RE
Method:
•Method is discussed considering the example.
Example
• To construct the FAs for the languages L1 = {a},
L2 = {b} and L3 = {Λ}
Step 1: Build NFA1, NFA2 and NFA3
corresponding to L1, L2 and L3 , respectively as
shown below
a b +/-
- + - +
–
a + – b +
a,b
a,b a,b
a a,b
b +/ - 1
1
1
a,b
a,b Dr. Nazir Ahmad Zafar
7. Construction of FA from RE
Union, concatenation and closure of FAs
• NFA can be built corresponding to
1. union,
2. concatenation and
3. closure
of FAs corresponding to REs
• Procedure is next
7.1. NFA corresponding to Union of FAs
1
a x2
x- a
a b b a -
b
a b a b b a
x3 x1 a x2
x4 +
b a b x4 + a x3
• FA2 b
a a, b
a,b y1 b y2+
a
b y2+
y1-
7.2. NFA corresponding to Concatenation of FAs
Cases
1.FA1 accepts null
2.FA2 accepts null
3.Both FA1 and
FA2 accept null
7.2. NFA corresponding to Concatenation of FAs
Case 1: FA1 may accept null
• Introduce additional transitions for each letter
connecting each final state of the first FA with the
states of second FA that are connected with the initial
state of second FA corresponding to each letter of the
alphabet.
• Remove the +ve sign of each of final states of first FA
• Remove –ve sign of the initial state of second FA.
• It will create non-determinism at final states of first FA
• Hence NFA, thus obtained, will be the required NFA.
7.2. NFA corresponding to Concatenation of FAs
• NFA = FA1FA2 2 a 4
b a,b a a
a b a,b
a 1 a b 6+
p- q r+ –
b b a b
33 b 5
2 a 4
a a a
b a a,b b a,b
pp- b q a 1 a 6+
r b
- a b
b
b
a, b
b a,b
a
p- q a
b r +
a, b
a, b
x+ y
b
7.3. NFA corresponding to the Closure of an FA
Method
• Introduce an initial state which should be final
as well
• Connect it with the states originally connected
with old start state with same transitions as old
start state and remove –ve sign of old start state
• Introduce new transitions, for each letter, at
each of 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.
7.3. NFA corresponding to the Closure of an FA
Example 1
Introducing new Initial state to find FA Closure
b a a, b
1- 2 a 3+
b
Closure of FA a
a a, b
b a
± b 2 a
1 3+
b
b
7.3. NFA corresponding to the Closure of an FA
Example 2
Introducing new Initial state to find FA Closure
b a a
Given FA
1 2+
–
b
NFA which is closure of FA
a
b a
a
± b 1 2+
b
7.3. NFA corresponding to the Closure of an FA
Example 3 a,
Given FA b 1± a, b a, b
2+ 3
Closure of
FA
• It can be observed that FA* not only accepts the
Null string but every other string as well.
• We don’t need separate initial and final state.
• Hence an NFA corresponding to FA* may be
a, b
a, b 2+a, b a, b
1± 3
7.3. NFA corresponding to the Closure of an FA
Example 4
Given FA Closure of FA
q q
0 0 0 0
0 0 0,1
0, 1
p- 0 1 s+ ± p 0 1 s
+
1 1 1
1 1 1
r r
8. Memory required to recognize a language
Example 1 = {a, b}
• L = {w {a, b}* | Length (w) ≥ 2 w neither ends in ab
nor in ba}