Lecture # 7

29
Lecture # 7 Lecture # 7 Finite Automata Finite Automata

description

Lecture # 7. Finite Automata. FA corresponding to finite languages. Example Consider the language L = { Λ , b, ab, bb} , defined over Σ ={a, b}, expressed by Λ + b + ab + bb OR Λ + b ( Λ + a + b) The language L may be accepted by the following FA. Example continued …. - PowerPoint PPT Presentation

Transcript of Lecture # 7

Page 1: Lecture # 7

Lecture # 7Lecture # 7

Finite AutomataFinite Automata

Page 2: Lecture # 7

FA corresponding to FA corresponding to finite finite languageslanguages

ExampleExample

Consider the language Consider the language L = {L = {ΛΛ, b, ab, bb}, b, ab, bb},, defined over defined over ΣΣ ={a, b}, expressed by ={a, b}, expressed by

ΛΛ + b + ab + bb + b + ab + bb OR OR ΛΛ + b ( + b (ΛΛ + a + b) + a + b)

The language L may be accepted by the The language L may be accepted by the following FAfollowing FA

Page 3: Lecture # 7

Example continued … Example continued …

Page 4: Lecture # 7

Example Continued … Example Continued …

It is to be noted that the states x and y are It is to be noted that the states x and y are called called Dead StatesDead States, , Waste BasketsWaste Baskets or or Davey John LockersDavey John Lockers,, as the moment one as the moment one enters these states there is no way to enters these states there is no way to leave it. leave it.

Page 5: Lecture # 7

Note Note

It is to be noted that to build an FA It is to be noted that to build an FA accepting the language having less accepting the language having less number of strings, the tree (Graph) kind of number of strings, the tree (Graph) kind of structure may also help in this regard, structure may also help in this regard, which can be observed in the following which can be observed in the following transition diagram for the Language L, transition diagram for the Language L, discussed in the previous example discussed in the previous example

Page 6: Lecture # 7
Page 7: Lecture # 7

Example Example

Consider the language Consider the language L = {aa, bab, aabb, bbba}L = {aa, bab, aabb, bbba}, defined over, defined over

ΣΣ ={a, b}, expressed by ={a, b}, expressed by aa + bab + aabb + bbba aa + bab + aabb + bbba

OR aa (OR aa (ΛΛ + bb) + b (ab + bba) + bb) + b (ab + bba)

The above language may be accepted by the The above language may be accepted by the following FAfollowing FA

Page 8: Lecture # 7

Example Continued … Example Continued …

Page 9: Lecture # 7

ExampleExample Consider the language :Consider the language :

L = {w belongs to {a,b}*: length(w) >= 2 L = {w belongs to {a,b}*: length(w) >= 2 and w neither ends in and w neither ends in aa aa nornor bb bb}.}.

The language L may be expressed by the The language L may be expressed by the regular expression regular expression (a+b)*(ab+ba)(a+b)*(ab+ba)

This language may be accepted by the This language may be accepted by the following FA following FA

Page 10: Lecture # 7

Example Continued … Example Continued …

Page 11: Lecture # 7

Note Note It is to be noted that building an FA It is to be noted that building an FA

corresponding to the language L, discussed in corresponding to the language L, discussed in the previous example, seems to be quite the previous example, seems to be quite difficult, but the same can be done using difficult, but the same can be done using tree tree structurestructure along with the along with the techniquetechnique discussed in discussed in the bookthe book

Introduction to Languages and Theory of Introduction to Languages and Theory of ComputationComputation, by J. C. Martin, by J. C. Martin

so that the strings ending in aa, ab, ba and bb so that the strings ending in aa, ab, ba and bb should end in the states labeled as aa, ab, ba should end in the states labeled as aa, ab, ba and bb, respectively; as shown in the following and bb, respectively; as shown in the following FA FA

Page 12: Lecture # 7
Page 13: Lecture # 7

Example Example

Consider the language Consider the language L = {w belongs to {a,b}*: w does not end L = {w belongs to {a,b}*: w does not end

in in aaaa}.}. The language L may be expressed by the The language L may be expressed by the

regular expression regular expression

ΛΛ + a + b + + a + b + (a+b)*(ab+ba+bb)(a+b)*(ab+ba+bb)

This language may be accepted by the This language may be accepted by the following FA following FA

Page 14: Lecture # 7

Example Continued … Example Continued …

