Conversion of NFA to FSA using Subset Construction Algorithm - Prof. Eric Torng, Exams of Computer Science

The process of converting a non-deterministic finite automaton (nfa) into a deterministic finite automaton (dfa) using the subset construction algorithm. It includes the theorem and visualization of the conversion process, construction specification, and step-by-step construction of the fsa from the nfa.

Typology: Exams

Pre 2010

Uploaded on 07/23/2009

koofers-user-10r-1
koofers-user-10r-1 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
1
Module 19
LNFA subset of LFSA
Theorem 4.1 on page 105 of Martin textb ook
Compare with set closure proofs
Main idea
A state in FSA represents a set of states in
original NFA
2
LNFA subset LFSA
Let L be an arbitrary language in LNFA
Let M be the NFA such that L(M) = L
M exists by definition of L in LNFA
Construct an FSA M’ such that L(M’ ) = L
Argue L(M’) = L
There exists an FSA M’ such that L(M’) = L
L is in LFSA
By definition of L in LFSA
3
Visualization
LNFA LFSA
NFA’s FSA’s
LL
MM’
•Let L be an arbitrary language in LNFA
•Let M be an NFA such that L(M) = L
•M exists by definition of L in LNFA
•Construct FSA M’ from NFA M
•Argue L(M’) = L
•There exists an FSA M’ such that L(M’)
= L
•L is in LFSA
4
Construction Specification
We need an algorithm which does the
following
Input: NFA M
Output: FSA M’ such that L(M’) = L(M)
5
An NFA can be in
several states after
processing an input
string x
Difficulty *
a a ab
a,b a,b
Input string aaaaba
(1, aaaaba)
(1, aaaba) (2, aaaba)
(1, aaba) (2, aaba) (3, aaba)
(1, aba) (2, aba) (3, aba) crash
(1, ba) (2, ba) (3, ba)
(1, a) (4, a)
(1, λ) (2, λ) (5, λ)
6
All strings which end up
in the set of states {1,2,3}
are indistinguishable with
respect to L(M)
Observation *
a a ab
a,b a,b
Input string aaaaba
(1, aaaaba)
(1, aaaba) (2, aaaba)
(1, aaba) (2, aaba) (3, aaba)
(1, aba) (2, aba) (3,aba) crash
(1, ba) (2,ba) (3, ba)
(1, a) (4, a)
(1, λ) (2, λ) (5, λ)
pf3
pf4

Partial preview of the text

Download Conversion of NFA to FSA using Subset Construction Algorithm - Prof. Eric Torng and more Exams Computer Science in PDF only on Docsity!

1

Module 19

• LNFA subset of LFSA

– Theorem 4.1 on page 105 of Martin textbook

– Compare with set closure proofs

• Main idea

– A state in FSA represents a set of states in

original NFA

2

LNFA subset LFSA

• Let L be an arbitrary language in LNFA

• Let M be the NFA such that L(M) = L

  • M exists by definition of L in LNFA

• Construct an FSA M’ such that L(M’) = L

• Argue L(M’) = L

• There exists an FSA M’ such that L(M’) = L

• L is in LFSA

  • By definition of L in LFSA

3

Visualization

LNFA

LFSA

NFA’s FSA’s

L L

M M’

•Let L be an arbitrary language in LNFA

•Let M be an NFA such that L(M) = L

•M exists by definition of L in LNFA

•Construct FSA M’ from NFA M

•Argue L(M’) = L

•There exists an FSA M’ such that L(M’)

= L

•L is in LFSA

4

Construction Specification

• We need an algorithm which does the

following

– Input: NFA M

– Output: FSA M’ such that L(M’) = L(M)

5

• An NFA can be in

several states after

processing an input

string x

Difficulty *

a a b a

a,b a,b

Input string aaaaba

(1, aaaaba)

(1, aaaba) (2, aaaba)

(1, aaba) (2, aaba) (3, aaba)

(1, aba) (2, aba) (3, aba) crash

(1, ba) (2, ba) (3, ba)

(1, a) (4, a)

(1, λ) (2, λ) (5, λ) 6

  • All strings which end up

in the set of states {1,2,3}

are indistinguishable with

respect to L(M)

Observation *

a a b a

a,b a,b

Input string aaaaba

(1, aaaaba)

(1, aaaba) (2, aaaba)

(1, aaba) (2, aaba) (3, aaba)

(1, aba) (2, aba) (3, aba) crash

(1, ba) (2, ba) (3, ba)

(1, a) (4, a)

(1, λ) (2, λ) (5, λ)

7

  • Given an NFA M = (Q,Σ,q 0 ,δ,A), the equivalent FSA M’

should have one state for each subset of Q

  • Example
    • In this case there are 5 states in Q
    • There are 2^5 subsets of Q including {} and Q
    • The FSA M’ will have 2^5 states
  • What strings end up in state {1,2,3} of M’?
    • The strings which end up in states 1, 2, and 3 of NFA M.
    • In this case, strings which do not contain aaba and end with aa

such as aa, aaa, and aaaa.

