← Back
CSNotes

Finite Automata (Finite memory/states)

  • States are switched by reading input symbols
  • Initial state has the arrow pointing to it
  • Final state has two circles around it

DFSM (Deterministic Finite Automata):

  • K is a finite set of states
  • Σ\Sigma is an alphabet
  • s∈Ks \in K is the initial state
  • A⊆KA \subseteq K is the set of accepting (final) states
  • δ\delta is the transition function from (K×ΣK \times \Sigma) to KK

δ:K×Σ→K\delta: K \times \Sigma \rightarrow K

δ(p,a)=q:pa→q\delta(p, a) = q : p \frac{a}{\rightarrow} q

Accepting by a DFSM:

  • Basically when you read the string w iff reading M ends at the final state then the string w is accepted, else it is rejected.
  • The language accepted by M, L(M), is the set of all strings accepted by M.
  • Also no ϵ\epsilon transitions and no choice

Drawing Example

TBA from prof example notes

Symbols Example

TBA from prof example notes

Theorem: Every DFSM M, on input s, halts in ∣s∣|s| steps.

Example:

Regular Languages

A language is regular iff it is accepted by some FSM.

Examples:

L={w∈{a,b}∗:every a is immediately follow by a b}L = \{w \in \{a, b\}^{*} : \text{every a is immediately follow by a b}\}

L={w∈{0,1}∗:w has odd parity}L = \{w \in \{0, 1\}^{*} : \text{w has odd parity}\}

L={w∈{a,b}∗:w contains at most b}L = \{w \in \{a, b\}^{*} : \text{w contains at most b}\}


When the starting state IS the final state, then that means you are accepting ϵ\epsilon

This also means that ϵ\epsilon is accepting (in the language)

So basically a iff relationship


L={w∈{a,b}∗:no two consecutive characters are the same}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{no two consecutive characters are the same}\rbrace}

L={w∈{a,b}∗:every a region in w is of even length}L = \{w \in \{a, b\}^{*} : \text{every a region in w is of even length}\}

L={w∈{a,b}∗:every b in w is surrounded by a’s}L = \{w \in \{a, b\}^{*} : \text{every b in w is surrounded by a's}\}


Therefore, DFSMs are complete since their transition functions are always complete (So any missing transitions lead to the "dead" state - even if it is not shown for clarity)

Programming FSMs

In this example we want to cluster strings that share a "future"

L={w∈{a,b}∗:w contains an even number of a’s and an odd number of b’s}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{w contains an even number of a's and an odd number of b's}\rbrace}

L={w∈{a−z}∗:all five vowels, a, e, i, o, and u, occur in w in alphabetical order}L = \lbrace{w \in \lbrace{a - z\rbrace}^{*} : \text{all five vowels, a, e, i, o, and u, occur in w in alphabetical order}\rbrace}

L={w∈{a,b}∗:w does not contain the substring aab}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{w does not contain the substring aab}\rbrace}

  • It is easier to construct the DFA for L={w∈{a,b}∗:w contains aab}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{w contains aab}\rbrace}
  • So start with ¬L\neg L and complement it

¬L\neg L:

How to complement:

Just flip the accepting and rejecting states

L:

The Missing Letter Language

Let Σ={a,b,c,d}\Sigma = \lbrace{a, b, c, d\rbrace}

Let LMissing={w:there is a symbol ai ∈Σ not appearing in w}L_{\text{Missing}} = \lbrace{w : \text{there is a symbol} \ a_{i} \ \in \Sigma \ \text{not appearing in} \ w\rbrace}

Trying to make a DFSM for LMissingL_{\text{Missing}} is super difficult but apparently making a NDFSM) (Non-deterministic FSM) is easier.

See The Missing Letter Language NDFSM

NDFSM (Non-Deterministic Finite State Machine)

  • K is a finite set of states
  • Σ\Sigma is an alphabet
  • s∈Ks \in K is the initial state
  • A⊆KA \subseteq K is the set of accepting states
  • Δ\Delta is the transition relation. It is a finite subset of (K×(Σ∪{ϵ}))×K(K \times (\Sigma \cup \{\epsilon\})) \times K
    • No longer a function because from the same state the same input, you can get to different states

Accepting by an NDFSM:

  • Basically M accepts a string w iff there exists some path along which w drives M to some element of A.
    • In English, w is accepted if it moves the initial state to literally any of the possible accepting states
    • So if all are rejecting then you reject w (w is NOT in L(M))
  • The language accepted by M, L(M), is the set of all strings accepted by M.

Optional Substrings

L={w∈{a,b}∗:w is made up of an optional a followed by aa followed by zero or more b’s}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{w is made up of an optional a followed by aa followed by zero or more b's}\rbrace}

L={w∈{a,b}∗:w = aba or |w| is even}L = \lbrace{w \in \lbrace{a, b\rbrace}^{*} : \text{w = aba or |w| is even}\rbrace}

For or, split the branch/path and use ϵ\epsilon as the transition symbol on both paths as the or is the inclusive or.

The Missing Letter Language NDFSM

Let Σ={a,b,c,d}\Sigma = \lbrace{a, b, c, d\rbrace}

Let LMissing={w:there is a symbol ai ∈Σ not appearing in w}L_{\text{Missing}} = \lbrace{w : \text{there is a symbol} \ a_{i} \ \in \Sigma \ \text{not appearing in} \ w\rbrace}

Now it is easier:

L={w∈{a,b,c}∗:∃x,y∈{a,b,c}∗ (w=x abcabb y)}L = \lbrace{w \in \lbrace{a, b, c\rbrace}^{*} : \exists{x, y} \in \lbrace{a, b, c\rbrace}^{*} \ (\text{w} = \text{x abcabb y})\rbrace}

Pattern Matching using a DFSM:

Pattern Matching Using an NDFSM:

Analyzing Nondeterministic FSMs

You can do this in 2 ways:

  • Explore a search tree
  • Follow all paths in parallel
    • You can use sets of states instead of just states which makes it DETERMINISTIC

Dealing with Epsilon Transitions

Simulating a NDFSM

Example:

NDFSM and DFSM

So clearly: {Languages accepted by a DFSM}⊆{Languages accepted by a NDFSM}\{\text{Languages accepted by a DFSM}\} \subseteq \{\text{Languages accepted by a NDFSM}\}

Theorem 5.3: For each NDFSM, there is an equivalent DFSM

  • NFA are Easy to Build while
  • DFA are Easy to Use

So build an NFA FIRST, and then make it an DFA

Finally, we can use this algorithm to Construct a DFSM from a NDFSM:

  1. Compute the eps(q)′seps(q)'s
  2. Compute s′=eps(s)s' = eps(s)
  3. Compute δ′\delta'
  4. Compute K′=a subset of P(K)K' = \text{a subset of} \ \mathcal{P}(K)
  5. Compute A′={Q∈K′:Q∩A≠∅}A' = \lbrace{ Q \in K' : Q \cap A \neq \emptyset \rbrace}

Hard Example to complete: