SemSure

Formal Language & Automata · Unit 1

NFA to DFA: from zero to exam ready

You do not need to know anything about automata yet. By the end you will solve the 8-mark university question on your own.

8 marks · NFA → DFA appeared in 7 of the last 9 papers

01 · Read any automaton diagram: states, inputs, arrows, start and accepting states

What is a finite automaton?

State
One square of the board: a situation the machine can be in. Drawn as a circle. Example: ("so far I have seen an even number of 1s").
Alphabet
The symbols that can appear on the cards, written . Example: .
String
The whole sequence of cards, read left to right. Example: . The empty string, with no symbols, is written .
Transition
The rule "from this state, on this symbol, go to that state". Drawn as a labelled arrow. Example: An arrow from to labelled 1.
Start state
Where you stand before the first card. Marked by an arrow that comes from nowhere.
Accepting state
A gold square. If the string ends here, the machine accepts the string. Drawn as a double circle.
0101EO
A machine that accepts strings with an even number of 1s. E = even so far, O = odd so far.
  • Circle = a state.
  • Arrow from nowhere = the start state (E).
  • Double circle = accepting state (E).
  • Arrow labelled 0 = “on reading 0, move here”.

Read the picture like a map. Reading a 0 never changes the count of 1s, so both states loop to themselves on 0. Reading a 1 flips the count, so 1 sends to and back to . The start state is (zero 1s is an even number), and is also the accepting state.

Only 0 and 1 are read. Move through the string with the buttons; the lit states are where the machine can be.

0101EO
After 4 symbols: O
1011
AfterSymbol readState
start–E
1 symbol1O
2 symbols0O
3 symbols1E
4 symbols1O

Ends in O, which is not accepting: REJECTED.

Checkpoint
The machine reads the string . Where does it finish, and is the string accepted?

02 · Understand how one input can lead to several states at once

NFA vs DFA: the intuition

The parity machine is a DFA (deterministic finite automaton): from every state, on every symbol, there is exactly one arrow. You always know where you are.

An NFA (non-deterministic finite automaton) relaxes that rule. From a state, a symbol may have two or more arrows, one arrow, or none at all.

0,100,11011PQRS
The NFA from the May 2026 paper. Start at P (lit). Q and S are accepting.

Look at . On 0 there are two arrows, to and to . So after reading 0, a token sits on and another on : the NFA could be in either. Now look at : there is no arrow labelled 0 leaving it. A token on that reads 0 vanishes.

State01
→ P{Q, S}{Q}
* Q{R}{Q, R}
R{S}{P}
* S∅{P}

The table says the same thing as the picture. Row , column 0 holds the set because there are two arrows. The entry (the empty set) means "no arrow". → marks the start state and * marks accepting states.

Only 0 and 1 are read. Move through the string with the buttons; the lit states are where the machine can be.

0,100,11011PQRS
After 1 symbol: {Q, S}
0
AfterSymbol readPossible NFA states
start–{P}
1 symbol0{Q, S}

Ends in {Q, S}. It contains Q and S, an accepting state, so at least one path accepts: ACCEPTED.

Checkpoint
The NFA could currently be in or , and it reads 1. Which states are possible next?
Formal definition · DFA and NFA

Both are 5-tuples : a finite set of states , an alphabet , a transition function , a start state and accepting states . They differ only in . In a DFA, returns one state. In an NFA, returns a set of states (possibly empty).

Read it as " takes a state and a symbol, and gives back a set of states."

all pairs (state, symbol), such as .
the set of all subsets of . With 4 states there are subsets, from to .
on reading 0 in , the NFA can go to or to .

03 · Learn why a group of NFA states becomes one DFA state

What is subset construction?

A real machine cannot be in " or " at the same time. The trick that removes the guessing is simple: treat the whole set of possible states as one new state. The DFA state means "the NFA could be in or in ". From , every symbol leads to exactly one next set, so the new machine is deterministic.

The whole method in five rules

  1. Start. The DFA starts in the set containing only the NFA's start state: .
  2. Move a set. For a set and a symbol , look up where every state of goes on and put all the answers together (their union).
  3. Discover. If that set has not been seen before, it is a new DFA state. Write it on the list (the queue) of sets still to process.
  4. Repeat. Take the next set from the queue and do the same for every symbol. Stop when the queue is empty.
  5. Mark accepting. A DFA state is accepting when its set contains at least one accepting NFA state.

Read it as "To move the set on symbol : for every state in , find , then join all of those sets into one."

