Download - Finite Automata. Definition : Finite Automata is a five Tuple (Q,∑,δ,q0,F) – Q is a finite set called states – ∑ is a finite set called alphabets – Q.

Transcript

Finite Automata

Finite Automata

• Definition :• Finite Automata is a five Tuple (Q,∑,δ,q0,F)– Q is a finite set called states– ∑ is a finite set called alphabets– Q X ∑ -> Q is a transition function– Q0 is a start state– F is a set of accept states

Examples of Finite Automata

1

0

q1 q2

0 1

M1

Cont……..

• Formal Description of M1 :• ({ q1,q2},{0,1}, δ,q1,{q2}) The transition

function :•

• L(M1) = {ω | ω ends in a 1 }

0 1

q1 q1 q2

q2 q1 q2

Designing a Finite Automata

• Example 1 : Design a finite automata for the language that has strings with odd number of 1s.

• Step 1 : construct two states q-even(even so far) and q-odd (odd so far).

• Step2 : Make q-odd the accepting state because the language has odd number of ones.

Cont.......

• Step 3:1

1

qeven

0 0

qodd

• Example 2 : Language for all strings that contain substring 001.

• Step1 : Assign states q,q0,q00,q001.• Step2 : Start state q.• Step3 : Accept state q001.

Example 2: FA

q q0

1

q00

0

0

0 1

00,1

q001

Class of Regular Languages is Closed Under Union Operation

Let M1 recognize A1 where M1=(Q1,∑,δ1,q1,F1)

Let M2 recognize A2 where M2=(Q2,∑,δ2,q2,F2 )

Construct M to recognize A1 U A2 where M==(Q,∑,δ,q0,F)

Step 1: Q= {(r1,r2) | r1 Є Q1 and r2 Є Q2}

This is cartesian product of sets Q1 and Q2

Step2 : ∑ is the same for M1 and M2

Step3 : For each (r1,r2) Є Q and each a Є ∑ δ((r1,r2),a) = (δ(r1,a), δ(r2,a))Step 4: q0 is the pair (q1, q2)

Step5 : F= {(r1,r2) | r1 Є F1 and r2 Є F2}

Example Problem

• Each of the following languages is the intersection of two simpler language

• In each part construct DFA’s for the simpler language then combine them using the construction discussed in footnote 3 of pg46 in the book to give state diagram of a DFA for the language given.In all parts the alphabets are {a,b}

• .{ω | ω has atleast 3 a’s and atleast 2 b’s }

Solution

• M1 = ({q0,q1,q2,q3,},{a,b}, δ,q0,{q3})

• M2= ({q0,q1,q2,},{a,b}, δ,q0,{q2}) • Transition δ for M1 : Transition of M2:

a b

q0 q1 q0

q1 q2 q1

q2 q3 q2

q3 q3 q3

a b

q0 q0 q1

q1 q1 q2

q2 q2 q2

Step1 : Q= {(r1,r2) | r1 Є Q1 and r2 Є Q2}

Q = {(q0, q0),(q0, q1),(q0, q2), (q1, q0),(q1, q1),(q1, q2),(q2, q0),(q2, q1),(q2, q2),(q3, q0),(q3, q1), (q3, q2)}

Step2 : δ ((q0, q0),a) = (q1, q0 )

δ ((q0, q1),a) = (q1, q1 )

And so on…..

a b

q0, q0 q1, q0 q0, q1

q0, q1 q1, q1 q0, q2

q0, q2 q1, q2 q0, q2

q1, q0 q2, q0 q1, q1

q1, q1 q2, q1 q1, q2

q1, q2 q2, q2 q1, q2

q2, q0 q3, q0 q2, q1

q2, q1 q3, q1 q2, q2

q2, q2 q3, q2 q2, q2

Q3, q0 q3, q0 q3, q1

q3, q1 q3, q1 q3, q2

q3, q2 q3, q2 q3, q2

Conversion of NFA to DFA

1

a

2

a,bb

a b

{1} {1},{2} {2}

{2} e {1}

Construction

• N= (Q1,∑,δ1,q1,F1)

• Q1 = ({1},{2})

• DFA M = (Q2,∑,δ2,q2,F2)

• Q2 = P(Q1)

• Q2 = {{e},{1},{2},{1,2}}

a b

{e} {e} {e}

{1} {1,2} {2}

{2} {e} {1}

{1,2} {1,2} {1,2}

1 1,22

a

b

b

e

a,b

aa,b

Regular Expression to NFA

ε

ε

ε

R

S

ε

ε

L(R)UL(S)

L(R)L(S)

R

S

ε

L(R*)

R

εε

ε

ε

Example

• (0U1)*000(0U 1)*Step 1 :

0

1

(0U1)

ε

ε

0

1

(0U1)*

ε

ε

0

1

ε

εε

0 ε 0ε 0

ε

0

1

εε

0 ε 0ε 0

ε

ε

ε

ε

0

ε

ε

NFA to Regular Expressions

1

a

2

bb

a

1

a

2

bb

a

S

Accept

2

Accept

S

aUba*b

Ea*b

S Accepta*b(aU(ba*b))*

E

HomeWork

Work out the Problems in Exercise 2 .