TYPES OF FINITE AUTOMATA:DFA & NFA

33
by: Er. Sukhwinder kaur

description

TYPES OF FINITE AUTOMATA:DFA & NFA. by: Er. Sukhwinder kaur. Topics to be discussed…. Deterministic Finite State Automata (DFA NON DETERMINISTIC FINITE AUTOMATA(NFA) DFA vs NFA Non Deterministic Features of NFA Subset Construction Method Limitations of Finite Automata. - PowerPoint PPT Presentation

Transcript of TYPES OF FINITE AUTOMATA:DFA & NFA

Page 1: TYPES OF FINITE AUTOMATA:DFA & NFA

by: Er. Sukhwinder kaur

Page 2: TYPES OF FINITE AUTOMATA:DFA & NFA

Deterministic Finite State Automata (DFA NON DETERMINISTIC FINITE AUTOMATA(NFA) DFA vs NFA Non Deterministic Features of NFA Subset Construction Method Limitations of Finite Automata

Page 3: TYPES OF FINITE AUTOMATA:DFA & NFA

Let M = (Q, , δ,q0, F) be a finite automaton and let w = w1w2…wn be a string where each wi is a member of alphabet ∑.

Where Q= total no of states = input alphabet δ= transition function F=final state

Page 4: TYPES OF FINITE AUTOMATA:DFA & NFA

One-way, infinite tape, broken into cells

One-way, read-only tape head.

Finite control, I.e., a program, containing the position of the read head, current symbol being scanned, and the current “state.”

A string is placed on the tape, read head is positioned at the left end, and the DFA will read the string one symbol at a time until all symbols have been read. The DFA will then either accept or reject.

Page 5: TYPES OF FINITE AUTOMATA:DFA & NFA

For every string x, there is a unique path from initial state and associated with x.The finite control can be described by a transition diagram:

Example #1:

Page 6: TYPES OF FINITE AUTOMATA:DFA & NFA

q3

q0 q1

q2

Start

1

1

1

1

0 0 0 0

Here is a DFA for the language that is the set of all strings of 0’s and 1’s whose numbers of 0’s and 1’s are both even:

back

Page 7: TYPES OF FINITE AUTOMATA:DFA & NFA

For any string x, there may exist none or more than one path from initial state and associated with x.

x is accepted if there is some path that ends at a accept state.

Page 8: TYPES OF FINITE AUTOMATA:DFA & NFA

We can have a simpler representation for common suffix language using NFA:

Use subset construction to convert it to a DFA.

back

Page 9: TYPES OF FINITE AUTOMATA:DFA & NFA

Deterministic vs nondeterministicFor every nondeterministic automata, there is an equivalent deterministic automata

Finite acceptors are equivalent iff they both accept the same language

L(M1) = L(M2)

Page 10: TYPES OF FINITE AUTOMATA:DFA & NFA

Deterministic vs nondeterministicIn DFA, label resultant state as a set of states

{q1, q2, q3,…}For a set of |Q| states, there are exactly 2Q subsets

Finite number of states

back

Page 11: TYPES OF FINITE AUTOMATA:DFA & NFA

There are three main cases of non- determinism in NFAs:1. Transition to a state without consuming any input.2. Multiple transitions on the same input symbol.3. No transition on an input symbol.

To convert NFAs to DFAs we need to get rid of non-determinism from NFAs.

back

Page 12: TYPES OF FINITE AUTOMATA:DFA & NFA

Using Subset construction method to convert NFA to DFA involves the following steps:

For every state in the NFA, determine all reachable statesreachable states for every input symbol.

The set of reachable states constitute a single statesingle state in the converted DFA (Each state in the DFA corresponds to a subset of states in the NFA).

Find reachable statesreachable states for each new DFAnew DFA state, until no more new states can be found.

Fig1. NFA without λ-transitions

Page 13: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig1. NFA without λ-transitions

1

3

2

4

5

a aaaa

aa

aa

b

b

b

a,b

a,b

Page 14: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig1. NFA without λ-transitions

Step1Step1

1

3

2

4

5

a aaaa

aa

aa

b

b

b

a,b

a,b

Construct a transition table showing all reachable states for every state for every input signal.

Page 15: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig1. NFA without λ-transitions Fig2. Transition table

1

3

2

4

5

a aaaa

aa

aa

b

b

b

a,b

a,b

Page 16: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig1. NFA without λ-transitions Fig2. Transition table

1

3

2

4

5

a aaaa

aa

aa

b

b

b

a,b

a,b

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

Page 17: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig1. NFA without λ-transitions Fig2. Transition table

1

3

2

4

5

a aaaa

aa

aa

b

b

b

a,b

a,b

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

Transition from state q with input a

Transition from state q with input b

Starts here

Page 18: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

Cont…

Step2Step2

The set of states resulting from every transition function constitutes a new state. Calculate all reachable states for every such state for every input signal.

Page 19: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

Starts withInitial state

Fig3. Subset Construction tableFig3. Subset Construction table

Page 20: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5}

{4,5}{4,5}

Starts withInitial state

Fig3. Subset Construction tableFig3. Subset Construction table

Page 21: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5}

