Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Eng. Farag Elnagahy Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.

Similar presentations


Presentation on theme: "Dr. Eng. Farag Elnagahy Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222."— Presentation transcript:

1 Dr. Eng. Farag Elnagahy farahelnagahy@hotmail.com Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222 Discrete Structures I Modeling Computation Finite-State Machines

2 2 Finite-State Machines (FSM) finite-state machine is one type of structures that used in models of computation. We will study two types of finite-state machines  finite-state machine with output  finite-state machine with no output (has final state) FSM is Used to model many kinds of machines FSM is Used to model many kinds of machines oVending machines oDelay machines oBinary adders oLanguage recognizer oSpell checking oRecognizing speech, etc.

3 3 Finite-State Machines with Outputs A finite-state machine with output M = ( S, I, O, f, g, s 0 ) M = ( S, I, O, f, g, s 0 ) consists of:  A finite set S of states  A finite input alphabet I  A finite output alphabet O  A transition function f that assigns to each sate and input pair a new state  An output function g that assigns to each sate and input pair an output  An initial state s 0

4 4 The following state table describes a finite-state machine with S={s 0,s 1,s 2,s 3 }, I={0,1} and O={0,1} the values of the transition function f are displayed in the first two columns, and the values of the output function g are displayed in the last two columns. State diagram State table Finite-State Machines with Outputs

5 5 Construct the state table for the finite-state machine with the following state diagram.

6 6 Finite-State Machines with Outputs Find the output string generated by the following finite-state machine if the input string is 101011. The obtained output is 001000 as shown in the table.

7 7 Finite-State Machines with Outputs Unit-Delay Machine Unit-Delay Machine produces as output the input string delayed by a specific amount of time. Input: x 1 x 2 x 3 ……..x n output: 0x 1 x 2 x 3 ……..x n-1 Previous input is 1 Previous input is 0

8 8 Finite-State Machines with Outputs Construct a finite-state machine that adds two integers using their binary expansion. Input 1 : (x n…….. x 1 x 0 ) 2 Input 2 : (y n…….. y 1 y 0 ) 2 For simplicity assumed that x n =y n =0 A finite-state machine for addition Previous carry is 1 Previous carry is 0

9 9 Finite-State Machines with Outputs Construct a finite-state machine that gives a 1 as its current output bit if and only if the last three bits received are all 1s.

10 10 Exercises pp. 802-803 1-6

11 11 Finite-State Machines with no Outputs  Finite-state machine with no output is called finite- state automaton (plural is automata)  This machine does not produce output, but it has a set for final states. The final states are indicated in state diagrams by using double circles. The final states are indicated in state diagrams by using double circles.

12 12 Finite-State Machines with no Outputs A finite-state automaton M = ( S, I, f, s 0, F ) consists of:  A finite set S of states  A finite input alphabet I  A transition function f that assigns a next state to every pair of state and input (so that f: SxI  S)  An initial state (start state) s 0 and  A subset F of S consisting of final states (accepting states)

13 13 Finite-State Machines with no Outputs Construct the state diagram for the finite-state automaton M = ( S, I, f, s 0, F ) where S={s 0,s 1,s 2,s 3 }, I={0,1},F={s 0,s 3 }, and the transition function f is given in the following table.

14 14 Finite-State Machines with no Outputs Set of strings Suppose that A and B are subsets of V*, where V is a vocabulary. The concatenation of A and B, denoted by AB, is the set of all strings of the form xy, where x is a string in A and y is a string in B. V* is the set of all words over v. Example A={0,11} and B={1,10,110} find AB and BA. AB={01,010,0110,111,1110,11110}BA={10,111,100,1011,1100,11011}

15 15 Finite-State Machines with no Outputs The empty string or null string ( ), is the string containing no symbol. is different from  (empty set) is different from  (empty set) A n n=0,1,2,….. concatenation AAAAAAAAA A 0 ={ } A n+1 = A n A Example A={1,00} find A n for n=0,1,and 3. A 0 ={ } A 1 = A 0 A= { }A= {1,00} A 2 =A 1 A={11,100,001,0000} A 3 = A 2 A={111,1100,1001,10000,0011,00100,00001, 000000}

16 16 Finite-State Machines with no Outputs Language recognition by finite-state machines  A string x is said to be recognized or accepted by the machine M = ( S, I, f, s 0, F ) if it takes the initial state s 0 to a final state,that is, f(s 0,x) is a state in F.  The Language recognized or accepted by the machine M, denoted by L(M), is the set of all strings that are recognized by M.  Two finite-state automata are called equivalent if they recognize the same language.

17 17 Finite-State Machines with no Outputs Language recognition by finite-state machines Determine the languages recognized by the finite-state automata M 1, and M 2 in the following figure. L(M 1 )={1 n |n=0,1,2,…} Concatenations 111111 M2M2M2M2 M1M1M1M1 L(M 2 )={1,01}

18 18 Examp1: Construct a deterministic finite-state automaton that recognizes the set of all bit strings such that the first bit is 0 and all remaining bits are 1’s. Finite-State Machines with no Outputs

19 19 Examp2: Construct a deterministic finite-state automaton that recognizes the set of all bit strings that contain exactly one 0. Finite-State Machines with no Outputs

20 20 Examp3: Determine the set of bit strings recognized by the following deterministic finite-state automaton. If the bit string ends in 0, you end in state s 2. If the bit string ends in 1, you end in state s 1. Therefore, this automaton recognizes all bit strings that end in 0. Finite-State Machines with no Outputs

21 21 Examp4: Determine the set of bit strings recognized by the following deterministic finite-state automaton. If the bit string has two consecutive 0’s or two consecutive 1’s, you end in state s 3. If the bit string has no two consecutive 0’s or two consecutive 1’s, you end in either state s 1 or s 2. Therefore, this automaton recognizes all bit strings that alternate 0’s and 1’s. Finite-State Machines with no Outputs

22 22 Examp5: Determine the set of bit strings recognized by the following deterministic finite-state automaton. The string must end in 01 in order to be recognized by this automaton. If the string ends in 11, the string ends in state s 0. If the string ends in 0, the string ends in state s 1. Finite-State Machines with no Outputs

23 23 Finite-State Machines with no Outputs Types of finite-state automata Deterministic For each pair of state and input value there is a unique next state given by transition function. Nondeterministic For each pair of state and input value there may be several possible next states given by transition function.

24 24 Find the state diagram for the nondeterministic finite- state automaton with the following state table. Finite-State Machines with no Outputs

25 25 Finite-State Machines with no Outputs Find the state diagram for the nondeterministic finite- state automaton with the following state table.

26 26 Exercises pp. 814-817 111-1216-2223-2430-31


Download ppt "Dr. Eng. Farag Elnagahy Office Phone: 67967 King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222."

Similar presentations


Ads by Google