Lecture-9.docx
Document Details
Uploaded by StylishSpessartine
University of Science and Technology
2022
Tags
Full Transcript
**University of Science and Technology** **Faculty of Computer Science and Information Technology** [Computer Science Department] Subject: Theory of Computation Lecture (9) Instructor: Prof. Noureldien Abdelrahman Date 21-12-2022 **Finite-State Machines with Output** **Introduction** Many ki...
**University of Science and Technology** **Faculty of Computer Science and Information Technology** [Computer Science Department] Subject: Theory of Computation Lecture (9) Instructor: Prof. Noureldien Abdelrahman Date 21-12-2022 **Finite-State Machines with Output** **Introduction** Many kinds of machines, including components in computers, can be modeled using a structure called a finite-state machine. Several types of finite-state machines are commonly used in models. All these versions of finite-state machines include a finite set of states, with a designated starting state, an input alphabet, and a transition function that assigns a next state to every state and input pair. Finite-state machines are used extensively in applications in computer science and data networking. **[For example, finite-state machines are the basis for programs for spell checking, grammar checking, indexing or searching large bodies of text, and recognizing speech]**. In this section, we will study those finite-state machines that produce output. **Finite-State Machines with Outputs** We will now give the formal definition of a finite-state machine with output. **DEFINITION 1** A *finite-state machine 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 state and input pair a new state], an *output [function g ]*[that assigns to each state and input pair an output], and an *initial state s*0. **EXAMPLE 1** The state table shown in Table 2 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. Another way to represent a finite-state machine is to use a **state diagram**, which is a directed graph with labeled edges. In this diagram, **[each state is represented by a circle]**. Arrows labeled **[with the input and output pair are shown for each transition]**. **EXAMPLE 2** Construct the state diagram for the finite-state machine with the state table shown in Table 2. ***Solution:*** The state diagram for this machine is shown in Figure 2. **EXAMPLE** 3 Construct the state table for the finite-state machine with the state diagram shown in Figure 3. ***Solution:*** The state table for this machine is shown in Table 3. An input string takes the starting state through a sequence of states, as determined by the transition function. As we read the input string symbol by symbol (from left to right), each input symbol takes the machine from one state to another. Because each transition produces an output, an input string also produces an output string. **[Hence, we can extend the definition of the output function *g* to input strings so that *g(x)* = *y*, where *y* is the output corresponding to the input string *x*. This notation is useful in many applications.]** **EXAMPLE 4** Find the output string generated by the finite-state machine in Figure 3 if the input string is 101011. ***Solution:*** The output obtained is 001000. The successive states and outputs are shown in Table 4. We can now look at some examples of useful finite-state machines. Examples 5, 6, and 7 illustrate that the states of a finite-state machine give it limited memory capabilities. The states can be used to remember the properties of the symbols that have been read by the machine. However, because there are only finitely many different states, finite-state machines cannot be used for some important purposes. **EXAMPLE 5** An important element in many electronic devices is a *unit-delay machine*, which produces as output the input string delayed by a specified amount of time. How can a finite-state machine be constructed that delays an input string by one unit of time, that is, produces as output the bit string 0*x*1*x*2 *... xk*−1 given the input bit string *x*1*x*2 *... xk*? ***Solution*** A delay machine can be constructed that has **[two possible inputs, namely, 0 and 1]**. The machine must have a start state *s*0. Because the machine has to remember whether the previous [ ] input was a 0 or a 1, two other states *s*1 and *s*2 are needed, where **[the machine is in state *s*1 if the previous input was 1 and]** **[in state *s*2 if the previous input was 0.]** An output of 0 is produced for the initial transition from *s*0. Each transition from *s*1 gives an output of 1, and each transition from *s*2 gives an output of 0. The output corresponding to the input of a string *x*1 *... xk* is the string that begins with 0, followed by *x*1, followed by *x*2*,... ,* ending with *xk*−1. The state diagram for this machine is shown in Figure 4. **EXAMPLE 6** In a certain coding scheme, when three consecutive 1s appear in a message, the receiver of the message knows that there has been a transmission error. 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**. ***Solution**:* Three states are needed in this machine. The start **state *s*0 remembers** that the previous input value, if it exists, was not a 1. The **state *s*1 remembers** that the previous input was a 1, but the input before the previous input, if it exists, was not a 1. **The state *s*2 remembers** that the previous two inputs were 1s. An input of 1 takes *s*0 to *s*1, because now a 1, and not two consecutive 1s, has been read; it takes *s*1 to *s*2, because now two consecutive 1s have been read; and it takes *s*2 to itself, because at least two consecutive 1s have been read. An input of 0 takes every state to *s*0, because this breaks up any string of consecutive 1s. The output for the transition from *s*2 to itself when a 1 is read is 1, because this combination of input and state shows that three consecutive 1s have been read. All other outputs are 0. The state diagram of this machine is shown in Figure 6. The final output bit of the finite-state machine we constructed in Example 6 is 1 if and only if the input string ends with 111. Because of this, we say that this finite-state machine **recognizes** the set of bit strings that end with 111.