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: s.hagahmoodi@uoh.edu.sa
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 output
•
DFA
•
NDFA
•
DMA 796 813
•
DMA 796-813
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:A finite-state machine M = {S I O f g s0} consists
Definition:A finite state machine M {S, I, O, f, g, s0} 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
3 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Finite-State Machines with Output
That assigns to each state and input pair an output, and an initial state s0.
Example: The state table shown in table describes a finite
state machine with S ={s0 , s1,s2 , s3 } , I = {0,1}, O={0,1}. 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.
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.
S0
S1
S3
start
5 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
S2
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}
Finite-State Machines with No Output
= {111, 1100, 1001, 10000, 0011, 00100, 00001, 000000 }
7 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
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, s0, 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 s0, 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
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
i d t d b th hi M (S I f F) if recognized or accepted by the machine M= (S, I, f, s0, F) if it takes the initial state s0to the final state, that is, f(s0, 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 l D t i th l i d b th fi it
Example:Determine the languages recognized by the
finite-state automata M1, M2, M3 in figure 2 at page 807.
9 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Deterministic Finite-State Automata
(DFA)
Solution:M1) In M1 the final state is S0, The only strings that
take S0to itself are those consisting of {}, or more
consecutive 1s. Hence, L(M1)= { ,1, 11, 111, 1111…..} or string of zero or more consecutive 0s. In addition the only
t i th t t k S t S t i f
λ
strings that takes S0 to S3are a string of zero or more consecutive 0s, followed by 10, Hence, L(M3)={0n, 0n10x |
n= 0,1,2,….. And x is any string with combination of 0 and 1}
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, s0, 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 s0,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 s2and s3.
11 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
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.
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.
a) AB, b) BA, c) A2 d) B3
Question 3:solve questions from 16-22 at page DMA-814-815.
Question 4:solve questions from 43-49 at page DMA-816.
13 ICS‐252 Dr. Salah Omer, Assistant Professor, CSSE, University of Hail.
Thank you for your Attention.
14