lecture-4.docx
Document Details
Uploaded by StylishSpessartine
University of Science and Technology
Tags
Full Transcript
**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Theory of Computation** **Lecture (4): Non-Deterministic Finite Automata** **Instructor: Prof. Noureldien A. Noureldien** **4.1 Nondeterminism** Nondeterminism is a useful concept that has had...
**University of Science and Technology** **Faculty of Computer Science and Information Technology** **Theory of Computation** **Lecture (4): Non-Deterministic Finite Automata** **Instructor: Prof. Noureldien A. Noureldien** **4.1 Nondeterminism** Nondeterminism is a useful concept that has had great impact on the theory of computation. So far in our discussion, every step of a computation follows in a unique way from the preceding step. When the machine is in a given state and reads the next input symbol, we know what the next state will be, that is to say the next state is determined, we call this ***deterministic*** computation. In a ***nondeterministic*** machine, several choices may exist for the next state at any point. **[Nondeterminism is a generalization of determinism, so every deterministic finite automaton is automatically a nondeterministic finite automaton]**. As Figure 1.27 shows, nondeterministic finite automata may have additional features. The difference between a deterministic finite automaton (DFA), and a nondeterministic finite automaton (NFA), is that: 1- **Every state of a DFA always has exactly one exiting transition arrow** **for each symbol in the alphabet**. The NFA shown in Figure 1.27 violates that rule. State q1 has one exiting arrow for 0, but it has two for 1; q2 has one arrow for 0, but it has none for 1. **[In an NFA, a state may have zero, one, or many exiting arrows for each alphabet symbol]**. **2- In a DFA, labels on the transition arrows are symbols from the alphabet.** This NFA has an arrow with the label €. **In general, an NFA may have arrows labeled with members of the alphabet or** **€. Zero, one, or many arrows may exit from each state with the label €.** **4.2 How does an NFA compute?** 1- If that we are running an NFA on an input string and come to a state with multiple ways to proceed. For example, say that we are in state q1 in NFA N1 and that the next input symbol is a 1. After reading that symbol, the machine splits into multiple copies of itself and follows *all* the possibilities in parallel. Each copy of the machine takes one of the possible ways to proceed and continues as before. If there are subsequent choices, the machine splits again. 2- If when in a state the next input symbol doesn't appear on any of the existing arrows, that copy of the machine dies. 3- If *any one* of these copies of the machine **is in an accept state** at the end of the input, **the NFA accepts the input string**. 4- If when in state an € symbol is occurring on an existing arrow, then without **reading any input**, the machine splits into multiple copies, one following each of the exiting €-labeled arrows **and one staying at the current state**. Then the machine proceeds non-deterministically as before. **Example** Let's consider some sample runs of the NFA N1 shown in Figure 1.27. The computation of N1 on input 010110 is depicted in the following figure. EXAMPLE **1.30** Let A be the language consisting of all strings over {0,1} **containing a 1 in the third position from the end (e.g., 000100 is in A but 0011 is not**). The following four-state NFA N2 recognizes A. to view the computation of this NFA is to say that it stays in the start state q1 until it "guesses" that it is three places from the end. At that point, if the input symbol is a 1, it branches to state q2 and uses q3 and q4 to "check" on whether its guess was correct. **To convert the NFA into an equivalent DFA**; it sometimes that DFA may have many more states. For example, the above NFA can be converted to DFA for A contains eight states. Furthermore, understanding the functioning of the NFA is much easier, as you may see by examining the following figure for the DFA. FIGURE **1.32** A DFA **Example** The following NFA accepts the strings €, a, baba, and baa, but that it doesn't accept the strings b, bb, and babba. Later we use this machine to illustrate the procedure for converting NFA to DFA. **Formal Definition of Nondeterministic Finite State Automata (NFA)** In a DFA, the transition function takes a state and an input symbol and produces the next state. In an NFA, the transition function takes a state and an input symbol *or the empty string* and produces *the set of possible next states*. In order to write the formal definition, we need to set up some additional notation. For any set Q we write P(Q) to be the collection of all subsets of Q. Here P(Q) is called the ***power set*** of Q. For any alphabet € \_we write ∑~€~ to be ∑ ~U\ €\.~ Now we can write the formal description of the type of the transition function in an NFA as