Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture2 Regular Language

Similar presentations


Presentation on theme: "Lecture2 Regular Language"— Presentation transcript:

1 Lecture2 Regular Language
 2004 SDU

2 DFA –deterministic finite automaton
A DFA has: a finite set of states 1 special state – start (initial) state 0 or more special states - final (accept) states input alphabet transition table: (state, symbol)  next state q s q4 p a r (p, a) -> r  2004 SDU

3 Informally -- How does a DFA work?
q1 a DFA begins in the start state. DFA goes into a loop until the entire input string is read. In each step, DFA consults a transition table and changes its state based on (q, a) where q - current state a – current symbol read After reading the input string, if the state is final, the input is accepted if the state is not final, the input is rejected Language recognized by a DFA or the language of a DFA – the set of all the strings accepted by the DFA.  2004 SDU

4 Pictorial representation of DFA
state q Start state s Final state q4 transition p a r (p, a) -> r  2004 SDU

5 DFA Demo b b a b a a b b a b b a a a b b b Y N N 1 2  2004 SDU 5
1 2 b multiple of 3 b's b b a b a a b b a b b  2004 SDU 5

6 DFA Demo b a b a a b b a b b a a a b b b Y N N 1 2  2004 SDU 6
1 2 b multiple of 3 b's b a b a a b b a b b  2004 SDU 6

7 DFA Demo b a a a b b a b b a a a b b b Y N N 1 2  2004 SDU 7
1 2 b multiple of 3 b's b a a a b b a b b  2004 SDU 7

8 DFA Demo b a a b b a b b a a a b b b Y N N 1 2  2004 SDU 8
1 2 b multiple of 3 b's b a a b b a b b  2004 SDU 8

9 DFA Demo b a b b a b b a a a b b b Y N N 1 2  2004 SDU 9
1 2 b multiple of 3 b's b a b b a b b  2004 SDU 9

10 DFA Demo b a b a b b a a a b b b Y N N 1 2  2004 SDU 10
1 2 b multiple of 3 b's b a b a b b  2004 SDU 10

11 DFA Demo b a a b b a a a b b b Y N N 1 2  2004 SDU 11
1 2 b multiple of 3 b's b a a b b  2004 SDU 11

12 DFA Demo b a b b a a a b b b Y N N 1 2  2004 SDU 12 multiple of 3 b's
1 2 b multiple of 3 b's b a b b  2004 SDU 12

13 DFA Demo b a b a a a b b b Y N N 1 2  2004 SDU 13 multiple of 3 b's
1 2 b multiple of 3 b's b a b  2004 SDU 13

14 DFA Demo ACCEPT b a a a a b b b Y N N 1 2  2004 SDU 14
1 2 ACCEPT b multiple of 3 b's b a  2004 SDU 14

15 DFA Demo b a b b a a b b a a a b b b Y N N 1 2  2004 SDU 15
1 2 b multiple of 3 b's b a b b a a b b  2004 SDU 15

16 DFA Demo b a b a a b b a a a b b b Y N N 1 2  2004 SDU 16
1 2 b multiple of 3 b's b a b a a b b  2004 SDU 16

17 DFA Demo b a a a b b a a a b b b Y N N 1 2  2004 SDU 17
1 2 b multiple of 3 b's b a a a b b  2004 SDU 17

18 DFA Demo b a a b b a a a b b b Y N N 1 2  2004 SDU 18
1 2 b multiple of 3 b's b a a b b  2004 SDU 18

19 DFA Demo b a b b a a a b b b Y N N 1 2  2004 SDU 19 multiple of 3 b's
1 2 b multiple of 3 b's b a b b  2004 SDU 19

20 DFA Demo b a b a a a b b b Y N N 1 2  2004 SDU 20 multiple of 3 b's
1 2 b multiple of 3 b's b a b  2004 SDU 20

21 DFA Demo REJECT b a a a a b b b Y N N 1 2  2004 SDU 21
1 2 REJECT b multiple of 3 b's b a  2004 SDU 21

22 Example: Diagram of DFA
q0 q1 a  2004 SDU

23 Step-By-Step a q0 q1 a aaa  2004 SDU

24 Step-By-Step a q0 q1 a aaa  2004 SDU

25 Step-By-Step a q0 q1 a aaa  2004 SDU

26 Step-By-Step a q0 q1 a aaa The string is accepted  2004 SDU

27 Formal definition of DFA
A DFA is a 5-tuple: M = (Q, , , s, F) Where, Q is a finite set of states  is a finite set of input alphabet s  Q is the start state F  Q is the set of final states : Q   -> Q is the transition function // note that this is a function, so, for each state and each symbol, there is an arrow that points to another state.  2004 SDU

28 Formal definition of Computation
Let M = (Q, , , s, F) be a finite automaton and let w = w1w2…wn be a string where each wi is a member of the alphabet . M accepts w if there is a sequence of states r0, r1, …, rn such that 1)r0 = s, 2)(ri, wi+1) = ri+1, for i=0, …, n-1. 3) rn F We say that M recognizes language A if A = {w | M accepts w}. Note that the language recognized by a DFA M (or the language of a DFA M) is unique! We write it as L(M). What is language of the following machine? Its formal description? q0 q1 a  2004 SDU

29 Regular Languages Definition: A Language is called regular if some DFA recognizes it.  2004 SDU

30 Given a language, how to define DFA?
Creative process requiring you to: (i) Put yourself in DFA's shoes (ii) Find finite amount of info, based on which string accepted/rejected (iii) From step (ii), determine number of states and then transitions.  2004 SDU

31 Examples L = {w | w begins with a 0 and ends with a 1} 1 1 q0 q1 q2 1
1 q0 q1 q2 1 r 0,1  2004 SDU

32 Examples (cont.) L = {w | w contains the substring 101 } 0,1 1 1 1 s 1
1 1 1 s 1 10 101 More in exercises  2004 SDU


Download ppt "Lecture2 Regular Language"

Similar presentations


Ads by Google