finite state automata

Post on 25-Feb-2016

95 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Finite State Automata. Formal Specification of Languages. Generators Context-free Grammars Regular Expressions Recognizers Parsers, Push-down Automata Finite State Automata FSA is a mechanism to recognize a set of valid inputs before carrying out an action. - PowerPoint PPT Presentation

TRANSCRIPT

CS480(Prasad) L9FSA 1

Finite State Automata

CS480(Prasad) L9FSA 2

Formal Specification of Languages

• Generators• Context-free Grammars• Regular Expressions

• Recognizers• Parsers, Push-down Automata• Finite State Automata

• FSA is a mechanism to recognize a set of valid inputs before carrying out an action.

• FSA is a notation for describing a family of language recognition algorithms.

CS480(Prasad) L9FSA 3

OP

Parity Problem

)( )1()()0(

).(

1s. ofnumber even contains )(:

}1,0{*

*

parityparityparityparity

parity

paritybooleanparity

EP

1

10 0

CS480(Prasad) L9FSA 4

Basic Features

• Consumes the entire input string.• Remembers the parity of the bit string by

abstracting from the number of 1s in the string.• Finite amount of memory required for this

purpose.• Observe that counting requires unbounded memory,

while computing the parity requires very small and fixed amount of memory.

• Accepts/Rejects the input in a deterministic fashion.

CS480(Prasad) L9FSA 5

• State• Indicates the status of the machine after consuming

some portion of the input.• Summarizes the history of the computation that is

relevant to the future course of action.• Initial / Start State• Final / Accepting state• State Transition

Even Parity Odd Parity

10

CS480(Prasad) L9FSA 6

Q: Finite set of statesFinite Alphabet : Transition function total function from Qx to Q : Initial/Start StateF : Set of final/accepting state

Deterministic Finite State Automaton (DFA)

),,,,( 0 FqQM

0q

CS480(Prasad) L9FSA 7

Operation of the machine

• Read the current letter of input under the tape head.

• Transit to a new state depending on the current input and the current state, as dictated by the transition function.

• Halt after consuming the entire input.

0 0 1

0q

Input Tape

Finite Control

CS480(Prasad) L9FSA 8

, where],[ Qqq• Machine configuration:

• Yields relation:

• Language:

Associating Language with the DFA

]),,([ ],[ *M aqaq

} ],[ ],[ |{ *M0

* Fqqq

CS480(Prasad) L9FSA 9

Examples

CS480(Prasad) L9FSA 10

• Set of strings over {a,b} that contain bb

• Design states by parititioning *.• Strings containing bb q2• Strings not containing bb

– Strings that end in b q1– Strings that do not end in b q0

– Initial state: q0– Final state: q2

)()( babbba

CS480(Prasad) L9FSA 11

q2

State Diagram and Table

q0 q1

ab

a

b

a

b a b

q0 q0 q1

q1 q0 q2

q2 q2 q2

}2{},{

}2,1,0{

qFba

qqqQ

],1[],0[ * qaabq

CS480(Prasad) L9FSA 12

q0 q2

Strings over {a,b} that do not contain bb

q1

ab

a

b

a

b a b

q0 q0 q1

q1 q0 q2

q2 q2 q2

}1,0{},{

}2,1,0{

qqFba

qqqQ

],0[],0[ * qbaq

CS480(Prasad) L9FSA 13

DFA for the complement of L given DFA for LLet M = (Q,,,q0,F) be a DFA. Then, M’ = (Q,,,q0,Q-F) is a DFA with

L(M’) = * - L(M).

Implication: Languages associated with DFAs are closed under complementation.

(Recall that languages associated with regular expressions are closed under union, concatenation, and Kleene Star operations, by definition.)

CS480(Prasad) L9FSA 14

Strings over {a,b} containing even number of a’s and odd number of b’s.

*

Ea OaEb Ob ObEb

b

b

b

b

aaa a

[Oa,Ob]

[Ea,Eb] [Ea,Ob]

[Oa,Eb]

CS480(Prasad) L9FSA 15

(ab)*c

*

valid prefix invalid prefixend_a

a

b

b

a,b,c

a,cc

Err

Eb Ea

Ec

end_b end_c

a,b,c

a

c

b

CS480(Prasad) L9FSA 16

(ab)*c

*

valid prefix invalid prefixend_a

a

b

b

a,b,c

a,cc

Err

Eb Ea

Ec

end_b end_c

a,b,c

CS480(Prasad) L9FSA 17

Nondeterministic Finite Automata

qi qj

qkq

qi qja a

aDFA

NFA

a

relationsubset function total)(:

function total :

QQQΡowQ

QQ

NFA

NFA

DFA

CS480(Prasad) L9FSA 18

• How do we associate a language with an NFA?• Every DFA is an NFA. However, does non-

determinism make NFAs strictly more expressive (powerful) than DFAs?

DFA: Unique computation for a given stringNFA: Accept if there exists an accepting

computation

)()( DFAsLNFAsL

CS480(Prasad) L9FSA 19

q2

NFA State Diagram (Strings over {a,b} ending in bb)

q0 q1

a

b b

a b

q0 {q0} {q0,q1}

q1 {q2}

q2

}2{},{

}2,1,0{

qFba

qqqQ

bbba )(

b

CS480(Prasad) L9FSA 20

],2[],1[],0[],0[ qbqbbqabbq Halts in accepting state after consuming the input.

],0[],0[],0[],0[ qbqbbqabbq ],1[],0[],0[],0[ qbqbbqabbq

Halts in non-accepting state after consuming the input.

)(NFALabb

CS480(Prasad) L9FSA 21

NFA State Diagram (a U b)* bb (a U b)*

q2q0 q1

a

b b

b ba

q2q0 q1

a

b b

ba

a

DFA

CS480(Prasad) L9FSA 22

NFA for (a U b)* (aa U bb) (a U b)*

q2q0 q1

a

a a

b ba

q22q11b b

ba

CS480(Prasad) L9FSA 23

Introducing -transitions into NFA

• A -transition causes the machine to change its state non-deterministically, without consuming any input.

)(}){(: QPQ

)-()()( sNFALNFAsLDFAsL

CS480(Prasad) L9FSA 24

Closure Properties of NFA-s

M1

M1

MM2

M2

LL(M1) U LL(M2)

LL(M1) LL(M2)

LL(M)*

CS480(Prasad) L9FSA 25

}|{for NFA niba ii

a0 a1

b1

a2

b2

a3

b3

a aa a

b

b b b

a3

b3

an

bn

This construction cannot be generalized to recognize }0|{ iba ii

because the machine will have infinite number of states.

b b b

top related