# Finite State Automata - PowerPoint PPT Presentation

1 / 12

Finite State Automata. Lecture 4. Finite State Automata FSA. Abstract machines that recognizes strings Can mechanically construct FSA that accepts strings from RE Easy to simulate FSA in Computer program Basis for scanners. Yes. FSA for L. No. FSA for R. RE R. RE NDFSA. NDFSA DFSA.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Finite State Automata

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## Finite State Automata

Lecture 4

### Finite State Automata FSA

• Abstract machines that recognizes strings

• Can mechanically construct FSA that accepts strings from RE

• Easy to simulate FSA in Computer program

• Basis for scanners

Yes

FSA for L

No

FSA for R

RE R

RE NDFSA

NDFSA DFSA

### What is FSA?

• Set of States

• Set of Transitions between States

• Start State

• Set of Final States

• Operation

• Start in Start State

• While input remains do

if transition on current state and character then

set current state to new state

else reject input

if current state is a final state then accept state

else reject state

• C.A.T

• C.A.(T|R)

Final State

Start State

T

C

A

2

3

4

1

Start State

4

C

A

T

2

3

1

5

R

### FSA Examples

• A*

• Identifiers

• Floating Point Numbers

A

1

Start State

[a-z, A-Z]

[a-z, A-Z]

2

1

[0-9]

[0-9]

Start State

[0-9]

[0-9]

.

3

2

4

1

### Non-Deterministic FSA

• Two Types of FSA

• Deterministic FSA or DFSA

• Every transition is labeled with a character

• NO duplicate labels on transition from a state

• Non-deterministic (NDSFSA)

• Transitions can be labeled with empty string

• Duplicate labels allowed

• TWO Types are equivalent in Power

• NDFSA are typically easier to write

• Can convert one to another

l

A

4

1

5

A

### NDFSA Example

Optionally Signed decimal numbers

(+ | - | l) . [0-9]* . (‘.’| l ) . [0-9]*

[0-9]

3

[0-9]

+

[0-9]

.

-

[0-9]

2

4

1

6

l

Start State

.

5

[0-9]

### Two Theorems

• For Every RE , there exists a NDFSA M such that L(R) = L (M)

• For Every NDFSA N, there exists a DFSA M such that L(N) = L(M)

• Hence, for every Regular expression R , there exists a DFSA M such that L(R) = L(M)

• And, best of AL, we can easily construct these FSA!

### Proof of Theorem 1

• Give rules of constructing NDSFA from R

a

M(a)

1) a

a

4) a*

M(a)

M(b)

l

l

2) a.b

Final state

Start state

M(a)

l

l

3) a|b

M(b)

l

l

### Example for Constructing NDFSA from RE

• (0|1|2 |…|9)* is (…(0|1)| …|9)*

l

0

l

l

l

1

l

l

l

---

9

l

l

l

### Proof of Theorem 2

• Basic Idea: keep track of set of states NDFSA may reach on an input

• But DFSA may be exponentially larger than NDFSA

• (a|b)*.b.b

a

l

b

b

2

3

1

4

b

a

a

b

II

I

III

b

b

a