{4,5}{4,5}

Starts withInitial state

Fig3. Subset Construction tableFig3. Subset Construction table

Step3Step3

Repeat this process(step2) until no more new states are reachable.

Page 22: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5}

{2,4,5}{2,4,5}

Fig3. Subset Construction tableFig3. Subset Construction table

Page 23: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5}

55

44

Fig3. Subset Construction tableFig3. Subset Construction table

Page 24: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55

44

{3,5}{3,5}

Fig3. Subset Construction tableFig3. Subset Construction table

Page 25: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44

{3,5}{3,5}

Fig3. Subset Construction tableFig3. Subset Construction table

Page 26: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5}

We already got 4 and 5.So we don’t add them again.

Fig3. Subset Construction tableFig3. Subset Construction table

Page 27: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5} ∅ 22

∅22

Fig3. Subset Construction tableFig3. Subset Construction table

Page 28: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5} ∅ 22

∅ ∅ ∅22

Fig3. Subset Construction tableFig3. Subset Construction table

Page 29: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5} ∅ 22

∅ ∅ ∅22 33 5533

Fig3. Subset Construction tableFig3. Subset Construction table

Page 30: TYPES OF FINITE AUTOMATA:DFA & NFA

Fig2. Transition table

q δ(q,a) δ(q,b)

11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

22 {3}{3} {5}{5}

33 ∅ {2}{2}

44 {5}{5} {4}{4}

55 ∅ ∅

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5} ∅ 22

∅ ∅ ∅22 33 5533 ∅ 22

Fig3. Subset Construction tableFig3. Subset Construction table

Stops here as there are no more reachable states

Page 31: TYPES OF FINITE AUTOMATA:DFA & NFA

q δ(q,a) δ(q,b)11 {1,2,3,4,5}{1,2,3,4,5} {4,5}{4,5}

{1,2,3,4,5}{1,2,3,4,5} {1,2,3,4,5}{1,2,3,4,5} {2,4,5}{2,4,5}

{4,5}{4,5} 55 44

{2,4,5}{2,4,5} {3,5}{3,5} 44

55 ∅ ∅44 55 44

{3,5}{3,5} ∅ 22

∅ ∅ ∅22 33 55

33 ∅ 22

1

45

12345 245

35

5

4

∅3

2

a

a

a

a

a

a

a

a

b

b

b

b

bb

b

b

a,b

a,b

Fig3. Subset Construction tableFig3. Subset Construction tableFig4. Resulting FA after Fig4. Resulting FA after applying Subset applying Subset Construction to fig1Construction to fig1

back

Page 32: TYPES OF FINITE AUTOMATA:DFA & NFA

Obvious: Can only accept languages that can be represented in finite memory!Can this language be represented with a FA?

L(M)=(ai bi | i n)How about this one?

L(M)=(ai bi | i > 0)

back

Page 33: TYPES OF FINITE AUTOMATA:DFA & NFA

Thank You