ICS-252 Discrete Structure II

  ICS-252 Discrete Structure II Lecture 9

  Assistant Professor, Department of Computer Science & Engineering, University of Hail, KSA.

  Email: s hagahmoodi@uoh edu sa Email: [email protected]

  ICS ‐252       Dr. Salah Omer, Assistant  Professor,  CSSE, University  of  Hail.  Outlines

  • Finite state machines with output • Finite state machines with output
  • Finite state machines with no ou>DFA
  • DMA 796 813 • DMA 796-813

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  Finite-State Machines with Output Finite-State Machines with Output: A finite state machine

  (FSM) is an abstract model of a machine with a primitive (sometimes read-only) internal memory. These are FSM that produce output. FSM are used extensively in many areas including electrical engineering linguistics computer areas including electrical engineering, linguistics computer science, philosophy, biology, mathematics and logic. In computer science, finite state machines are widely used in modeling of application behavior, design of hardware digital systems, software engineering, compilers, network protocols, and the study of computation and languages.

  Definition: Definition: A finite-state machine M = {S I O f g s A finite state machine M {S, I, O, f, g, s } consists } 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 state and input pair a new state, an output function g ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  3 Finite-State Machines with Output

  That assigns to each state and input pair an output, and an initial state s .

  Example: The state table shown in table describes a finite state machine with S ={s , s s s } , I = {0,1}, O={0,1}.

  1, 2 ,

  3 The values of the transition function f and the values of the

  output function g are shown in table. Draw the state diagram from this state table.

  Table  2 f g State Input Input                                          1                              1  

  1 S S S 1

  1

  1 S S S 1 3                              1 S S S 2 1 2                              0

  S S S 3 2 ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  1

  Finite-State Machines with Output Solution: see the state diagram at page DMA- 799.

  Example: Draw the state table from the state diagram obtained in the above example.

  S 1 S 3 S start S 2 ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  5 Finite-State Machines with No Output

  One of the most important application of finite-state machines is in language recognition. This application plays a fundamental role in the design and construction of compilers for programming languages. It does not have any output. output

  Definition: 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.

  Example: Let A= {0, 11} and B= {1, 10, 110}, Find AB and BA Solution: AB= {01, 010, 0110, 111, 1110, 11110} and BA={10, 111, 100, 1011, 1100, 11011} ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  Finite-State Machines with No Output n+1 n

  Example: A = { } and A = A A for n = 0, 1, 2……

  n

  Then Let A={1, 00}. Find A for only n= 0, 1, 2, and 3 Solution:

  n+1 n+1 n n

  A A = { }, we know that A { } e kno that A = A A A A

  0+1

  A = A A= {} {1, 00} = {1, 00}

  1+1

  1

  2

  1

  n= 1 => A = A A => A = A A = {1, 00} {1,00} = {11, 100, 001, 0000}

  3

2 A = A A = {11, 100, 001, 0000} {1, 00} { , , , } { , }

  = {111, 1100, 1001, 10000, 0011, 00100, 00001, 000000 } ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  7 Deterministic Finite-State Automata (DFA)

  Definition: A finite-state machine with no output is called

  finite-state automata. It also called deterministic finite-state automata (DFA). A DFA M=(S, I, f, s , F ) consists of a finite set S of states, a finite input alphabet I, a transition 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: S x I -> S), an initial or start state s , and a subset F of S consisting of final state. We can represent finite-state automata using either state tables or state diagram. Final states are indicated in state diagrams

  by using double circles.

  Example 4: Construct the state diagram for the finite-state

  automata M= (S, I, f, s , F) , where S = {s , s , s , s }, I=

  1

  2

  3

  {0,1}, F= {s , s } and the transition function f is given in

  3 table 1 (see at page DMA- 806). ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  Deterministic Finite-State Automata (DFA) Solution: State diagram is shown in figure 1 at page DMA- 806. Language recognition by DFA: A string x is said to be

  recognized or accepted by the machine M= (S, I, f, s i d t d b th hi M (S I f , F) if

  F) if it takes the initial state s to the final state, that is, f(s , 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.

  E Example: l Determine the languages recognized by the finite- D t i th l i d b th fi it state automata M1, M2, M3 in figure 2 at page 807. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  9 Deterministic Finite-State Automata (DFA)

  Solution: M1) In M1 the final state is S , The only strings that

  take S to itself are those consisting of {}, or more consecutive 1s. Hence, L(M1)= { ,1, 11, 111, 1111…..} or

  λ n

  L(M1) {1 | n 0,1,2……….} L(M1)= {1 | n= 0,1,2……….} M2) The only final state of M2 is S . The only strings that take

  2 S to S are 1 and 01. Hence L(m2) = {1, 01}.

2 M3) The final states of M3 are S and S . The only strings

  3 λ

  that take S to itself are , 0, 00, 000 …….. That is , any string of zero or more consecutive 0s. In addition the only strings that takes S t i th t t k S t S to S are a string of zero or more t i f

  3 n n

  consecutive 0s, followed by 10, Hence, L(M3)={0 , 0 10x | n= 0,1,2,….. And x is any string with combination of 0 and 1} ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  Non Deterministic Finite-State Automata (NDFA) Non deterministic finite-state of automata (NDFA): In DFA

  for each pair of state and input value there is a unique next state given by the transition function. But in NDFA there may be several possible next states for each pair of input may be several possible next states for each pair of input value and state.

  Definition: A NDFA M= (S, I, f, s , F) consists of a set S of

  states, an input alphabet I, a transition function f that assigns a set of states to each pair of state and input (so that f: S x I -> P(S)), a starting state s ,and a subset F of S consisting of the final states. consisting of the final states.

  Example 9: Find the state diagram for the NDFA with the

  state table shown in table 2 (at page DMA-812). The final states are s and s .

  2 ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  3 11 Non Deterministic Finite-State Automata (NDFA) Solution: See figure 6 at page DMA-812.

  Example 10: Find the state table for the NDFA with the state diagram shown in figure 7.

  Solution: See Table 3 at page DMA-812.

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail. 

  Home Work Question 1: construct a DFA that recognized each of these languages.

  a) The set of bit strings that begin with two 0s.

  b) The set of bit strings that contain two consecutive 0s.

  c) The set of bit strings that do not contain two consecutive 0s.

  d) The set of bit strings that end with two 0s.

  e) The set of bit strings that contain at least two 0s.

  Question 2: Let A={0,11}, and B={00, 01}. Find each of these sets.

  2

  3

  a) AB, b) BA, c) A

  d) B Question 3: solve questions from 16-22 at page DMA-814-815.

  Question 4: solve questions from 43-49 at page DMA-816. ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.  13 Thank you for your Attention.

  ICS ‐252       Dr. Salah Omer, Assistant Professor, CSSE, University  of  Hail.