31
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli

Introduction to Computability Theory

  • Upload
    angeni

  • View
    40

  • Download
    2

Embed Size (px)

DESCRIPTION

Introduction to Computability Theory. Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli. Roadmap for Lecture. In this lecture we: Present and motivate Non-Deterministic Finite Automata. Demonstrate that NFA-s and DFA-s are equivalent . Example of an NFA. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Computability Theory

1

Introduction to Computability Theory

Lecture2: Non Deterministic Finite Automata

Prof. Amos Israeli

Page 2: Introduction to Computability Theory

Roadmap for Lecture

In this lecture we:• Present and motivate Non-Deterministic Finite

Automata.• Demonstrate that NFA-s and DFA-s are

equivalent.

2

Page 3: Introduction to Computability Theory

Example of an NFA

0,10,1

1q 4q2q 3q1 1 ,0

1. A state nay have 0 or more transitions labeled with the same symbol.2. transitions are possible.

NFA – Nondeterministic Finite Automaton

3

Page 4: Introduction to Computability Theory

Computation of an NFA

• When several transitions with the same label exist, an input word may induce several paths.

• When no transition is possible a computation is “stuck”.

Q:Which words are accepted and which are not?A: If word w induces (at least) a single accepting

path, the automaton “chooses” this accepting path and w is accepted.

4

Page 5: Introduction to Computability Theory

Possible Computations

hqgqfq

eqdq

cq

DFA

0q

bqjq

aq

.

.

.. . . .

iq kq lq

NFAAt each step of the computation: DFA - A single state is occupied.NFA - Several states may be occupied.

5

Page 6: Introduction to Computability Theory

Computation of an NFA - Example

On the input word w=01011 there exist an accepting path and w is accepted.

Can we characterize (find) the language recognized by this automaton?

Words containing either 101 or 11 as substrings.

6

0,10,1

1q 4q2q 3q1 1 ,0

Page 7: Introduction to Computability Theory

Computation tree of 01011

1q

0,1

4q2q 3q1 1 ,0

0,1

7

1q 1q 1q011

2q

3q

1q0

3q0

1q

2q

4q

1q

2q

4q

3q

11

1

11

1Accepting branch

Page 8: Introduction to Computability Theory

Why do we Care About NFAs?

• NFA-s and DFA-s are equivalent (Meaning: They recognize the same set of languages). In other words: Each NFA recognizing language L has an equivalent DFA recognizing L.

(Note: This statement must be proved.)• But usually, the NFA is much simpler.• Enables the proof of theorems. (e.g. about

regular operations)

8

Page 9: Introduction to Computability Theory

Example - A Complicated DFA

• Can you guess the language?

000 011

010

0011 1 1

1

1

1 1

10

00

00

00

0

100 101

111

110

Page 10: Introduction to Computability Theory

Example – An Equivalent NFA

Can you guess the language?

1q 3q2q1 0,1 0,1

0,1

4q

Bit Strings that have 1 in position third from the end

Page 11: Introduction to Computability Theory

Example - A Complicated DFA

• Can you guess the language?

000 011

010

0011 1 1

1

1

1 1

10

00

00

00

0

100 101

111

110

Can you verify it now?

Page 12: Introduction to Computability Theory

A finite automaton is a 5-tupple where:

1. is a finite set called the states.2. is a finite set called the alphabet.3. is the transition function.4. is the start state, and5. is the set of accepting states.

DFA – A Formal Definition(Rerun)

12

FqQ ,,,, 0

Q

QQ :

Qq 0

QF

Page 13: Introduction to Computability Theory

A finite automaton is a 5-tupple where:

1. is a finite set called the states.2. is a finite set called the alphabet.3. is the transition function.

( )4. is the start state, and5. is the set of accept states

QPQ :

NFA – A Formal Definition

13

FqQ ,,,, 0

Q

Qq 0

QF

Page 14: Introduction to Computability Theory

Differences between NFA-s and DFA-s

There are two differences:1. The range of the transition function is now

. (The set of subsets of the state set ) 2. The transition function allows transitions.

QP Q

14

Page 15: Introduction to Computability Theory

Computations of NFA-s

