Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 2670 Introduction to Theory of Computing

Similar presentations


Presentation on theme: "CSCI 2670 Introduction to Theory of Computing"— Presentation transcript:

1 CSCI 2670 Introduction to Theory of Computing
September 6, 2007

2 Announcement Check website for next homework assignment

3 Agenda Last class This class Defined regular languages
Discussed creating DFA’s Showed that union is a regular operation This class Show concatenation is a regular operation Introduce NFA’s Non-deterministic finite automata

4 Combining regular languages
We can create a regular language from other regular languages A and B using specific allowable operations called regular operations Union: A  B Concatenation: A  B Kleene star: A*

5 Union is a regular operation
Theorem: The class of regular languages is closed under the union operation Proof approach: Assume A1 and A2 are both regular languages with A1=L(M1) and A2=L(M2) and create a DFA M such that L(M) = A1A2 Method: Proof by construction

6 Example M1 M2 q1 q2 q3 0,1 1 q1’ q2’ q3’ 1 1 1 q2,q1’ q3,q1’ q1,q1’ 1
0,1 1 M1 Example q1’ q2’ q3’ 1 1 1 M2 q2,q1’ q3,q1’ q1,q1’ 1 1 1 q3,q2’ q1,q2’ q2,q2’ 1 1 1

7 Still need to prove L(M) = A1A2
How should we do this? Show any string in A1A2 is in L(M) Let x be an element of A1A2 For simplicity, assume x is in A1 Same argument below (with minor changes) applies for A2 The computation path q0, q1, …, qk for x in the DFA that recognizes A1 ends at an accept state The computation path in M will be (q0,r0), (q1,r1), …, (qk,rk) for some states r0, r1, …, rk in the DFA that accepts A2 (qk,rk) is an accept state in M Therefore x is in L(M)

8 Still need to prove L(M) is A1A2
Show any string in L(M) is in A1A2 Let x be an element of L(M) The computation path of x in M is (q0,r0), (q1,r1), …, (qk,rk) for some states q0, q1, …, qk and r0, r1, …, rk in the DFA’s that accept A1 and A2, respectively (qk,rk) is an accept state in M Either qk or rk must be an accept state in its DFA Therefore x is in A1A2

9 Concatenation is a regular operation
Theorem: The class of regular languages is closed under the concatenation operation Proof approach: Assume A1 and A2 are both regular languages with A1=L(M1) and A2=L(M2) and create a DFA M such that L(M) = A1A2 Method: Proof by construction

10 Example M1 M2 Can jump to q1’ non-deterministically q1 q2 q3 0,1 1 1
0,1 1 M1 1 q1’ q2’ q3’ M2 Example q1 q2 q3 0,1 1 q1’ q2’ q3’ ε Can jump to q1’ non-deterministically

11 NFA vs. DFA DFA NFA Exactly one arrow exiting each node for each symbol of the alphabet Number of exiting arrows can be anything from 0 to the number of nodes Each arrow is labeled only with characters of the alphabet Characters may be labeled with an empty string, ε Each string reaches exactly one state at the end of the input A string may reach several different states states at the end of the input

12 Computing on an NFA For each symbol of the string, keep track of all possible transitions in parallel When input ends, there may be several possible ending states If at least one of the possibilities is an accepting state, then the NFA accepts the string

13 Example Does this NFA accept the string 001? From state(s) Input
0,1 1 q1 q2 ε q3 1 1 Does this NFA accept the string 001? From state(s) Input To state(s) q1 q2, q3 1 q1, q3 Yes q1, q3

14 Example Any string containing two 1’s separated by at most one 0 0,1 1
ε Any string containing two 1’s separated by at most one 0

15 Example Zero or more concatenations of the strings aba and ab   b a

16 Example ε a, b, c a, b, d a, c, d b, c, d Strings of any length containing at most three of the symbols in  = {a, b, c, d}

17 The power of non-determinism
Strings of any length containing at most two of the symbols in  = {a, b, c} c a b a, b, c a, c b,c a, b DFA a, b a, c b, c ε NFA

18 Non-deterministic finite automaton
A non-deterministic finite automaton is a 5-tuple (Q,,,q0,F), where Q is a finite set of states  is a (finite) alphabet  : Q × ε  P(Q) is the transition function  maps to sets of states q0 is the start state, and F  Q is the set of accept states

19 Equivalence of DFAs and NFAs
Theorem: Every non-deterministic finite automaton has an equivalent deterministic finite automaton Both FAs accept the same language Proof method Construction Similar to method used for calculating strings Follow all paths in parallel where states represent parallel paths

20 Proof idea Given NFA M1={Q,,,q0,F} construct DFA M2={Q’,,’,q0’,F’} with L(M1)=L(M2) Intuition Recall :Q×εP(Q) Our DFA’s transition function will generate paths within P(Q) ’: P(Q)×P(Q)

21 Defining M2 (ignoring  jumps)
Determine Q’, q0’, and F’ Q’ = P(Q) q0’ = {q0} F’ = {R  Q’ | R  F  } i.e., R contains at least one of M1’s accept states Defining ’ (for now ignore ε jumps) (r,a) is the set of states reached from r when a is processed r is one of the states in R (i.e., a state in the NFA) R is a set of states from the NFA a is a symbol in the alphabet

22 Example Q’={,{q1}, {q2}, {q3}, {q1,q2}, {q1,q3}, {q2,q3}, {q1,q2,q3}}
q1 1 q3 Q’={,{q1}, {q2}, {q3}, {q1,q2}, {q1,q3}, {q2,q3}, {q1,q2,q3}}

23 Example 1 q2 q1 1 q3 q0’={q1}

24 Example 1 q2 q1 1 q3 F’={{q3}, {q1,q3}, {q2,q3}, {q1,q2,q3}}

25 Example 1 {q1} {q2,q3}  {q2} {q1,q3} {q3} {q1,q2} {q1,q2,q3} 1 1 q2
1 {q1} {q2,q3} {q2} {q1,q3} {q3} {q1,q2} {q1,q2,q3} 0,1 {q1} 1 {q2,q3} {q1,q3} 1 q1 q2 q3

26 Proof of Correctness Theorem: Let N be an NFA and let M be the DFA constructed by the method described above. Then L(M) = L(N). Proof: Let x be any string in Σ*. Let R be the set of states in N in which computation of x terminates and let R’ be the state in M in which computation of x terminates. Want to prove R = R’

27 R = R’ Proof by induction Base case Induction hypothesis
On what? Base case x = ε Then R = R’ = {q0} Induction hypothesis Assume R = R’ for all strings of length at most k Induction step Prove R = R’ when |x| = k + 1

28 Induction Step Let x = x1x2…xkxk+1
Let S and S’ be the (set of) states arrived at after computing x1…xk in M and N, respectively By induction hypothesis S = S’ What happens when we read xk+1 In N, we can go to any state q such that q = δ(q’,xi+1) for some q’ in S R = {δ(q’,xk+1) | q’ in S} In M, by definition we go to R’ = δ’(S’,xk+1) = {δ(q’,xk+1) | q’ in S’} Thus R = R’ by induction hypothesis

29 Have a Fabulous Weekend


Download ppt "CSCI 2670 Introduction to Theory of Computing"

Similar presentations


Ads by Google