4.6.2Theory of Computation

Finite automata — DFA - formal definition (5-tuple), state diagrams

2,053 words9 min readdifficulty · medium6 backlinks

WHY does this object exist?


The formal 5-tuple — derived, not dumped

We will build the definition by asking "what do I minimally need to describe such a machine?"

I need to know... so I introduce... symbol
What situations can the machine be in? a finite set of states QQ
What symbols can it read? a finite input alphabet Σ\Sigma
Given (state, symbol), where do I go? a total transition function δ\delta
Where do I begin? a single start state q0q_0
Which endings mean "yes"? a set of accepting states FF

Extending δ to whole strings (the part most notes skip)

δ\delta only handles one symbol. To process a string ww, we define the extended transition function δ^:Q×ΣQ\hat\delta : Q \times \Sigma^* \to Q by recursion on string length:


State diagrams (Dual Coding: picture ↔ tuple)

A state diagram is the visual twin of the tuple:

  • circle = a state in QQ
  • double circle = an accept state (F\in F)
  • an incoming arrow from nowhere ("start") = q0q_0
  • labeled arrow qapq \xrightarrow{a} p = the fact δ(q,a)=p\delta(q,a)=p
Figure — Finite automata — DFA -  formal definition (5-tuple), state diagrams

Worked Example 1 — strings over {0,1} that END in 1

Goal: L={w:w ends in 1}L = \{w : w \text{ ends in } 1\}.

State design (WHAT to remember): the only thing that matters for "ends in 1" is the last symbol seen. So 2 states suffice:

  • q0q_0 = "last symbol was 0, or no symbol yet" → reject
  • q1q_1 = "last symbol was 1" → accept

The tuple:

  • Q={q0,q1}Q=\{q_0,q_1\}, Σ={0,1}\Sigma=\{0,1\}, start q0q_0, F={q1}F=\{q_1\}
  • δ(q0,0)=q0\delta(q_0,0)=q_0, δ(q0,1)=q1\delta(q_0,1)=q_1, δ(q1,0)=q0\delta(q_1,0)=q_0, δ(q1,1)=q1\delta(q_1,1)=q_1

Trace w=1011w=1011:

step reading from to Why this step?
1 1 q0q_0 q1q_1 saw a 1 ⇒ remember "ended in 1"
2 0 q1q_1 q0q_0 a 0 erases that ⇒ "ended in 0"
3 1 q0q_0 q1q_1 back to "ended in 1"
4 1 q1q_1 q1q_1 still ends in 1

End state q1Fq_1 \in Faccepted. ✓ (and indeed "1011" ends in 1)


Worked Example 2 — number of 0's is EVEN (parity)

