Mathematics.

formal languages

Finite Automata

Theory of Computation45 minDifficulty5 out of 10

You should know: set basics

Overview

A finite automaton is the simplest formal model of computation: a machine with a finite set of states that reads an input symbol at a time and moves between states according to fixed rules, accepting or rejecting the input based on which state it ends in. Despite their simplicity, finite automata exactly capture the 'regular languages' — the class of patterns matched by regular expressions — and form the theoretical foundation of lexical analysis in compilers, text search, and protocol design.

Intuition

Think of a vending machine that only accepts a specific coin sequence. It has a small number of 'states' (how much money inserted so far), and each coin moves it to a new state. If it ends in the 'dispense' state after the input stops, it accepts; otherwise it rejects. A finite automaton generalizes this: any pattern-matching task where the answer only depends on a fixed, finite amount of 'memory' about what's been seen so far can be modeled this way.

Interactive Graph

A state diagram — explore traversal order

Loading visualization…

Formal Definition

Definition

A deterministic finite automaton (DFA) is a 5-tuple:

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)
Definition
δ:Q×ΣQ\delta: Q \times \Sigma \to Q

The transition function: current state × input symbol → next state

Notation

NotationMeaning
QQThe finite set of states
Σ\SigmaThe input alphabet (finite set of symbols)
δ\deltaThe transition function
q0q_0The start state
FQF \subseteq QThe set of accepting (final) states

Derivation

Building a DFA that accepts binary strings with an even number of 1s: two states track the parity of 1s seen so far.

Q={qeven,qodd},q0=qeven,F={qeven}Q = \{q_{\text{even}}, q_{\text{odd}}\}, \quad q_0 = q_{\text{even}}, \quad F = \{q_{\text{even}}\}
δ(qeven,1)=qodd,δ(qodd,1)=qeven,δ(q,0)=q\delta(q_{\text{even}}, 1) = q_{\text{odd}}, \quad \delta(q_{\text{odd}}, 1) = q_{\text{even}}, \quad \delta(q, 0) = q

Reading a 1 flips parity; reading a 0 does nothing

Theorems

Theorem 1: NFA-DFA equivalence
For every nondeterministic finite automaton (NFA), there exists a DFA that accepts the exact same language (via the subset construction).\text{For every nondeterministic finite automaton (NFA), there exists a DFA that accepts the exact same language (via the subset construction).}
Theorem 2: Kleene's theorem
A language is recognized by some finite automaton if and only if it is described by some regular expression.\text{A language is recognized by some finite automaton if and only if it is described by some regular expression.}

Applications

Lexical analyzers in compilers use DFAs to tokenize source code (identifying keywords, numbers, operators).

Worked Examples

  1. Two states: 'last symbol was 0' (start, non-accepting) and 'last symbol was 1' (accepting).

    δ(q0,1)=q1, δ(q1,1)=q1, δ(q0,0)=q0, δ(q1,0)=q0\delta(q_0, 1) = q_1,\ \delta(q_1, 1)=q_1,\ \delta(q_0,0)=q_0,\ \delta(q_1,0)=q_0

Answer: A 2-state DFA with F = {q₁}

Practice Problems

Difficulty 5/10

How many states does the minimal DFA need to recognize binary strings divisible by 3 (as a binary number)?

Difficulty 4/10

A subway turnstile has two states: Locked and Unlocked. A coin unlocks it; pushing through re-locks it. Model this as a finite automaton — how many states and what are the transitions?

Difficulty 6/10

Every compiler's lexical analyzer (tokenizer) and every regex engine is built on finite automata. Explain why a DFA can scan input text in time linear in its length.

Difficulty 6/10

Which task is IMPOSSIBLE for a finite automaton (a regular language limitation)?

Common Mistakes

Common Mistake

Assuming nondeterministic automata (NFAs) are strictly more powerful than DFAs.

NFAs and DFAs recognize exactly the same class of languages (regular languages) — NFAs can just be more concise to describe; any NFA can be converted to an equivalent DFA (possibly with exponentially more states).

Quiz

Why can a DFA scan a text string of length n in O(n) time?
Real-world systems modelled directly as finite automata include:
Matching arbitrarily-deep nested parentheses is impossible for a finite automaton because:

Historical Background

Finite automata were formalized in the 1940s-50s by Warren McCulloch and Walter Pitts (modeling neurons) and later by Stephen Kleene, who proved their equivalence to regular expressions in 1956. Michael Rabin and Dana Scott's 1959 paper on nondeterministic automata (winning them the 1976 Turing Award) showed nondeterministic and deterministic finite automata recognize exactly the same languages — a foundational result in computer science.

  1. 1943

    McCulloch and Pitts model neural networks with finite-state machines

    Warren McCulloch, Walter Pitts

  2. 1956

    Stephen Kleene proves finite automata are equivalent to regular expressions

    Stephen Kleene

  3. 1959

    Rabin and Scott formalize nondeterministic finite automata (NFA)

    Michael Rabin, Dana Scott

Summary

  • A finite automaton is a state machine with a finite number of states, transitioning on input symbols.
  • Formally a 5-tuple (Q, Σ, δ, q₀, F).
  • DFAs and NFAs recognize exactly the regular languages (Kleene's theorem).
  • Finite automata underlie lexical analysis, regex engines, and protocol verification.

References