Page 15: Lecture # 7

Defining Languages Defining Languages (continued)… (continued)…

Method 5 Method 5 (Transition Graph) (Transition Graph)

DefinitionDefinition: : A Transition graph (TG), is a A Transition graph (TG), is a collection of the followings collection of the followings

1.1. Finite number of states, Finite number of states, at least oneat least one of which of which is start state and is start state and some (maybe none)some (maybe none) final final states. states.

2.2. Finite set of input letters (Finite set of input letters (ΣΣ) from which input ) from which input strings are formed. strings are formed.

3.3. Finite set of transitions that show how to go Finite set of transitions that show how to go from one state to another based on reading from one state to another based on reading specified specified substrings of input letterssubstrings of input letters, possibly , possibly even the even the null stringnull string ΛΛ..

Page 16: Lecture # 7

Note Note

It is to be noted that in TG there It is to be noted that in TG there may exist more may exist more than one pathsthan one paths for certain for certain stringstring, while there , while there may not exist any path for certain string as well. may not exist any path for certain string as well.

If there exists If there exists at least one pathat least one path for a certain for a certain string, starting from initial state and ending in a string, starting from initial state and ending in a final state, the string is supposed to be final state, the string is supposed to be accepted by the TG, otherwise the string is accepted by the TG, otherwise the string is supposed to be rejected. Obviously collection of supposed to be rejected. Obviously collection of accepted strings is the language accepted by accepted strings is the language accepted by the TG. the TG.

Page 17: Lecture # 7

Example Example Consider the Language L , defined over Consider the Language L , defined over ΣΣ = =

{a, b} of {a, b} of all strings including all strings including ΛΛ.. The The language L may be accepted by the following language L may be accepted by the following TG TG

RememberRemember: we have different paths for same : we have different paths for same string like string like aaaaΛΛ = = ΛΛaaaa = = aaΛΛaa = = [[ aa aa ]]

The language L may also be accepted by the The language L may also be accepted by the following TG following TG

Page 18: Lecture # 7

Example Continued … Example Continued …

TGTG11

TGTG22

Page 19: Lecture # 7

Example Example

Consider the following TGs Consider the following TGs

TGTG11

TGTG22

TGTG33

These TGThese TGss accept accept Empty Empty LanguageLanguage

Page 20: Lecture # 7

Example Example

Consider the language L of strings, Consider the language L of strings, defined over defined over ΣΣ={a, b}, ={a, b}, starting starting with b. with b. The language L may be The language L may be expressed by RE expressed by RE b(a + b)*b(a + b)* , may be , may be accepted by the following TG accepted by the following TG

Page 21: Lecture # 7

Example Example

Consider the language L of strings, defined Consider the language L of strings, defined over over ΣΣ={a, b}, ={a, b}, notnot ending in b. ending in b. The The language L may be expressed by RE language L may be expressed by RE ΛΛ + + (a + b)*a(a + b)*a , may be accepted by the , may be accepted by the following TG following TG

Page 22: Lecture # 7

Example Example

Consider the Language L of strings, Consider the Language L of strings, defined over defined over ΣΣ = {a, b}, = {a, b}, containing containing double a. double a.

The language L may be expressed by the The language L may be expressed by the following regular expression following regular expression

(a+b)* (aa) (a+b)*(a+b)* (aa) (a+b)*

This language may be accepted by the This language may be accepted by the following TG following TG

Page 23: Lecture # 7

Example Continued … Example Continued …

Multiple paths (options) are visible for Multiple paths (options) are visible for Double a.Double a.

Page 24: Lecture # 7

Example Example

Consider the language L of strings, defined Consider the language L of strings, defined over over ΣΣ={a, b}, ={a, b}, having double a or having double a or double bdouble b. .

The language L can be expressed by RE The language L can be expressed by RE (a+b)* (aa + bb) (a+b)*(a+b)* (aa + bb) (a+b)*

The above language may also be The above language may also be expressed by the following TGs.expressed by the following TGs.

Page 25: Lecture # 7

Example continued … Example continued …

Page 26: Lecture # 7

OR OR

Page 27: Lecture # 7

OROR

Page 28: Lecture # 7

Note Note

In the above TG if the states are not In the above TG if the states are not labeled then it may not be labeled then it may not be considered to be a single TG considered to be a single TG

Page 29: Lecture # 7

Thank You…Thank You…