Idea

a a b a

a,b a,b

Input string aaaaba

8

Idea Illustrated

a a b a

a,b a,b

Input string aaaaba

( 1 ,aaaaba) ({ 1 }, aaaaba) ( 1 , aaaba) ( 2 , aaaba) ({1,2}, aaaba)

( 1 , aaba) ( 2 , aaba) ( 3 , aaba) ({1,2,3}, aaba)

( 1 , aba) ( 2 , aba) ( 3 , aba) ({1,2,3}, aba)

( 1 , ba) ( 2 , ba) ( 3 , ba) ({1,2,3}, ba)

( 1 , a) ( 4 , a) ({1,4}, a)

( 1 , λ) ( 2 , λ) ( 5 , λ)^ ({1,2,5},^ λ)

9

Construction *

• Input NFA M = (Q, Σ, q 0 , δ, A)

• Output FSA M’ = (Q’, Σ’, q’, δ’, A’)

  • What is Q’?
    • all subsets of Q including Q and {}
    • In this case, Q’ =
  • What is Σ’?
    • We always make Σ’ = Σ
    • In this case, Σ’ = Σ = {a,b}
  • What is q’?
    • We always make q’ = {q 0 }
    • In this case q’ =

a,b a,b a a

NFA M

10

Construction *

  • Input NFA M = (Q, Σ, q 0 , δ, A)
  • Output FSA M’ = (Q’, Σ’, q’, δ’, A’)
    • What is A’?
      • Suppose a string x ends up in states 1 and 2 of the NFA M above.
        • Is x accepted by M?
        • Should {1,2} be an accepting state in FSA M’?
      • Suppose a string x ends up in states 1 and 2 and 3 of the NFA M above.
        • Is x accepted by M?
        • Should {1,2,3} be an accepting state in FSA M’?
      • Suppose p = {q 1 , q 2 , …, qk} where q 1 , q 2 , …, qk are in Q
      • p is in A’ iff at least one of the states q 1 , q 2 , …, qk is in A
      • In this case, A’ =

a,b a,b a a

NFA M

11

Construction *

• Input NFA M = (Q, Σ, q 0 , δ, A)

• Output FSA M’ = (Q’, Σ’, q’, δ’, A’)

  • What is δ’?
    • If string x ends up in states 1 and 2 after being processed by the

NFA above, where does string xa end up after being processed

by the NFA above?

  • Figuring out δ’(p,a) in general
    • Suppose p = {q 1 , q 2 , …, qk} where q 1 , q 2 , …, qk are in Q
    • Then δ’(p,a) = δ(q 1 ,a) union δ(q 2 ,a) union … union δ(qk,a) » Similar to 2 FSA to 1 FSA construction
    • In this case » δ’({1,2},a) =

a,b a,b a a

NFA M

12

Construction

Summary

  • Input NFA M = (Q, Σ, q 0 , δ, A)
  • Output FSA M’ = (Q’, Σ’, q’, δ’, A’)
    • Q’ = all subsets of Q including Q and {}
      • In this case, Q’ = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
    • Σ’ = Σ
      • In this case, Σ’ = Σ = {a,b}
    • q’ ={q 0 }
      • In this case, q’ = {1}
    • A’
      • Suppose p = {q 1 , q 2 , …, qk} where q 1 , q 2 , …, qk are in Q
      • p is in A’ iff at least one of the states q 1 , q 2 , …, qk is in A
    • δ’
      • Suppose p = {q 1 , q 2 , …, qk} where q 1 , q 2 , …, qk are in Q
      • Then δ’(p,a) = δ(q 1 ,a) union δ(q 2 ,a) union … union δ(qk,a)

a,b a,b a a

NFA M

19

Step 4: Answer

a,b

A a^ B b C

NFA M

Initial state is {A}

Set of final states A’ = {{B,C}}

{A} {B} {}

a b

{B} {B} {B,C}

{B,C} {B} {B,C}

This is sufficient. You do NOT need to turn this into a diagram.

20

Step 5:

Optional

a,b

A a^ B b C

NFA M

a

{A} a^ {B} b {B,C}

b

a

a,b

b

FSA M’

21

Comments

  • You should be able to execute this algorithm
    • You should be able to convert any NFA into an equivalent FSA.
  • You should understand the idea behind this algorithm
    • For an FSA M’, strings which end up in the same state of M’ are

indistinguishable wrt L(M’)

  • For an NFA M, strings which end up in the same set of states of M

are indistinguishable wrt L(M)

22

Comments

  • You should understand the importance of this algorithm
    • Design tool
      • We can design using NFA’s
      • A computer will convert this NFA into an equivalent FSA
        • FSA’s can be executed by computers whereas NFA’s cannot (or at least cannot easily be run by computers)
    • Chaining together algorithms
      • Perhaps it is easy to build NFA’s to accept L 1 and L 2
      • Use this algorithm to turn these NFA’s to FSA’s
      • Use previous algorithm to build FSA to accept L 1 intersect L 2
  • You should be able to construct new algorithms for new

closure property proofs