Non-Deterministic Automata Regular Expressions

37
1 Non-Deterministic Automata Regular Expressions

description

Non-Deterministic Automata Regular Expressions. NFA Example. NFA Example. Input aplhabet, i.e. Formal Definition of NFAs. Set of states, i.e. Transition function. Initial state. Final states. Transition Function. Extended Transition Function. Formally. It holds. if and only if. - PowerPoint PPT Presentation

Transcript of Non-Deterministic Automata Regular Expressions

Page 1: Non-Deterministic Automata Regular Expressions

1

Non-Deterministic Automata

Regular Expressions

Page 2: Non-Deterministic Automata Regular Expressions

2

NFA Example

0q 1q 2q

0

11,0

*10

...,101010,1010,10,

L

Page 3: Non-Deterministic Automata Regular Expressions

3

NFA Example

0q 1q 2qa b

3q

ab

abababababL ...,,,

Page 4: Non-Deterministic Automata Regular Expressions

4

Formal Definition of NFAs FqQM ,,,, 0

:Q

:

:0q

:F

Set of states, i.e. 210 ,, qqq

: Input aplhabet, i.e. ba,Transition function

Initial state

Final states

Page 5: Non-Deterministic Automata Regular Expressions

5

Transition Function

0q 1q 2q

0

11,0

200

0

10

,,

0,

1,

qqq

q

qq

1,

,0,

2

201

q

qqq

Page 6: Non-Deterministic Automata Regular Expressions

6

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

0320

540

10

,,,*

,,*

,*

qqqabq

qqaaq

qaq

Page 7: Non-Deterministic Automata Regular Expressions

7

Formally

wqq ij ,*

It holds

if and only if

there is a walk from towith label

iq jqw

Page 8: Non-Deterministic Automata Regular Expressions

8

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

0320

540

,,,*

,,*

qqqabq

qqaaq

M

MLab

MLaa

)(

50 ,qqF

Page 9: Non-Deterministic Automata Regular Expressions

9

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10

540

,*

,,*

qabaq

qqabaaq

MLaba

MLaaba

)(

Page 10: Non-Deterministic Automata Regular Expressions

10

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

Page 11: Non-Deterministic Automata Regular Expressions

11

FormallyThe languageaccepted by NFA is:

where

and there is some

)(MLM

,...,, 321 wwwML

,...,),(* 0 ji qqwq

Fqk (final state)

Page 12: Non-Deterministic Automata Regular Expressions

12

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

Page 13: Non-Deterministic Automata Regular Expressions

13

Equivalence of NFAs and DFAs

For DFAs or NFAs:

Machine is equivalent to

if

1M 2M

21 MLML

Page 14: Non-Deterministic Automata Regular Expressions

14

Example

0q 1q 2q

0

11,0

0q 1q 2q

0

11

0

1,0

NFA

DFA

*}10{1 ML

*}10{2 ML

Page 15: Non-Deterministic Automata Regular Expressions

15

Since

machines and are equivalent

*1021 MLML

1M 2M

0q 1q 2q

0

11,0

0q 1q 2q

0

11

0

1,0

DFA

NFA 1M

2M

Page 16: Non-Deterministic Automata Regular Expressions

16

Equivalence of NFAs and DFAs

Every DFA is also an NFA

A language accepted by a DFA will be accepted by an NFA

An NFA is as least as powerful as a DFA

Is an DFA as powerful as an NFA?

Page 17: Non-Deterministic Automata Regular Expressions

17

Is a DFA as Powerful as an NFA?

Answer: YES!

A language accepted by an NFA will be accepted by some DFA

For every NFA there is an equivalent DFAthat accepts the same language

Page 18: Non-Deterministic Automata Regular Expressions

18

NFAs Accept the Regular Languages

For every NFA there is an equivalent DFA

The language accepted by a DFA is regular

The language accepted by an NFA is regular

Page 19: Non-Deterministic Automata Regular Expressions

19

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 20: Non-Deterministic Automata Regular Expressions

20

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

Page 21: Non-Deterministic Automata Regular Expressions

21

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

Page 22: Non-Deterministic Automata Regular Expressions

22

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

a

Page 23: Non-Deterministic Automata Regular Expressions

23

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

Page 24: Non-Deterministic Automata Regular Expressions

24

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

Page 25: Non-Deterministic Automata Regular Expressions

25

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 26: Non-Deterministic Automata Regular Expressions

26

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 27: Non-Deterministic Automata Regular Expressions

27

NFA to DFA Observations

We are given an NFA

We want to convert it to an equivalent DFA

With

M

M

)(MLML

Page 28: Non-Deterministic Automata Regular Expressions

28

If the NFA has states

The DFA has states in the powerset

,...,, 210 qqq

,....,,,,,,, 7432110 qqqqqqq

Page 29: Non-Deterministic Automata Regular Expressions

29

Procedure NFA to DFA

1. Initial state of NFA:

Initial state of DFA:

0q

0q

Page 30: Non-Deterministic Automata Regular Expressions

30

Example

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 31: Non-Deterministic Automata Regular Expressions

31

Procedure NFA to DFA 2. For every DFA’s state

Compute in the NFA

Giving union

Add a transition

mji qqq ,...,,

...,,*

,,*

aq

aq

j

i

mji qqq ,...,,

mjimji qqqaqqq ,...,,,,...,,

Page 32: Non-Deterministic Automata Regular Expressions

32

Exampe

a

b

a

0q 1q 2q

NFA

0q 21,qqa

DFA

},{),(* 210 qqaq

210 ,, qqaq

Page 33: Non-Deterministic Automata Regular Expressions

33

Procedure NFA to DFA

Repeat Step 2 for all letters, untilno more transitions can be added.

Page 34: Non-Deterministic Automata Regular Expressions

34

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 35: Non-Deterministic Automata Regular Expressions

35

Procedure NFA to DFA 3. For any DFA state

If some is a final state for the NFA

Then, is a final state for the DFA

mji qqq ,...,,

jq

mji qqq ,...,,

Page 36: Non-Deterministic Automata Regular Expressions

36

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Fq 1

Fqq 21,

Page 37: Non-Deterministic Automata Regular Expressions

37

Theorem Take NFA M

Apply procedure to obtain DFA M

Then and are equivalent :M M

MLML