UNIHIVE

Study Hub UNIPORT CSC 396

CSC 396 · Automata theory, Computability and Formal Languages

Deterministic finite automata

What a DFA is, its formal definition, transition tables and diagrams, and designing DFAs for given languages.

Our notes

2 min read

The idea

A finite automaton reads a string one symbol at a time, moving between a finite number of states. If it ends in an accepting state, the string is in the language. It has no memory beyond its current state.

Formal definition

A DFA is M = (Q, Σ, δ, q₀, F):

  • Q: finite set of states,
  • Σ: input alphabet,
  • δ: transition function Q × Σ → Q (exactly one next state for each state and symbol),
  • q₀: start state,
  • F: set of accepting (final) states.

Example 1: even number of 1s

States E (even so far, start, accepting) and O (odd).

State01
→ *EEO
OOE

Trace 10110: E →1 O →0 O →1 E →1 O →0 O. Ends in O: rejected (three 1s). Trace 1001: E → O → O → O → E: accepted.

Example 2: binary strings ending in 01

States: q0 (start), q1 (last symbol 0), q2 (last two symbols 01, accepting).

State01
→ q0q1q0
q1q1q2
*q2q1q0

Trace 1101: q0 →1 q0 →1 q0 →0 q1 →1 q2: accepted. Trace 0110: ... ends in q1: rejected.

Example 3: binary numbers divisible by 3

Keep the remainder mod 3 as the state. Reading bit b changes remainder r to (2r + b) mod 3.

State01
→ *r0r0r1
r1r2r0
r2r1r2

Trace 110 (= 6): r0 → r1 → r0 → r0: accepted ✓. Trace 111 (= 7): r0 → r1 → r0 → r1: rejected ✓ (7 mod 3 = 1).

Uses

Lexical analysers in compilers, text search, vending machines, traffic lights, protocol checking, input validation (is this a valid phone number?).

Design tips

  1. Decide what the machine must remember about the input so far; each possibility is a state.
  2. Fill in every transition (a missing one goes to a dead state that never accepts).
  3. Test with strings that should be accepted and rejected, including ε.

Exams usually ask

  • Give the formal definition of a DFA.
  • Design a DFA for a described language, with diagram and table.
  • Trace strings through a DFA.

Common mistake

Leaving out transitions. In a DFA every state needs exactly one transition for every symbol; add a dead state for the missing ones.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 396 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.