Post on 25-Feb-2016
description
Dr. Eng. Farag Elnagahyfarahelnagahy@hotmail.c
omOffice Phone: 67967
King ABDUL AZIZ University
Faculty Of Computing and Information Technology
CPCS 222Discrete Structures IModeling ComputationModeling ComputationFinite-State MachinesFinite-State Machines
22
Finite-State Machines (Finite-State Machines (FSMFSM))finite-state machine is one type of finite-state machine is one type of structuresstructures that used in that used in models of computationmodels of computation. . We will study two types of finite-state We will study two types of finite-state machinesmachines finite-state machine with finite-state machine with outputoutput finite-state machine with finite-state machine with no outputno output (has final (has final state)state)
FSM is Used to model many kinds of FSM is Used to model many kinds of machinesmachines
o Vending machinesVending machineso Delay machinesDelay machineso Binary addersBinary adderso Language recognizerLanguage recognizero Spell checkingSpell checkingo Recognizing speech, etc.Recognizing speech, etc.
33
Finite-State Machines with Finite-State Machines with OutputsOutputs
A finite-state machine with output A finite-state machine with output M = ( M = ( SS, , II, , OO, , ff, , gg, , ss0 0 ) ) consists of:consists of:
A finite set A finite set SS of of statesstates A finite A finite inputinput alphabet alphabet II A finite A finite outputoutput alphabet alphabet OO A A transitiontransition function function ff that assigns to each that assigns to each
sate and input pair a new statesate and input pair a new state An An outputoutput function function gg that assigns to each that assigns to each
sate and input pair an outputsate and input pair an output An An initialinitial state state ss00
44
The following The following state tablestate table describes a finite- describes a finite-state machine with S={sstate machine with S={s00,s,s11,s,s22,s,s33} , I={0,1} } , I={0,1} and O={0,1} the values of the transition and O={0,1} the values of the transition function function ff are displayed in the first two are displayed in the first two columns, and the values of the output function columns, and the values of the output function gg are displayed in the last two columns. are displayed in the last two columns.
State State diagramdiagram
State tableState table
Finite-State Machines with Finite-State Machines with OutputsOutputs
55
Finite-State Machines with Finite-State Machines with OutputsOutputs
Construct the Construct the state table state table for thefor the finite-state finite-state machine with the following state diagram. machine with the following state diagram.
66
Finite-State Machines with Finite-State Machines with OutputsOutputs
Find the Find the output stringoutput string generated by the generated by the following finite-state machine if the following finite-state machine if the input stringinput string is is 101011101011. .
The obtained The obtained outputoutput is is 001000001000 as shown in the as shown in the table.table.
77
Finite-State Machines with Finite-State Machines with OutputsOutputs
Unit-Delay Unit-Delay MachineMachine
Unit-Delay MachineUnit-Delay Machine produces as output the produces as output the input string delayed by a specific amount of input string delayed by a specific amount of time.time.InputInput: x: x11xx22xx33……..x……..xn n outputoutput: : 00xx11xx22xx33……..x……..xn-1n-1
Previous input is 1
Previous input is 0
88
Finite-State Machines with Finite-State Machines with OutputsOutputs
Construct a finite-state machine that adds two Construct a finite-state machine that adds two integers using their binary expansion.integers using their binary expansion.InputInput11: (x: (xn……..n……..xx11xx00))2 2 InputInput22: (y: (yn……..n……..yy11yy00))2 2
For simplicity assumed that xFor simplicity assumed that xnn=y=ynn=0=0
A finite-state machine for A finite-state machine for additionaddition
Previous carry is 1
Previous carry is 0
99
Finite-State Machines with Finite-State Machines with OutputsOutputs
Construct a finite-state machine that gives a Construct a finite-state machine that gives a 11 as its as its current outputcurrent output bit if and only if the bit if and only if the last last threethree bits bits received are received are all 1sall 1s. .
1010
ExercisesExercises
pp. 802-803pp. 802-803
1-61-6
1111
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Finite-state machine with no output is called Finite-state machine with no output is called finite- state finite- state automaton (automaton (plural isplural is automata) automata)
This machine does not produce output, but it This machine does not produce output, but it has a set for final states.has a set for final states.
The The finalfinal states are indicated in state states are indicated in state diagrams by using diagrams by using double circlesdouble circles..
1212
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
A finite-state A finite-state automaton automaton M = ( M = ( SS, , II, , ff, , ss00 , , FF ) ) consists of:consists of:
A finite set A finite set SS of of statesstates A finite A finite inputinput alphabet alphabet II A A transitiontransition function function ff that assigns a next that assigns a next
state to every pair of state and input (so state to every pair of state and input (so that that
f: f: SSxxIISS) ) An An initialinitial state (start state) state (start state) ss0 0 and and A subset A subset FF of of SS consisting of consisting of finalfinal states states
((acceptingaccepting states) states)
1313
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Construct the state diagram for the finite-state Construct the state diagram for the finite-state automaton M = ( automaton M = ( SS, , II, , ff, , ss00 , , FF ) where ) where SS={s={s00,s,s11,s,s22,s,s33} , } , II={0,1} ,={0,1} ,FF={s={s00,s,s33}, and the }, and the transition function transition function ff is given in the following is given in the following table.table.
1414
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Set of stringsSet of strings
Suppose that A and B are subsets of V*, where Suppose that A and B are subsets of V*, where V is a vocabulary. The V is a vocabulary. The concatenationconcatenation of of AA and and BB, denoted by , denoted by ABAB, is the set of all strings of the , is the set of all strings of the form xy, where x is a string in A and y is a form xy, where x is a string in A and y is a string in B.string in B.
V*V* is the set of all words over v. is the set of all words over v.
ExampleExample A={0,11} and B={1,10,110} find AB A={0,11} and B={1,10,110} find AB and BA.and BA.
AB={01,010,0110,111,1110,11110}AB={01,010,0110,111,1110,11110}BA={10,111,100,1011,1100,11011}BA={10,111,100,1011,1100,11011}
1515
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
The empty string or null string (The empty string or null string (), is the string ), is the string containing no symbol.containing no symbol. is different from is different from ( (empty setempty set))
AAnn n=0,1,2,….. n=0,1,2,….. concatenationconcatenation AAAAAAAAA AAAAAAAAAAA00={={}}AAn+1n+1= A= An n AA
ExampleExampleA={1,00} find AA={1,00} find Ann for n=0,1,and 3. for n=0,1,and 3.AA00={={}}AA11= A= A0 0 A= {A= {}A= {1,00} }A= {1,00} AA2 2 =A=A1 1 A={A={1111,,100100,,001001,,00000000}}AA3 3 = A= A2 2
A={A={11111,1,111100,00,1001001,1,10010000,00,0010011,1,00100100,00,000000001,1,0000000000}00}
1616
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Language recognition by finite-state machinesLanguage recognition by finite-state machines
A string A string x x is said to be is said to be recognizedrecognized or or acceptedaccepted by the machine M = ( by the machine M = ( SS, , II, , ff, , ss00 , , FF ) if it takes ) if it takes the initial state the initial state ss00 to a to a finalfinal state,that is, f(s state,that is, f(s00,x) ,x) is a state in F. is a state in F.
The Language The Language recognizedrecognized or or acceptedaccepted by the by the machine M, denoted by machine M, denoted by L(M)L(M), is the set of all , is the set of all strings that are recognized by M.strings that are recognized by M.
Two finite-state automata are called Two finite-state automata are called equivalentequivalent if they if they recognizerecognize the the same same languagelanguage..
1717
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Language recognition by finite-state machinesLanguage recognition by finite-state machinesDetermine the languages recognized by the Determine the languages recognized by the finite-state automata Mfinite-state automata M11, and M, and M22 in the in the following figure.following figure.
L(ML(M11)={1)={1nn |n=0,1,2, |n=0,1,2,…}…}Concatenations Concatenations 111111111111
MM22
MM11
L(ML(M22)={1,01)={1,01}}
1818
Examp1:Examp1: Construct a deterministic finite-state Construct a deterministic finite-state automaton that recognizes the set of all bit automaton that recognizes the set of all bit strings such that the first bit is strings such that the first bit is 00 and and all all remaining bitsremaining bits are are 1’s1’s..
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
1919
Examp2:Examp2: Construct a deterministic finite-state Construct a deterministic finite-state automaton that recognizes the set of all bit automaton that recognizes the set of all bit strings that contain exactly one 0.strings that contain exactly one 0.
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
2020
Examp3:Examp3: Determine the set of bit strings Determine the set of bit strings recognized by the following deterministic recognized by the following deterministic finite-state automaton.finite-state automaton.
If the bit string ends in If the bit string ends in 00, you end in state , you end in state ss22. If . If the bit string ends in 1, you end in state the bit string ends in 1, you end in state ss11. . Therefore,Therefore,thisthis automatonautomaton recognizes all bit strings that recognizes all bit strings that end in 0end in 0..
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
2121
Examp4:Examp4: Determine the set of bit strings Determine the set of bit strings recognized by the following deterministic recognized by the following deterministic finite-state automaton.finite-state automaton.
If the bit string has If the bit string has two consecutivetwo consecutive 00’s or two ’s or two consecutive consecutive 11’s, you end in state ’s, you end in state ss33. . If the bit string If the bit string has no two consecutivehas no two consecutive 00’s or ’s or two consecutive two consecutive 11’s, you end in either state ’s, you end in either state ss11 or or ss22. Therefore, . Therefore, thisthis automatonautomaton recognizes all recognizes all bit strings that alternate bit strings that alternate 00’s and ’s and 11’s.’s.
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
2222
Examp5:Examp5: Determine the set of bit strings Determine the set of bit strings recognized by the following deterministic recognized by the following deterministic finite-state automaton.finite-state automaton.
The string must end in The string must end in 0101 in order to be in order to be recognized by recognized by thisthis automatonautomaton. If the string . If the string ends in 11, the string ends in state ends in 11, the string ends in state ss00. If the . If the string ends in 0, the string ends in state string ends in 0, the string ends in state ss11..
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
2323
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Types of finite-state automata Types of finite-state automata
DeterministicDeterministicFor each pair of state and input value there is a For each pair of state and input value there is a unique next stateunique next state given by transition function. given by transition function.
NondeterministicNondeterministicFor each pair of state and input value there For each pair of state and input value there may be may be several possible next statesseveral possible next states given by given by transition function.transition function.
2424
Find the Find the state diagramstate diagram for the nondeterministic for the nondeterministic finite-state automaton with the following state finite-state automaton with the following state table.table.
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
2525
Finite-State Machines with no Finite-State Machines with no OutputsOutputs
Find the Find the state diagramstate diagram for the nondeterministic for the nondeterministic finite-state automaton with the following state finite-state automaton with the following state table.table.
2626
ExercisesExercises
pp. 814-817pp. 814-817
1111-1211-1216-2216-2223-2423-2430-3130-31