2022-07-16 16:55:57 -07:00
|
|
|
# Finite Automata
|
|
|
|
***(AKA: Finite State Machine)***
|
|
|
|
|
|
|
|
Mechanism and abstraction used behind regular grammars.
|
|
|
|
|
|
|
|
Usually has its state represented using nodes and edges.
|
|
|
|
|
|
|
|
Regular grammar:
|
|
|
|
```
|
|
|
|
S -> bA
|
|
|
|
A -> epsilon
|
|
|
|
```
|
|
|
|
Equivalent to: `\b\`
|
|
|
|
|
|
|
|
State transition:
|
|
|
|
|
|
|
|
--label--> : Transition symbol
|
|
|
|
O : State Symbol
|
|
|
|
(o) : Accepting State
|
|
|
|
->O.Start : Starting State (State transition to Start)
|
|
|
|
|
|
|
|
Ex:
|
|
|
|
|
|
|
|
->O.*Start* --*transition*--> (o).*Accepting*
|
|
|
|
|
|
|
|
*ε* - Epsilon (Empty String)
|
|
|
|
`I will be spelling it out as I do not enjoy single glyth representation`
|
|
|
|
|
|
|
|
Two main types of Finite Automtata :
|
|
|
|
|
|
|
|
FA w/ output
|
|
|
|
* Moore machine
|
|
|
|
* Mealy machine
|
|
|
|
|
|
|
|
FA w/o output
|
|
|
|
* DFA - Deterministic
|
|
|
|
* NFA - Non-deterministic
|
|
|
|
* epsilon-NFA - (Epsilon Transition) special case
|
|
|
|
|
|
|
|
NFA : Non-deterministic FA - Allos transition on the same symbol to
|
|
|
|
different states
|
|
|
|
|
|
|
|
```
|
2022-07-16 17:01:13 -07:00
|
|
|
a->o
|
2022-07-16 16:55:57 -07:00
|
|
|
/
|
|
|
|
->o.1---b-->o
|
|
|
|
\
|
2022-07-16 17:01:13 -07:00
|
|
|
a->o
|
2022-07-16 16:55:57 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
epsilon-NFA : Extension of NFA that allows *epsilon* transitions
|
|
|
|
|
|
|
|
```
|
2022-07-16 17:01:13 -07:00
|
|
|
a--->o---epsi--->(o)
|
|
|
|
/ /
|
2022-07-16 16:55:57 -07:00
|
|
|
->o----b-->epsi--->o
|
|
|
|
\
|
2022-07-16 17:01:13 -07:00
|
|
|
a-->o--epsi-->(o)
|
2022-07-16 16:55:57 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
DFA : A state machine which forbids multiple transitions on the same symbol, and *epsilon* transitions
|
|
|
|
|
|
|
|
```
|
2022-07-16 17:01:13 -07:00
|
|
|
a--->o
|
2022-07-16 16:55:57 -07:00
|
|
|
/
|
|
|
|
->o----b-->o
|
|
|
|
```
|
|
|
|
|
|
|
|
Use case:
|
|
|
|
|
|
|
|
Implementation Transformations:
|
|
|
|
```RegExp -> epsilon-NFA -> ... -> DFA```
|
|
|
|
|
|
|
|
## Formal Definition:
|
|
|
|
|
|
|
|
Non-deterministic finite automata is a tuple of five elements:
|
|
|
|
* All possible states
|
|
|
|
* Alphabet
|
|
|
|
* Transition Function
|
|
|
|
* Starting State
|
|
|
|
* Set of accepting states
|
|
|
|
|
|
|
|
NFA = ( States, Alphabet, TransitionFunction, StartingState, AcceptingStates )
|
|
|
|
|
|
|
|
NFA = ( Q, Σ, Δ, q0, F )
|