Deterministic Finite Automata Lecture 4 1 Input Accepted by a DFA - - PowerPoint PPT Presentation

deterministic finite automata
SMART_READER_LITE
LIVE PREVIEW

Deterministic Finite Automata Lecture 4 1 Input Accepted by a DFA - - PowerPoint PPT Presentation

Deterministic Finite Automata Lecture 4 1 Input Accepted by a DFA We say that M accepts w * if M , on input w , starting from the start state s , reaches a final state i.e., * ( s,w ) F L ( M ) is the set of all strings accepted by


slide-1
SLIDE 1

Deterministic Finite Automata

Lecture 4

1

slide-2
SLIDE 2

CS 374

Input Accepted by a DFA

We say that M accepts w ∈ Σ* if M, on input w, starting from the start state s, reaches a final state i.e., δ*(s,w) ∈ F L(M) is the set of all strings accepted by M i.e., L(M) = { w | δ*(s,w) ∈ F } Called the language accepted by M

2

slide-3
SLIDE 3

CS 374

Input Accepted by a DFA

What kind of language is accepted by FSM?

  • Automatic (it is an automaton after all)!
  • We will use: REGULAR (not a coincidence)

Language is regular iff

  • it is accepted by a finite state automaton
  • it is described by a regular expression

3

slide-4
SLIDE 4

CS 374

Warning

“M accepts language L” does not mean simply that M accepts each string in L. “M accepts language L” means
 M accepts each string in L and no others! L(M) = L

4

slide-5
SLIDE 5

CS 374 Reject state

Examples: What is L(M) ?

1 0,1 1 1 2 abbreviation B 1 A 2 B B B A 4 A 3 A B A

A AB ABB ABBA

1 3 1 2 1 1 1

  • dd #0 and odd #1

0*11* (A+B)*ABBA

5

slide-6
SLIDE 6

Building DFAs

6

slide-7
SLIDE 7

CS 374

State = Memory

First, decide on Q The state of a DFA is its entire memory of what has come before The state must capture enough information to complete the computation on the suffix to come When designing a DFA, think “what do I need to know at this moment?” That is your state.

7

slide-8
SLIDE 8

CS 374

DFA Construction Exercise

Is it regular?? What should be in the memory?

8

(0+1)*00(0+1)*

s a

L(M) = {w | w contains 00 }

slide-9
SLIDE 9

CS 374

L(M) = {w | w contains 00 } Is it regular?? What should be in the memory?

9

1

(0+1)*00(0+1)*

s a

DFA Construction Exercise

slide-10
SLIDE 10

CS 374

L(M) = {w | w contains 00 } Is it regular?? What should be in the memory?

10

1 1

(0+1)*00(0+1)*

s a

DFA Construction Exercise

slide-11
SLIDE 11

CS 374

L(M) = {w | w contains 00 } Is it regular?? What should be in the memory?

11

1 1

(0+1)*00(0+1)*

b s a

DFA Construction Exercise

slide-12
SLIDE 12

CS 374

L(M) = {w | w contains 00 } Is it regular?? What should be in the memory?

12

1 1

(0+1)*00(0+1)*

b s a 0,1

DFA Construction Exercise

slide-13
SLIDE 13

CS 374

  • s : I haven’t seen a 00, previous symbol was 1 or

undefined.

  • a: I haven’t seen a 00, previous symbol was a 0
  • b: I have seen a 00

13

1 1 b s a 0,1

L(M) = {w | w contains 00 }

  • We have exhausted of all strings. Either accepted (with 00) or not.

DFA Construction Exercise

slide-14
SLIDE 14

CS 374

DFA construction

  • Make sure you interpret all the cases!
  • How about design a DFA for L(M) = {w | w contains

001100110011111001101101}?

  • There is algorithm to minimize the DFA, but when you are

asked to do it, try to be clear versus succinct.

  • Try to be “stupid”, do brute force!!!
  • When you are just trying to prove that a language is regular

—> DFA for the language exists. Write an algorithm like we did for multiple of 5!

14

slide-15
SLIDE 15

CS 374

A More Complicated example

L(M) = {w | w contains 00 and then 11}

15

slide-16
SLIDE 16

CS 374

L(M) = {w | w contains 00}

16

1 1 b s a 0,1

A More Complicated example

slide-17
SLIDE 17

CS 374

L(M) = {w | w contains 11}

17

1 1 b’ s’ a’ 0,1

A More Complicated example

slide-18
SLIDE 18

CS 374

L(M) = {w | w contains 00 and then 11}

18

1 1 00 s

A More Complicated example

slide-19
SLIDE 19

CS 374

L(M) = {w | w contains 00 and then 11}

19

1 1 00 s

A More Complicated example

slide-20
SLIDE 20

CS 374

L(M) = {w | w contains 00 and then 11}

20

1 1 00 s 1 00,1

A More Complicated example

slide-21
SLIDE 21

CS 374

L(M) = {w | w contains 00 and then 11}

21

1 1 00 s 1 00,1

A More Complicated example

slide-22
SLIDE 22

CS 374

L(M) = {w | w contains 00 and then 11}

22

1 1 00 s 1 1 00,11 00,1

A More Complicated example

slide-23
SLIDE 23

CS 374

L(M) = {w | w contains 00 and then 11}

23

1 1 00 s 1 1 00,11 00,1

A More Complicated example

slide-24
SLIDE 24

CS 374

L(M) = {w | w contains 00 and then 11}

24

1 1 00 s 1 1 00,11 0,1 00,1

A More Complicated example

