# Finite Automata Simple machines that take in strings (sequences of symbols) as input and recognize whether or note each input string satisfies some condition(s) Finite automata use states to keep track of important information about symbols ## Mathematical definition of a finite automaton $M = (Q, \sum, \delta, q, F)$ - $Q$ is a finite set of states - $\sum$ is a finite set of input symbols called the input alphabet - $\delta$ is the transition function - Takes every pair consisting of a state and an input smbol and returns the next state, this tells us everything we need to know about what the machine does in one computation step - $q \in Q$ is the start state - $F \subseteq Q$ is the set of accept states ## Acceptance by a finite automaton Let M be a finite automaton Let $w = w_1, w_2, ..., w_n$ be n input string over \sum As input string w is process by $M$, define the sequence of visited states $r_0, r_1, ..., r_n$ as follows: - $r_0 = q$ - $\forall i = 0,1, ... n-1, r_{i+1} = \delta(r_i, w_{i+1})$ If $r_n \in F$ then $M$ accepts $w$, otherwise $M$ rejects $w$ Note: The empty string $\epsilon$ has length $0$, it is accepted by $M$ if any only if the start state is an accept state For a given finite automaton $M$, the set of stings accepted by $M$ is the language of $M$ and is denoted $L(M)$ A language $A$ is called regular if there exists a finite automaton $M$ such that $A = L(M)$ ## Example of finite automata A finite automation $M_1$ that accepts $$\{w \in \{0,1\}^* \ | \ n_1(w) \geq 2\}$$ (State diagram on board) A is the start sate and C is the accept state A -> B (On 1) B -> C (On 1) A -> A (On 0) B -> B (On 0) C -> C (On 0, 1) A: we have seen no ones yet B: we have seen exactly one 1 C: we have seen two ore more 1's ## Example 2 of finite automata A finite automation $M_2$ that accepts $$\{w \in \{0,1\}^* \ | \ n_1(w) = 2\}$$ (State diagram on board) A is the start state and C is the accept state A -> B (On 1) B -> C (On 1) C -> D (On 1) A -> A (On 0) B -> B (On 0) C -> C (On 0) D -> D (On 0, 1) Note: D is an example of a dead state, in which you cannot escape after ## Example 3 of finite automata A finite automation $M_3$ that accepts $$\{w \in \{a,b\}^* \ | \ \text{w starts with abb}\}$$ (State diagram on board) A is the start state and D is the accept state A -> B (On a) B -> C (On b) C -> D (On b) D -> D (On a, b) A -> X (On b) B -> X (On a) C -> X (On a) X -> X (On a ,b) ## Example 4 of finite automata A finite automation $M_4$ that accepts (Didn't catch the definition) $$\{w \in \{0,1\}^* \ | \ n_1(w) = 2\}$$ (State diagram on board) A is the start state and D is the accept state (state transitions would go here) A: the most recent symbol was 1 or we have seen no symbols B: the last symbol was 0, but we have noon seen 010 yet C: the last two symbols were 01, but we have not seen 010 D: we have seen the pattern 010