In general a computation of an NFA, N, on input w, induces a computation tree.

Each path of the computation tree represents a possible computation of N.

The NFA N accepts w, if its computation tree includes at least one path ending with an accepting state.

15

Page 16: Introduction to Computability Theory

Computations of NFA-s

There are two ways to look at computations of an NFA:

• The first is to say that the NFA N “chooses” the right path on its tree of possible computations.

• The second is to say that the NFA N traverses its computation tree “in parallel”.

16

Page 17: Introduction to Computability Theory

Equivalence Between DFAs and NFAs

Now we prove that the class of NFAs is Equivalent to the class of DFA:

Theorem: For every NFA , there exists a DFA , such that .

Proof Idea: The proof is Constructive: We assume that we know , and construct a simulating DFA, .

17

NMM N

NMLNL

N

M

Page 18: Introduction to Computability Theory

We start with an NFA with no transitions.

The equivalent DFA is denoted by:

Construction Demonstration

0,10,1

1q 2q 3q1 0

18

',',',,' 0 FqQD

Page 19: Introduction to Computability Theory

Construction Demonstration

The state set of the equivalent DFA, D, should reflect the fact that at each step of the computation, N may occupy several sates, Thus we define the state set of D as the power-set of the state set of N, namely:

321313221

321

,,,,,'

qqqqqqqqqqqq

QPQ

Page 20: Introduction to Computability Theory

Construction Demonstration

Recall that the transition function of any NFA is defined by .

Do not be confused by the use of as the state set of D . D is a DFA, not the original NFA.

QP QPQ :

Page 21: Introduction to Computability Theory

Construction Demonstration

The alphabet of D, , is identical to the alphabet of N.

The starting state of D corresponds to the starting state of N, namely .

The most complex part of the construction is the transition function:

In the sequel it is demonstrated stage by stage:

0q

Page 22: Introduction to Computability Theory

0,10,1

1q 2q 3q1 0

Construction Demonstration

Since the only state reachable from by 0 is ,we get .

0

1q

1q 1q 11 0,' qq

Page 23: Introduction to Computability Theory

0,10,1

1q 2q 3q1 0

0

1q 21,qq1

Construction Demonstration

Since both and are reachable from by 1,we get .

1q 2q1q

211 ,1,' qqq

Page 24: Introduction to Computability Theory

Similarly we get .

0,10,1

1q 2q 3q1 0

Construction Demonstration

2121 ,1,,' qqqq

0

1q 21,qq1

1

Page 25: Introduction to Computability Theory

and .

0,10,1

1q 2q 3q1 0

Construction Demonstration

3121 ,0,,' qqqq

0

1q 21,qq 31,qq1 0

1

Page 26: Introduction to Computability Theory

Since and ,we get .

0,10,1

1q 2q 3q1 0

Construction Demonstration

211 ,1, qqq 33 1, qq 32131 ,,1,,' qqqqq

321 ,, qqq

00

1q 21,qq 31,qq1 0 1

1

Page 27: Introduction to Computability Theory

Finally we get the following DFA:

0,10,1

1q 2q 3q1 0

Construction Demonstration

1

321 ,, qqq

00

1q 21,qq 31,qq1 0

0

1

1

Page 28: Introduction to Computability Theory

And its disconnected section:

Construction Demonstration

1

321 ,, qqq

00

1q 21,qq 31,qq1 0

0

1

32 ,qq

00

2q 3q1 0

0

1

1

1

Page 29: Introduction to Computability Theory

Since 1,0 is accepted we get that is an accepting state.

0,10,1

1q 2q 3q1 0

Construction Demonstration

1

321 ,, qqq

00

1q 21,qq 31,qq1 0

0

1

31,qq

1

Page 30: Introduction to Computability Theory

Since 1,0,1 is accepted we get that is also an accepting state.

0,10,1

1q 2q 3q1 0

Construction Demonstration

1

321 ,, qqq

00

1q 21,qq 31,qq1 0

0

1

321 ,, qqq

1

Page 31: Introduction to Computability Theory

Wrap Up

In this lecture we:• Introduced NonDeterministic Finite

Automatons.• Demonstrated the equivalence between DFA-s

and NFA-s.

31