Goal: L={w{0,1}:#0(w) is even}L=\{w\in\{0,1\}^* : \#0(w)\text{ is even}\}.

WHY 2 states: parity is a yes/no fact; you never need the actual count, just even vs odd. This is the 80/20 insight — keep the minimal memory that distinguishes accept from reject.

  • Q={E,O}Q=\{E,O\} ("even-so-far","odd-so-far"), start EE, F={E}F=\{E\}
  • δ(E,0)=O\delta(E,0)=O, δ(O,0)=E\delta(O,0)=E (a 0 flips parity)
  • δ(E,1)=E\delta(E,1)=E, δ(O,1)=O\delta(O,1)=O (a 1 is irrelevant — self-loop)

Trace w=0100w=0100: E0O1O0E0OE \xrightarrow{0} O \xrightarrow{1} O \xrightarrow{0} E \xrightarrow{0} O. End OFO \notin Frejected. Check: 01000100 has three 0's (odd) ⇒ correctly rejected. ✓


Worked Example 3 — Forecast-then-Verify

Machine: Q={A,B,C}Q=\{A,B,C\}, Σ={a,b}\Sigma=\{a,b\}, start AA, F={C}F=\{C\}, δ(A,a)=B, δ(A,b)=A, δ(B,a)=B, δ(B,b)=C, δ(C,a)=B, δ(C,b)=A.\delta(A,a)=B,\ \delta(A,b)=A,\ \delta(B,a)=B,\ \delta(B,b)=C,\ \delta(C,a)=B,\ \delta(C,b)=A.

Recall Forecast: does this DFA accept "abab"? (predict before reading)

Forecast: CC is reached only by reading "b" while in BB, i.e. an "...ab" ending. So accept iff string ends in "ab". Verify trace of abababab: AaBbCaBbCA\xrightarrow{a}B\xrightarrow{b}C\xrightarrow{a}B\xrightarrow{b}C. End CFC\in Faccepted. Forecast confirmed (it ends in "ab"). ✓


Flashcards

What are the 5 components of a DFA, in order?
(Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F) — states, alphabet, transition function, start state, accept states.
What is the type signature of the DFA transition function δ\delta?
δ:Q×ΣQ\delta : Q \times \Sigma \to Q (total, single-valued).
What makes a finite automaton deterministic?
For every (state, symbol) pair there is exactly one next state — δ\delta is a total function, no choices, no ε\varepsilon-moves.
Define δ^(q,ε)\hat\delta(q,\varepsilon) and δ^(q,xa)\hat\delta(q,xa).
δ^(q,ε)=q\hat\delta(q,\varepsilon)=q; δ^(q,xa)=δ(δ^(q,x),a)\hat\delta(q,xa)=\delta(\hat\delta(q,x),a).
When does a DFA MM accept string ww?
When δ^(q0,w)F\hat\delta(q_0,w)\in F.
What is L(M)L(M)?
{wΣ:δ^(q0,w)F}\{w\in\Sigma^* : \hat\delta(q_0,w)\in F\} — the set of all strings it accepts.
What is a "regular language"?
A language recognized by some DFA.
In a state diagram, what does a double circle mean?
An accept (final) state, i.e. a member of FF.
In a state diagram, what marks the start state?
An arrow coming from nowhere into that state.
If a state diagram is missing an arrow for some symbol, what does a DFA require?
A hidden total δ\delta — really a transition to a dead/trap state (loops on itself, non-accepting).
Does a DFA accept ε\varepsilon iff what?
Iff q0Fq_0\in F (the start state is accepting).
Difference between δ\delta and δ^\hat\delta?
δ\delta reads one symbol; δ^\hat\delta reads a whole string by recursion.

Recall Feynman: explain a DFA to a 12-year-old

Imagine a board game with a few squares. You start on the START square. Someone reads you a string of letters one at a time. Each square has a rule: "if you hear an a, hop to that square; if you hear a b, hop to this square." You just keep hopping — you have NO notebook, NO memory except which square you're standing on. When the letters run out, look down: if you're on a glowing (double-circle) square, you shout "YES, this word is in my club!"; otherwise "NO." That's a DFA: a finite hopping game where the square you're on is your whole brain.

Concept Map

contains

contains

contains

contains

contains

maps Q x Sigma to Q

must be

missing arrow implies

extended to strings

ends in F means

recognizes

power same as

DFA 5-tuple

Q finite states

Sigma alphabet

delta transition fn

q0 start state

F accept states

total single-valued

dead trap state

delta-hat on Sigma*

accept yes/no

regular languages

regexes and tokenizers

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, DFA ek bahut simple "machine" hai jiske paas sirf finite memory hai — na koi notebook, na koi extra storage. Uske paas kuch states hote hain (circles), aur jis bhi state pe vo abhi khada hai, wahi uski poori memory hai. Input string ek-ek symbol karke aata hai, aur har symbol pe machine ek fixed rule (transition function δ\delta) follow karke agle state pe jump karta hai. "Deterministic" ka matlab: har (state, symbol) ke liye sirf ek hi next state — koi guessing nahi, koi choice nahi.

Formal definition yaad rakhne ke liye 5 cheezein chahiye, yaani 5-tuple (Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F): QQ = saare states, Σ\Sigma = alphabet (jo symbols read honge), δ\delta = transition rule Q×ΣQQ\times\Sigma\to Q, q0q_0 = start state, aur FF = accept (final) states. String complete padhne ke baad agar machine kisi accept state (FF ka member, diagram me double circle) pe khada hai, toh string accept, warna reject. Iska formal version δ^\hat\delta se aata hai: δ^(q,ε)=q\hat\delta(q,\varepsilon)=q aur δ^(q,xa)=δ(δ^(q,x),a)\hat\delta(q,xa)=\delta(\hat\delta(q,x),a).

State diagram bas isi tuple ki picture hai — circle = state, double circle = accept, bahar se aati arrow = start, aur labelled arrow = δ\delta ki ek line. Real life me ye important hai kyunki tokenizers, regex search, password/pattern checking — sab DFA jaisi cheez se chalti hain.

Ek common galti: agar diagram me kisi symbol ki arrow missing dikhe, mat socho "undefined hai". DFA me δ\delta total hona chahiye — woh missing arrow asal me ek hidden "dead/trap state" ki taraf jaati hai. Aur dusri galti: ε\varepsilon (empty string) ko bhulna mat — agar q0Fq_0\in F hai toh empty string bhi accept hoti hai. Bas itna pakka rakho, baaki sab same logic pe chalta hai.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections