Finite State Machines
Chapter overview: Finite State Machines add a finite amount of persistent state. They can recognize regular languages and can also be viewed as generators of strings or sequences.
2.1 FSM as Acceptor
Introduction / Definition
An FSM used as an acceptor reads an input string one symbol at a time and decides whether the string belongs to a language. A deterministic finite automaton (DFA) is commonly represented as M=(Q,Σ,δ,q₀,F), where Q is a finite set of states, Σ is the alphabet, δ is the transition function, q₀ is the start state, and F is the set of accepting states.
Syntax / Structure / Formula
δ : Q × Σ → Q
M = (Q, Σ, δ, q₀, F)
Detailed Explanation
After reading every symbol, the FSM changes state according to δ. If the final state belongs to F, the string is accepted. For example, a DFA can recognize binary strings ending in 01.
Example
States: q0=start, q1=last symbol was 0, q2=ends in 01
Input: 1101
Path: q0 → q0 → q1 → q2
Output / Result
1101 is accepted because the final state is q2.
Important Points / Notes
- DFA has exactly one next state for each state-symbol pair.
- NFA may have multiple possible transitions.
- FSMs recognize exactly the regular languages.
- FSMs have finite memory.
Mini Practice Question
Design a DFA that accepts binary strings containing at least one 1.
2.2 FSM as Generator
Introduction / Definition
An FSM can be interpreted as a generator when its transitions or states are used to produce strings or sequences rather than merely test an input. A finite-state generator starts from an initial state and follows transitions, emitting symbols along the way. This view is useful in sequence generation, protocol modeling, and simple pattern generation.
Syntax / Structure / Formula
- State transition: qᵢ --a/output--> qⱼ
Detailed Explanation
A generator can produce strings in a regular language by following allowed transitions. If q0 can emit 0 and return to q0, or emit 1 and move to another state, its paths define the possible generated sequences.
Example
q0 --0--> q0
q0 --1--> q1
q1 --0--> q0
Output / Result
Possible generated prefixes include 0, 00, 01, 010, 0100, etc., depending on the stopping rule.
Important Points / Notes
- Generation and recognition are two views of finite-state systems.
- Only finitely many states are available.
- Generated languages are regular when generation is finite-state.
Mini Practice Question
Give a finite-state generator for alternating 0 and 1 symbols.
2.3 Regular Expressions
Introduction / Definition
A regular expression is a formal notation for describing regular languages. Basic operations include union, concatenation, and Kleene star. Regular expressions are widely used in search, validation, lexical analysis, and text processing.
Syntax / Structure / Formula
Union: R | S
Concatenation: RS
Kleene star: R*
Example: (0|1)*01
Detailed Explanation
The expression (0|1)*01 describes all binary strings ending in 01. The star allows any sequence of 0s and 1s before the final 01.
Example
(0|1)*01
Matches: 01, 101, 0001, 1101
Does not match: 10, 111
Output / Result
The matching strings are exactly the binary strings whose final two symbols are 01.
Important Points / Notes
- ε is the empty string.
- R* means zero or more repetitions.
- Regular expressions describe regular languages.
- Operator precedence and parentheses matter.
Mini Practice Question
Write a regular expression for binary strings containing only 0s.
2.4 Equivalence
Introduction / Definition
Two computational descriptions are equivalent when they define the same language or computational behavior. For regular languages, deterministic finite automata, nondeterministic finite automata, and regular expressions have equivalent expressive power. This is a central result of automata theory.
Syntax / Structure / Formula
L(DFA) = L(NFA) = L(RE)
DFA ↔ NFA ↔ Regular Expression
Detailed Explanation
An NFA can be converted to a DFA using subset construction. A finite automaton can be converted to a regular expression, and a regular expression can be converted to an automaton. The machines may differ in size, but their recognized language can be the same.
Example
RE: (0|1)*01
DFA: states tracking whether the final suffix is 01
Output / Result
Both descriptions recognize the same language: binary strings ending in 01.
Important Points / Notes
- Equivalent does not mean identical structure.
- Conversions may increase the number of states.
- Equivalence concerns expressive behavior/language.
Mini Practice Question
Why can an NFA and DFA with different numbers of states still be equivalent?