Download presentation
Presentation is loading. Please wait.
Published byDarlene Warner Modified over 9 years ago
1
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
2
Introduction # Many kinds if machines, including components in computers, can be modeled using a structure called a finite- state machine. # Finite-state machines are used extensively in applications in computer science and data networking. For example, FSM are the basis for programs for spell checking, grammar checking, indexing or searching large bodies of text, recognizing speech, ……
3
Remark: We can use a state table to represent the values of the transition function f and the output function g for all pairs of states and input. Definition: A finite-state machine M = {S, I, O, f, g, s 0 } consists of: finite set S of states, finite input alphabet I, finite output alphabet O, transition function f that assigns to each state and input pair a new state, output function g that assigns to each state and input pair an output, initial state s 0.
4
Example: Given a finite state machine with S ={s 0, s 1,s 2, s 3 }, 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
5
Representation of FSM We use state diagram to represent FSM. State diagram is a directed graph with labeled edges. In this diagram, each sate is represented by a circle. Arrows labeled with the input and output pair are shown for each transition. Example: Example: Draw the state diagram for the finite-state machine S ={s0, s1,s2, s3 }, I = {0,1}, O={0,1} with the following state table.
6
s0s0 s1s1 0 f(S 0,0)=S 1 s0s0 s1s1 0 f(S 0,1)=S 0 1 s0s0 s1s1 0 g(S 0,0)=1 s0s0 s1s1 0 g(S 0,1)=0 1,1,0,1 1 S ={s0, s1,s2, s3 } s0s0 s1s1 s2s2 s3s3
7
s0s0 s1s1 0 1,0,1 s3s3 0,1 1,1 s0s0 s1s1 0 1,0,1 s3s3 0,1 1,1 s2s2 0,0 1,1 s0s0 s1s1 0 1,0,1 s3s3 0,1 1,1 s2s2 0,0 1,1 0,0 1,0
9
Example: Construct the state table for the finite-state machine with the state diagram shown in Figure
11
Home Work
13
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. 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.
14
Example: Let A= {0, 11} and B= {1, 10, 110}, Find AB and BA. Solution: 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. x=0 and y=1, 10, or 110 then xy= 01, 010, or 0110 x=11 and y=1, 10, or 110 then xy= 111, 1110, or 11110 So, AB= {01, 010, 0110, 111, 1110, 11110} and BA={10, 111, 100, 1011, 1100, 11011}(by similar way). 110110 00 10 100 110 1111 111 1011 110 011 110111 101001011 110110011011
15
Example: Given A 0 = { } and A n+1 = A n A, for n = 0, 1, 2…… Then let A={1, 00}. Find A n for only n= 0, 1, 2, and 3 Solution: A 0 = { }, we know that A n+1 = A n A n = 0 A 0+1 = A 0 A= {} {1, 00} = {1, 00} n = 1 A 1+1 = A 1 A A 2 = A 1 A = {1, 00} {1,00} = {11, 100, 001, 0000} A 3 = A 2 A = {11, 100, 001, 0000} {1, 00} = {111, 1100, 1001, 10000, 0011, 00100, 00001, 000000 }
16
Let A={0,11}, and B={00, 01}. Find each of these sets. (a) AB, (b) BA, (c) A 2 (d) B 3 Home Work
17
Deterministic Finite-State Automata A finite-state machine with no output is called finite-state automata. It also called deterministic finite-state automata (DFA). # We can represent finite-state automata using either state tables or state diagram. # Final states are indicated in state diagrams by using double circles. Definition: A DFA M=(S, I, f, s 0, F ) consists of: finite set S of states, finite input alphabet I, transition function f that assigns a next state, initial or start state s 0, subset F final state.
18
Example : Construct the state diagram for the finite-state automata 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. f Input state01 s0s0 s0s0 s1s1 s1s1 s0s0 s2s2 s2s2 s0s0 s0s0 s3s3 s2s2 s1s1 s0s0 s1s1 s3s3 s2s2 0 1 0 0 1 0,1 1 start
19
Definition : A NDFA, M= (S, I, f, s 0, 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 0,and a subset F of S consisting of the final states. Non Deterministic Finite-State Automata 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 value and state.
20
Example : Find the state diagram for the NDFA with the state table shown in table. The final states are s 2 and s 3 f Input state01 s0s0 s 0, s 1 s3s3 s1s1 s0s0 s 1, s 3 s2s2 s 0, s 2 s3s3 s 0, s 1, s 2 s1s1 s0s0 s1s1 s3s3 s2s2 0 0 0 0 1 1 0 start 1 1 0,1 1
21
Example : Find the state table for the NDFA with the state diagram shown in figure. f Input state01 s0s0 s 0, s 2 s1s1 s1s1 s3s3 s4s4 s2s2 s4s4 s3s3 s3s3 s2s2 s4s4 s3s3 s3s3 s0s0 s1s1 s3s3 s2s2 0 1 0 0 0 start 0 s4s4 1 1 0,1 1
22
EQUIVALENT FINITE-STATE AUTOMATA A string x is said to be recognized or accepted by the machine M = (S, I, f, s0, F) if it takes the initial state s0 to a 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 we specified that two finite state automata are equivalent if they recognize the same language.
23
EQUIVALENT FINITE-STATE AUTOMATA Show that the two finite-state automata M0 and M1 shown in Figure 5 are equivalent.
24
EQUIVALENT FINITE-STATE AUTOMATA
25
Solution: For a string x to be recognized by M0, x must take us from s0 to the final state s1 or the final state s4. The only string that takes us from s0 to s1 is the string 1. The strings that take us from s0 to s4 are those strings that begin with a 0, which takes us from s0 to s2, followed by zero or more additional 0s, which keep the machine in state s2, followed by a 1, which takes us
26
EQUIVALENT FINITE-STATE AUTOMATA from state s2 to the final state s4. All other strings take us from s0 to a state that is not final. We conclude that L(M0) is the set of strings of zero or more 0 bits followed by a final 1. For a string x to be recognized by M1, x must take us from s0 to the final state s1. So, for x to be recognized, it must begin with some number of 0s, which leave us in state s0, followed by
27
EQUIVALENT FINITE-STATE AUTOMATA a 1, which takes us to the final state s1.A string of all zeros is not recognized because it leaves us in state s0, which is not final. All strings that contain a 0 after 1 are not recognized because they take us to state s2, which is not final. It follows that L(M1) is the same as L(M0).We conclude
28
END
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.