the DFA's transition from the set on symbol (the textbook also writes ).
"the union over every in ": collect everything, keep each state once.
one row lookup in the NFA table.
Checkpoint
Our NFA could currently be in or . What happens when we read 0? From , 0 leads to . From , 0 leads to . So which states are possible after reading 0?

Why a set containing $Q$ or $S$ must be accepting. The DFA state means the NFA could be in or in after reading the string so far. The NFA accepts when at least one of its possible states is accepting. is accepting, so in that situation the NFA accepts, and the DFA must accept too. The same reasoning applies to every set: it is accepting exactly when it contains or . is accepting (it contains ). , and are not.

Why the empty set is a trap state. If every token vanishes, the set of possible states is . No arrows leave an empty set, so on every symbol it goes back to , and since it contains no accepting state it never accepts. In the DFA it is a dead (trap) state with a self-loop on 0 and 1. It must be drawn, because a DFA needs a move for every state and symbol.

Why we do not list all 16 subsets. Only the sets you can actually reach from matter. For this NFA that is 10 of the 16; the other 6 (such as ) never occur while reading any string, so they would be unreachable states that change nothing.

Checkpoint
Which of these DFA states is accepting? (Accepting NFA states: and .)

04 · Build the complete transition table, one union at a time

Convert the NFA step by step

Now apply the five rules to the May 2026 NFA. The walkthrough below does one calculation per step: it lights up the states in the current set, then the arrows they take on the symbol, then forms the union, and finally checks whether the result is new. The table at the bottom fills in as you go. Use Next and Previous, or Auto-play to watch.

Step 1 of 20
0,100,11011PQRS
Active states {P}

Compute T({P}, 0)

The DFA state [P] means “the NFA could be in any of {P}”. We read 0 from every one of them.

    Discovered: [P]
    Queue (still to process): empty
    DFA stateon 0on 1
    → {P}

    Now do it yourself. The same walkthrough asks you to build every union before it shows it. If you pick a wrong set, it tells you exactly which state is missing or extra and why.

    Step 1 of 20Practice: you compute each union
    0,100,11011PQRS
    Active states {P}

    Compute T({P}, 0)

    The DFA state [P] means “the NFA could be in any of {P}”. We read 0 from every one of them.

      Discovered: [P]
      Queue (still to process): empty
      DFA stateon 0on 1
      → {P}
      Common mistakes

      ✗ Taking only the first state's row for a set, e.g. writing .

      Why it happens: It is easy to stop after the first lookup.

      ✓ Instead: Look up every state in the set and take the union: .

      ✗ Leaving the entries blank or dropping the trap state.

      Why it happens: An empty cell looks like "nothing to do".

      ✓ Instead: Write as a DFA state with both arrows looping back to itself. A DFA must have a move for every state and symbol.

      ✗ Treating and as different states.

      Why it happens: Writing states in different orders.

      ✓ Instead: A set has no order. Always write the states in the same fixed order (P, Q, R, S), so repeated sets are easy to spot.

      ✗ Marking only and as accepting.

      Why it happens: Confusing "is accepting" with "equals an accepting state".

      ✓ Instead: Every set that contains or is accepting: , , , , as well.

      05 · Turn table rows into states and arrows, then check the result

      Draw the final DFA

      DFA state01
      → [P][QS][Q]
      * [QS][R][PQR]
      * [Q][R][QR]
      [R][S][P]
      * [PQR][QRS][PQR]
      * [QR][RS][PQR]
      * [S]∅[P]
      * [QRS][RS][PQR]
      * [RS][S][P]
      ∅∅∅

      → marks the start state, * marks accepting states. [QS] is short for the subset {Q, S}.

      1. One circle per row. Label each with its subset, e.g. . There are as many circles as rows in the table.
      2. Start arrow into , the row marked →.
      3. Double circles for every row marked * (the sets containing or ).
      4. Two arrows out of every circle, one labelled 0 and one labelled 1, copied from the row. If both go to the same place, draw one arrow labelled "0,1".
      5. The trap state $\varnothing$ gets a self-loop labelled 0,1.
      0101010101010101010,1PQSQRPQRQRSQRSRS∅
      The equivalent DFA (labels are the NFA states in each subset). Scroll sideways on a phone.

      Check your DFA. The DFA must accept exactly the strings the NFA accepts. Run a few strings through both. Each row of this table is computed by actually running both machines, so you can compare it with your own working:

      StringNFA ends inDFA ends inVerdict
      0{Q, S}[QS]accept
      00{R}[R]reject
      01{P, Q, R}[PQR]accept
      000{S}[S]accept
      0000∅∅reject
      101{P}[P]reject
      0110{Q, R, S}[QRS]accept

      Only 0 and 1 are read. Move through the string with the buttons; the lit states are where the machine can be.

      0,100,11011PQRS
      After 4 symbols: {Q, R, S}
      0110
      AfterSymbol readPossible NFA statesDFA state
      start–{P}[P]
      1 symbol0{Q, S}[QS]
      2 symbols1{P, Q, R}[PQR]
      3 symbols1{P, Q, R}[PQR]
      4 symbols0{Q, R, S}[QRS]

      Ends in {Q, R, S}. It contains Q and S, an accepting state, so at least one path accepts: ACCEPTED. The DFA ends in [QRS] and gives the same verdict.

      06 · Write the full 8-mark answer the way the examiner wants it

      Solve the university question

      University question · 8 marks · May 2026 Q21b; Nov 2023 Q21a

      Construct a DFA equivalent to the NFA where is given by the table below.

      Write this in the answer booklet

      Model answer

      Given NFA

      with:

      State01
      → P{Q, S}{Q}
      * Q{R}{Q, R}
      R{S}{P}
      * S∅{P}

      Method (subset construction)

      The DFA's states are sets of NFA states. Its start state is . For a set and symbol , . Only sets reachable from are constructed. A set is accepting if it contains or .

      Sample calculations (show two or three in the exam)

      and . . . .

      DFA transition table

      DFA state01
      → [P][QS][Q]
      * [QS][R][PQR]
      * [Q][R][QR]
      [R][S][P]
      * [PQR][QRS][PQR]
      * [QR][RS][PQR]
      * [S]∅[P]
      * [QRS][RS][PQR]
      * [RS][S][P]
      ∅∅∅

      → marks the start state, * marks accepting states. [QS] is short for the subset {Q, S}.

      The DFA

      is every subset that contains or , the accepting states of the NFA.

      Transition diagram

      0101010101010101010,1PQSQRPQRQRSQRSRS∅
      The equivalent DFA (labels are the NFA states in each subset). Scroll sideways on a phone.

      Verification

      StringNFA ends inDFA ends inVerdict
      01{P, Q, R}[PQR]accept
      00{R}[R]reject
      000{S}[S]accept
      0000∅∅reject
      Where the marks are. Spend most of your effort on the complete transition table with included and the accepting rows marked. Then add the diagram, the statement of , and , and two or three sample union calculations to show the method. In Nov 2023 the same machine used states (finals ); rename , , , and the answer is identical.

      07 · Convert new NFAs on your own, with hints only when you ask

      Practice and test yourself

      Practice · Second-last symbol is 1

      This NFA accepts the strings over whose second-last symbol is 1. Convert it to a DFA. Build every union yourself in the walkthrough.

      State01
      → q0{q0}{q0, q1}
      q1{q2}{q2}
      * q2∅∅
      Step 1 of 8Practice: you compute each union
      0,110,1q0q1q2
      Active states {q0}

      Compute T({q0}, 0)

      The DFA state [q0] means “the NFA could be in any of {q0}”. We read 0 from every one of them.

        Discovered: [q0]
        Queue (still to process): empty
        DFA stateon 0on 1
        → {q0}
        Practice · Unit 1 practice NFA (p, q, r, s)

        Convert this NFA (start , accepting ) to a DFA. Remember: every set that contains is accepting.

        State01
        → p{p, q}{p}
        q{r}{r}
        r{s}∅
        * s{s}{s}
        Step 1 of 16Practice: you compute each union
        0,100,100,1pqrs
        Active states {p}

        Compute T({p}, 0)

        The DFA state [p] means “the NFA could be in any of {p}”. We read 0 from every one of them.

          Discovered: [p]
          Queue (still to process): empty
          DFA stateon 0on 1
          → {p}
          Revise in one minute
          • A DFA has exactly one move per state and symbol. An NFA may have several or none.
          • Subset construction makes each set of possible NFA states one DFA state.
          • Start at . For each discovered set and each symbol, take the union of the rows: .
          • A new set joins the queue. Stop when the queue is empty.
          • A set is accepting if it contains any accepting NFA state.
          • is the trap state with a self-loop on every symbol.

          Exam checklist

          • Wrote the given NFA (5-tuple and table).
          • Stated the subset construction rule.
          • Showed two or three union calculations.
          • Complete DFA table, included, → on the start, * on accepting rows.
          • Listed , and .
          • Drew the diagram: double circles, start arrow, trap loop.
          • Checked one accepted and one rejected string.