Download presentation
Presentation is loading. Please wait.
1
61 Nondeterminism and Nodeterministic Automata
2
62 The computational machine models that we learned in the class are deterministic in the sense that the next move is uniquely determined by the current state and the input (i.e., external stimulus). Thus, the state transition graphs of DFA's have one (and only one) edge for each input symbol. (Recall that, just for convenience, we agreed not to draw the edge for a transition with an input symbol leading to the dead state.) Deterministic machines follow our intuition, because the models are based on the determinism, which propose that, for a given cause (current state of the system and external input), the effect (state change and the output of the system) is uniquely determined. Nondeterminism does not go along our intuition because it allows multiple conflicting effects for a given cause. Consider the state transition graph shown on the following page, which has transitions which violate the determinism. For example, the transition (1, a) = {1, 2} says that in state 1 the automaton, reading input symbol a, enters states 1 and 2. (Note that the machine enters states 1 and 2 at the same time.We call such machines nondeterministic finite automata (NFA). Nondeterminism and Nondeterministic Automata
3
63 Nodeterministic FA: Nondeterministic transitions: (1, a) = {1, 2} (4, b) = {2, 3, 4} * (2, ) = {2, 3} Deterministic transitions: (1, b) = {3} (3, a) = {4} (4, a) = {2} 2 3 4 1 a b a a a, b b b * Notice that in any state p, the machine stays in the same state while there is no input, which implicitly there is (p, ) = {p}. Therefore, if there is an explicit transition, like from state 2 to state 3 in the above graph, the transition is nondeterministic, because (2, ) = {2, 3}. We will deal with such -transitions later as a separate topic. Until then we study nondeterministic automata with no -transitions. Nondeterministic Automata (cont’ed)
4
64 If an FA has transition (p, a) = {q, r}, we say that the machine, in state p reading a, nondeterministically enters states q and r. After taking this transition, the machine is in both q and r. We think that two machines, one in q and the other in r, continue the computation independently for the same input. Formally an NFA M is defined by the same tuple M = (Q, , , q 0, Z 0, F ) as for DFA. The only difference is the transition function; : Q 2 Q,which implies that in a state in Q, reading a symbol in , the machine can enter simultaneously in some states (i.e., a subset of Q). Notice that DFA is a special case of NFA which for an input symbol, takes a transition to a single state. For a string x, let (q 0, x) = S, where S is the set of states that the machine enters after reading string x. The language accepted by an NFA M is defined as follows; L(M) = {x| x {a,b} *, (q 0, x) = S, and S F }. Notice the accepting condition, S F . This implies that if there exists at least one sequence of transition that ends up in an accepting state, then we say the input x is accepted. All non-accepting cases are ignored. If there is no accepting case (i.e., S F = ), then we say the input is rejected. Nondeterministic Automata (cont’ed)
5
65 For example, consider the NFA shown in Figure (a) below. Figure (b) shows all possible sequences of transitions for input bbba, where nodes with label X denote the dead state which is not shown on the state transition graph. String bbba is accepted by the machine since there exists a sequence of transitions, which ends in an accepting state (q 2 in the figure). Note that NFA's are similar to parallel machines in the sense that they explore an answer simultaneously in more than one way. However, nondeterministic machines do not produce (or announce) the final result out of all possible sequences of operations. We, the user, must search all possible terminating states of the machine and decide whether it satisfies the accepting condition or not. q0q0 q1q1 q2q2 a b b a,b b Figure (a): An NFA q0q0 q1q1 q2q2 a b b q0q0 q0q0 q0q0 q1q1 q1q1 q1q1 X X b b bb b b a Figure (b): The profile of nondeterministic transition for input string bbba. Nondeterministic Automata (cont’ed)
6
66 Designing NFA: a a a, b {xaa | x {a, b} * } a a a, b b b {x | x {a, b} * and there is aa followed by bb somewhere in x} Nondeterministic Automata (cont’ed)
7
67 Nodeterministic PDA: Notice that a PDA is nondeterministic if there is a state q, an input symbol t, and a stack symbol s such that either (a) | (q, t, s) | > 1, or (b) | (q, t, s) | 0 and | (q, , s) | 0 (see case * above) Nondeterministic transitions: (1, a, b) = {(2, aa), (3, aa)} (3, b, a) = {(3, ), (3, ba)} (4, a, b) = {(4, ab)} (4, , b ) = {(2, )} Deterministic transitions: (2, a, b) = {(3, ab)} (3, a, b) = {(4, ab)} (3, b, b) = {(2, bb)} (4, b, a) = {(2, ba)} }*}* 1 2 3 4 (a, b/aa) (b, a/ ), (b, a/ba), (a, a/aa) (b, b/bb) (a, b/ab) (a, b/ab), ( , b/ ) (b, a/ba) Nondeterministic Automata (cont’ed)
8
68 Designing NPDA: Nondeterministic Automata (cont’ed) q0q0 q1q1 q2q2 q3q3 (X, Z 0 /X Z 0 ) (Y, X/YX ) ( , X/X ) (X, X/ ) ( , Z 0 /Z 0 ) start Figure (a): NPDA accepting {xx R | x {a, b} + } X, Y {a, b}
9
69 Nondeterministic Automata (cont’ed) Designing NPDA: Figure (b): NPDA accepting {a i b j c k | i, j, k > 0, and i = j or j = k } start (a, Z 0 /aZ 0 ) (b, a/ ) (c, Z 0 / Z 0 ) (a, a/ aa) (a, Z 0 /Z 0 ) (c, Z 0 / Z 0 ) (b, Z 0 /bZ 0 ) (b, b/bb) (c, b/ ) ( , Z 0 / Z 0 )
10
70 Nodeterministic TM and LBA: 1 2 3 4 (a, b, R) (a, b, R), (a, b, L), (b, a, L) (b, a, R), (b, b, R) (b, a, R) (a, b, R) (b, a, L) Nondeterministic transitions: (1, a) = {(2, b, R), (3, b, R)} (2, b) = {(2, a, R), (2, b, R), (2, a, L)} (3, a) = {(4, b, R), (4, b, L)} Deterministic transitions: (3, b) = {(4, a, L)} (4, a) = {(4, b, R)} (4, b) = {(2, a, R)} Nondeterministic Automata (cont’ed) Notice that if there is a pair of a state q and a symbol t such that | (q, t) | > 1, then the automaton is nondeterministic.
11
71 Nondeterministic automata are different from probabilistic machines which change their state based on some probability. If an NFA has nondetermininistic transition (p, a) = {q, r}, then reading a in state p the machine definitely enters both states q and r. The same concept of nondeterminism can be applied to algorithm design. Instead of nondeterministic transition, we use “nondeterministic guess (or choose)” in nondeterministic algorithms. For a finite set S, let nondet_choose(S) mean nondeterministically choosing an element in S. For example, suppose that in an algorithm we have the following statement. Nondeterminism and nondeterministic Algorithms. x = nondet_choose (q, r) ;.
12
72. x = nondet_choose (q, r) ;. x = nondet_choose (q, r) ; {proceed with x = q). x = nondet_choose (q, r) ; (proceed with x = r). Upon execution of this assignment statement the algorithm forks into two independently running program instances, one with x = q, and the other with x = r. Nondeterministic Algorithms This way nondeterministic algorithms can search the solution space of the given problem simultaneously. As in the nondeterministic automata, if t here is no instances of computation generating the answer, we say the a lgorithm fails to give the answer.
13
73 Nondeterministic Algorithms (cont’ed) If we assume that the statement nondet_choose ( ) takes constant time, we can solve many, so called, intractable problems, for which only exponential-time algorithms are available, can be solved in polynomial time. For example, consider the sum-of-subset problem, which is given as follows; Given a set S of n integers and an integer M, is there any sum of subset of S that is equal to M? Given S = {8, 21, 13, 20, 7, 11, 5} and M = 34, for example, the answer should be yes, since 8 + 21 + 5 = 34. This problem, which is one of the well known intractable problems, can be solved in linear-time, if we use the function nondet_choose ( ). Suppose that the set S is given in an array. The nondeterministic algorithm in the following slide solves the problem in linear- time.
14
74 Nondet-Sum-of-Subset (int S [ ], int n, int M) // S is an integer array of size n. { int i, sum = 0; boolean selected; for ( i = 0; i < n; i++) { selected = nondet_choose(true, false); if (selected) sum += S[i]; } if (sum = = M) return “yes”; else return “no”; } Nondeterministic Algorithms (cont’ed) Notice that in the algorithm above, by selected = nondet_choose(true, false) for each element S[i], we are considering both cases of adding and not adding it to the sum. Thus the algorithm examines all possible sums of subsets. If there is an output “yes”, then we can say the answer is yes, ignoring all other “no” answers.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.