slide-25
SLIDE 25

CS 374

L(M) = {w | w contains 00 and then 11}

  • If A and B are regular, then AB is regular. Does the

same hold for DFA?

25

1 1 00 s 1 1 00,11 0,1 00,1

A More Complicated example

slide-26
SLIDE 26

CS 374

L(M) = {w | w contains 00 and then 11}

26

1 1 00 s 1 1 00,11 0,1 00,1

A More Complicated example

  • If A and B are regular, then AB is regular. Does the same

hold for DFA?

  • NO! you cannot glue two DFAs together in general like
  • that. This was a special case
slide-27
SLIDE 27

CS 374

L(M) = {w | w contains no 11 after 00}

27

1 1 00 s 1 1 00,11 0,1 00,1

What about the complement?

slide-28
SLIDE 28

CS 374

L(M) = {w | w contains no 11 after 00}

28

1 1 00 s 1 1 00,11 0,1 00,1

What about the complement?

slide-29
SLIDE 29

CS 374

L(M) = {w | w contains no 11 after 00}

29

1 1 00 s 1 1 00,11 0,1 00,1

What about the complement?

  • If L is regular, then Σ*\L is regular
  • Make the accepting states into non-accepting

and the non-accepting states into accepting

slide-30
SLIDE 30

CS 374

L = {w: w contains 00 and 11}?

1 1 b s a 0, 1 1 b’ s’ a’ 0,

  • I want to build a machine that decides if a string

contains two zeroes in a row AND two ones in a row.

  • I want to run both machines at the same time.
  • At the end of the string, if I am on the accept state

for machine 1 AND on the accept state for machine 2, then I accept.

  • How many states total?
slide-31
SLIDE 31

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

31

1 1 b s a 0, 1 1 b’ s’ a’ 0,

slide-32
SLIDE 32

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

32

1 1 b s a 0, 1 1 b’ s’ a’ 0,

slide-33
SLIDE 33

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

33

1 1 b s a 0, 1 1 b’ s’ a’ 0,

slide-34
SLIDE 34

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

34

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1

slide-35
SLIDE 35

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

35

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1

slide-36
SLIDE 36

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

36

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1

slide-37
SLIDE 37

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

37

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1

slide-38
SLIDE 38

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

38

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1

slide-39
SLIDE 39

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

39

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1

slide-40
SLIDE 40

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

40

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1 1 1 1 0,1 1 1 1

slide-41
SLIDE 41

CS 374

L = {w: w contains 00 and 11}?

L(M1) contains 00 L(M2) :contains 11

41

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1 1 1 1 0,1 1 1 1

slide-42
SLIDE 42

CS 374

The Product Construction

Formally, given two DFAs M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 ∩ L2 Q = Q1 × Q2, s = (s1, s2) A = {(q1,q2): q1 ∈ A1 and q2 ∈ A2} δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = ( , )

42

slide-43
SLIDE 43

CS 374

The Product Construction

Formally, given two DFAs M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 ∩ L2 Q = Q1 × Q2, s = (s1, s2) A = {(q1,q2): q1 ∈ A1 and q2 ∈ A2} δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = (δ1(q1, a), δ2(q2, a) )

43

slide-44
SLIDE 44

CS 374

L = {w: w contains 00 and 11}?

44

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1 1 1 1 0,1 1 1 1

slide-45
SLIDE 45

CS 374

L = {w: w contains 00 and 11}?

45

1 1 1 1 0,1 1 1

Or

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1

slide-46
SLIDE 46

CS 374

L = {w: w contains 00 and 11}?

46

1 1 1 1 0,1 1 1

Or

1 1 b s a 0, 1 1 b’ s’ a’ 0, 1

slide-47
SLIDE 47

CS 374

The Product Construction

Formally, given two DFAs M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 ∩ L2 Q = Q1 × Q2, s = (s1, s2) A = {(q1,q2): q1 ∈ A1 and q2 ∈ A2} δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = (δ1(q1, a), δ2(q2, a) )

47

L1 ∪ L2

slide-48
SLIDE 48

CS 374

The Product Construction

Formally, given two DFAs M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 ∩ L2 Q = Q1 × Q2, s = (s1, s2) A = {(q1,q2): q1 ∈ A1 or q2 ∈ A2} δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = (δ1(q1, a), δ2(q2, a) )

48

L1 ∪ L2

slide-49
SLIDE 49

CS 374

The Product Construction: Question

M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 \L2 Q = Q1 × Q2, s = (s1, s2) A = {} ? δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = ( , ) ?

49

slide-50
SLIDE 50

CS 374

M1 = (Σ,Q1,s1,A1,δ1) and M2 = (Σ,Q2,s2,A2,δ2)

Where M1 accepts L1 M2 accepts L2

M = (Σ,Q,s,A,δ) accepts L1 \L2 Q = Q1 × Q2, s = (s1, s2) A = {(q1,q2): q1 ∈ A1 but not q2 ∈ A2} δ: (Q1 × Q2 )×Σ —>Q1 × Q2 δ( (q1,q2), a) = (δ1(q1, a), δ2(q2, a) )

50

The Product Construction: Question

slide-51
SLIDE 51

CS 374

Closure Properties of Regular Languages

  • Union: trivial for regular expressions, easy for DFAs via

product

  • Complement: easy for DFAs, hard for regular expressions
  • Intersection: easy for DFAs via product, hard for regular

expressions

  • Difference: easy for DFAs via product, hard for regular

expressions

  • Concatenation: easy for regular expressions, hard for

DFA’s

51