Download presentation
Presentation is loading. Please wait.
Published byHubert Fleury Modified over 6 years ago
1
CSC 4170 Theory of Computation Nondeterminism Section 1.2
2
An NFA without -transitions
q1 1 q2 0,1 q3 0,1 What language does this NFA recognize?
3
An NFA with -transitions
1.2.b 1 b a a 3 a,b 2 b a b a b Does this NFA accept: ? a ? b ? aaa…a ?
4
Formal definition of a nondeterministic finite automaton
Let = {} A NFA is a 5-tuple (Q, , , s, F), where: Q is a finite set called the states, is a finite set called the alphabet, is a function of the type Q P(Q) called the transition function, s is an element of Q called the start state, F is a subset of Q called the set of accept states.
5
Our automaton formalized
1 Q: : : s: F: b a a a b 1 2 3 3 a,b 2 A = (Q, , , s, F)
6
Formal definition of accepting by NFA
M = (Q, , , s, F) 1 b a a 3 a,b 2 M accepts the string x iff x can be written as u1 u2 … un where each ui is in , and there is a sequence r1, r2, …, rn, rn+1 of states such that: r1= s ri+1 (ri,ui), for each i with 1 i n rn+1 F Example: aa u u2 … un aa = r1, r2, …, rn, rn+1
7
What language does this NFA recognize?
8
What language does this DFA recognize?
1 2 3 5 4
9
Equivalence of NFAs and DFAs
1.2.h Two machines are said to be equivalent, if they recognize the same language. Theorem Every NFA has an equivalent DFA. Proof. Consider an NFA N = (Q, , , s, F) We need construct an equivalent DFA D = (Q’, , ’, s’, F’) using a procedure called the subset construction (next slide). Notation: For RQ, let R = {q | q can be reached from R by traveling along 0 or more -arrows} Explain the idea: keep track of what set of states is possible a a For RQ and a, let (R,a) = {q | q can be reached from R by traveling along an a-arrow} a
10
The Subset Construction
Constructing DFA D = (Q’, , ’, s’, F’) from NFA N = (Q, , , s, F) Q’ = P (Q) ’(R,a) = (R,a) s’ = {s} F’= {R | R is a subset of Q containing an accept state of N} D obviously works correctly: at every step in the computation, it clearly enters a state that corresponds to the subset of states that N could be in at that point. a a a
11
Applying the subset construction to our NFA
1.2.j Q’: : ’: s’: F’: N = (Q, , , s, F) 1 a b {1} {2} {3} {1,2} {1,3} {2,3} {1,2,3} b a a 3 a,b 2 Q’ = P (Q) ’(R,a) = (R,a) s’ = {s} F’= {R | R is a subset of Q containing an accept state of N}
12
D {,{1},{2},{3}, {{1},{1,2},{1,3},{1,2,3}} The resulting DFA
1.2.k {,{1},{2},{3}, {1,2},{1,3},{2,3},{1,2,3}} D Q’: : ’: s’: F’: a,b {3} b {a,b} a a a b {1} {2} {3} {1,2} {1,3} {2,3} {1,2,3} b {1,3} {1} {2} b {2,3} {3} a b b {1,3} {2,3} {2,3} {1,3} {2} {2,3} a {2} {1,2,3} {3} {1,2,3} {2,3} a b a,b {1,2,3} {1,2} {1,3} {{1},{1,2},{1,3},{1,2,3}} a
13
Removing unreachable states
{,{1},{2},{3}, {1,2},{1,3},{2,3},{1,2,3}} D Q’: : ’: s’: F’: a,b {3} b {a,b} a a b {1} {2} {3} {1,2} {1,3} {2,3} {1,2,3} b {1,3} {2} b {2,3} {3} a b {1,3} {2,3} {2,3} {1,3} {2} {2,3} a {2} {1,2,3} {3} {1,2,3} {2,3} a b {1,2,3} {1,3} {{1},{1,2},{1,3},{1,2,3}} a
14
N D b a a Testing in work 1 b a a 3 a,b 2 a,b {3} b a b {1,3} b a
1.2.m N D a,b {3} b 1 a b a b {1,3} b a a b 3 a,b 2 {2,3} a {2} a b b a a {1,2,3} a
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.