23
Lecture # 13 Lecture # 13

Lecture # 13

  • Upload
    joyce

  • View
    47

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture # 13. NFA and Kleene’s Theorem. - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture # 13

Lecture # 13Lecture # 13

Page 2: Lecture # 13

NFANFA and and Kleene’s TheoremKleene’s Theorem It has been discussed that, by Kleene’s It has been discussed that, by Kleene’s

theorem part III, theorem part III, there exists an FA there exists an FA corresponding to a given RE.corresponding to a given RE. If the given RE If the given RE is as simple asis as simple as r=aa+bbbr=aa+bbb or or r=a(a+b)*,r=a(a+b)*, the the corresponding FAs can easily be constructed. corresponding FAs can easily be constructed. However, for a complicated RE, the RE can However, for a complicated RE, the RE can be decomposed into simple REs be decomposed into simple REs corresponding to which the FAs can easily be corresponding to which the FAs can easily be constructed and hence, using the method, constructed and hence, using the method, constructing the FAs corresponding to constructing the FAs corresponding to sumsum, , concatenationconcatenation and and closureclosure of FAs, the of FAs, the required FA can also be constructed. required FA can also be constructed. It is to It is to be noted that NFAs also help in proving be noted that NFAs also help in proving Kleene’s theorem part III, as well. Two Kleene’s theorem part III, as well. Two methods are discussed in the following. methods are discussed in the following.

Page 3: Lecture # 13

NFA and Kleene’s Theorem NFA and Kleene’s Theorem

Method 1Method 1: : The method is discussed The method is discussed considering the following example.considering the following example.

ExampleExample::To construct the FAs To construct the FAs for the languages Lfor the languages L11= {a}, L= {a}, L22= {b} = {b} and Land L3 3 = {= {ΛΛ} } Step 1Step 1: Build NFA: Build NFA11, NFA, NFA22 and NFAand NFA33 corresponding to L corresponding to L11, L, L22 and and LL33 , respectively as shown in the , respectively as shown in the following diagram following diagram

Page 4: Lecture # 13

NFA and Kleene’s Theorem NFA and Kleene’s Theorem (method 1 ) continued … (method 1 ) continued …

Page 5: Lecture # 13

NFA and Kleene’s Theorem NFA and Kleene’s Theorem (method 1 ) continued … (method 1 ) continued …

Step 2Step 2::

As discussed earlier for every NFA there is As discussed earlier for every NFA there is an FA equivalent to it, hence there must be an FA equivalent to it, hence there must be FAs for the above mentioned NFAs as well. FAs for the above mentioned NFAs as well. The corresponding FAs can be considered The corresponding FAs can be considered as follows as follows

Page 6: Lecture # 13

NFA and Kleene’s Theorem NFA and Kleene’s Theorem (method 1 ) continued … (method 1 ) continued …

Page 7: Lecture # 13

NFA and Kleene’s Theorem NFA and Kleene’s Theorem method 2 method 2

It may be observed that if an It may be observed that if an NFANFA can be can be built corresponding to built corresponding to unionunion, , concatenationconcatenation and and closureclosure of of FAsFAs corresponding to the corresponding to the REs, then converting the NFA, thus, REs, then converting the NFA, thus, obtained into an equivalent FA, this FA will obtained into an equivalent FA, this FA will correspond to the given RE. correspond to the given RE.

Followings are the procedures showing how Followings are the procedures showing how to obtain to obtain NFAsNFAs equivalent to equivalent to unionunion, , concatenationconcatenation and and closureclosure of of FAsFAs

Page 8: Lecture # 13

NFANFA corresponding to corresponding to UnionUnion of of FAsFAs

Method: Method:

Introduce a new start state and connect it Introduce a new start state and connect it with the states originally connected with with the states originally connected with the old start state with the same the old start state with the same transitions as the old start state, then transitions as the old start state, then remove the –ve sign of old start state. This remove the –ve sign of old start state. This creates non-determinism and hence creates non-determinism and hence results in an NFA. results in an NFA.

Page 9: Lecture # 13

Example Example

FA1 FA1

FA2 FA2

Page 10: Lecture # 13

NFA equivalent to NFA equivalent to FAFA1 1 U FAU FA22

Page 11: Lecture # 13

Example Example

Page 12: Lecture # 13

NFA equivalent to NFA equivalent to FAFA1 1 U FAU FA22

Page 13: Lecture # 13

TaskTask

Using the FAs corresponding to Using the FAs corresponding to

rr11=(a+b)*(aa+bb)(a+b)*=(a+b)*(aa+bb)(a+b)* and and

rr22=a(a+b)*=a(a+b)*

build an build an NFANFA corresponding to corresponding to rr11+r+r22

Page 14: Lecture # 13

NFANFA corresponding to corresponding to ConcatenationConcatenation of of FAsFAs

Page 15: Lecture # 13

NFANFA corresponding to corresponding to ConcatenationConcatenation of of FAsFAs

MethodMethod: :

Introduce additional transitions for each Introduce additional transitions for each letter connecting each final state of the first letter connecting each final state of the first FA with the states of second FA that are FA with the states of second FA that are connected with the initial state of second FA connected with the initial state of second FA corresponding to each letter of the corresponding to each letter of the alphabet. Remove the +ve sign of each of alphabet. Remove the +ve sign of each of final states of first FA and –ve sign of the final states of first FA and –ve sign of the initial state of second FA. It will create non-initial state of second FA. It will create non-determinism at final states of first FA and determinism at final states of first FA and hence NFA, thus obtained, will be the hence NFA, thus obtained, will be the required NFA. required NFA.

Page 16: Lecture # 13

NFANFA corresponding to corresponding to ConcatenationConcatenation of of FAsFAs

NoteNote::It may be noted that if first FA accepts the It may be noted that if first FA accepts the Null string then every string accepted by Null string then every string accepted by second FA must be accepted by the second FA must be accepted by the concatenation of FAs as well. This situation concatenation of FAs as well. This situation will automatically be accommodated using will automatically be accommodated using the method discussed earlier. However if the the method discussed earlier. However if the second FA accepts Null string, then every second FA accepts Null string, then every string accepted by first FA must be accepted string accepted by first FA must be accepted by the required FA as well. This target can by the required FA as well. This target can be achieved as, while introducing new be achieved as, while introducing new transitions at final states of first FA the +ve transitions at final states of first FA the +ve sign of these states will not be removed. sign of these states will not be removed.

Page 17: Lecture # 13

Note Continued … Note Continued …

LastlyLastly if both FAs accepts the Null string, if both FAs accepts the Null string, then the Null string must be accepted by then the Null string must be accepted by the required FA. This situation will the required FA. This situation will automatically be accommodated as the automatically be accommodated as the second FA accepts the Null string and second FA accepts the Null string and hence the +ve signs of final states of first hence the +ve signs of final states of first FA will not be removed. FA will not be removed.

Page 18: Lecture # 13

Example (Example (No FA accepts Null No FA accepts Null stringstring))

Page 19: Lecture # 13

NFANFA equivalent to equivalent to FAFA11FAFA22

Page 20: Lecture # 13

Example (Example (FAFA22 accepts Null accepts Null stringstring) )

Page 21: Lecture # 13

NFANFA equivalent to equivalent to FAFA11FAFA22

Page 22: Lecture # 13

Example (Example (Both FAs accept Null Both FAs accept Null stringstring) )

FAFA11

FAFA2 2

Page 23: Lecture # 13

NFANFA equivalent to equivalent to FAFA11FAFA22