CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.1.4 · Item 18 of 91

Product construction and complement

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. Minimal DFA states for strings containing ab?
    Stuck? Peek at 1.1.3 DFA design patterns
    Language (|w| = k pattern)Minimal states
    starts with wk + 2
    contains w / ends with wk + 1
    |x| ≡ r mod nn
    |x| = k, |x| ≤ kk + 2
    |x| ≥ kk + 1
    #a mod m and/or #b mod nm·n (typical)
    binary value ≡ 0 mod k, k oddk
    binary ÷ 2ʲj + 1
    k-th symbol from start fixedk + 2

    Divisibility update: r ← (base·r + digit) mod k.

    Read lesson 1.1.3

  2. Write A − B using ∩ and complement.
    Stuck? Peek at 0.2.1 Sets
    • x ∈ A (element) vs X ⊆ A (subset). ∅ ⊆ every set. A = B ⇔ A ⊆ B and B ⊆ A.
    • A ∪ B, A ∩ B, A − B = A ∩ B̅, A̅ = U − A. De Morgan: (A∪B)̅ = A̅∩B̅, (A∩B)̅ = A̅∪B̅.
    • |A ∪ B| = |A| + |B| − |A ∩ B|. |A × B| = |A|·|B|. |P(A)| = 2^|A|.
    • |∅| = 0, |{∅}| = 1, P(∅) = {∅}.

    Read lesson 0.2.1

  3. What is L(M) when no accepting state is reachable?
    Stuck? Peek at 1.1.2 Extended transition function and regular languages
    • δ̂(q, ε) = q; δ̂(q, wa) = δ(δ̂(q, w), a); δ̂(q, xy) = δ̂(δ̂(q, x), y).
    • L(M) = { w : δ̂(q₀, w) ∈ F }. Regular ⇔ accepted by some DFA. All finite languages are regular.
    • From the graph: empty ⇔ no reachable final; Σ* ⇔ all reachable states final; infinite ⇔ cycle on a path start→final.
    • Prove correctness with state meanings + induction on |w|.

    Read lesson 1.1.2

The Hook

An airport scanner checks a bag for two things at once: “no liquids over 100 ml” and “no sharp objects”. It doesn’t scan twice — it runs both checks in parallel as the bag passes. A DFA can do the same: run two DFAs side by side on one pass, remembering a pair of states. This proves that combinations of regular languages are regular, and it’s how GATE expects you to count states for combined conditions.

Predict First

DFA A has 3 states, DFA B has 4 states. A DFA that runs both at once would need at most how many states?

Core Concept

Prediction check

At most 3 × 4 = 12: one state per pair (state of A, state of B). Some pairs may be unreachable or merge after minimization, so 12 is an upper bound.

B1B2B3B4
A1(A1,B1)(A1,B2)(A1,B3)(A1,B4)
A2(A2,B1)(A2,B2)(A2,B3)(A2,B4)
A3(A3,B1)(A3,B2)(A3,B3)(A3,B4)
Product states = all pairs: 3 × 4 = 12 at most.

The product construction

Given complete DFAs M₁ = (Q₁, Σ, δ₁, s₁, F₁) and M₂ = (Q₂, Σ, δ₂, s₂, F₂), the product DFA has states Q₁ × Q₂, start (s₁, s₂), and
δ((p, q), a) = (δ₁(p, a), δ₂(q, a)).

After reading w, the product is in (δ̂₁(s₁, w), δ̂₂(s₂, w)) — it knows exactly where both machines are. Only the choice of accepting pairs changes:

  • Intersection L₁ ∩ L₂: F = F₁ × F₂ (both accept).
  • Union L₁ ∪ L₂: F = (F₁ × Q₂) ∪ (Q₁ × F₂) (either accepts).
  • Difference L₁ − L₂: F = F₁ × (Q₂ − F₂).
  • Symmetric difference: exactly one accepts.

Conclusion: regular languages are closed under union, intersection and difference — combining regular languages this way always gives a regular language.

pairab∩∪L₁ − L₂
→ EPOPEQ✓✓
EQOPEQ✓✓
OPEPOQ
OQEPOQ✓
Same four states, three different languages — only the accepting column changes.

Build only what you can reach

In practice, start from (s₁, s₂) and add pairs as transitions reach them (like BFS, Lesson 0.2.5). Unreachable pairs never matter.

Build only reachable pairs, breadth first.
Build only reachable pairs, breadth first.

Complement of a DFA

For a complete DFA M, swap accepting and non-accepting states: M̅ = (Q, Σ, δ, q₀, Q − F). Then L(M̅) = Σ* − L(M).

It works because a DFA run always ends in exactly one state, and that state is accepting in exactly one of M, M̅. So regular languages are closed under complement, and the number of states doesn’t change.

The trap: the DFA must be complete. If the dead state was left out of the drawing, strings that “fall off” the diagram are rejected by both M and the swapped machine — wrong. Add the dead state first; after swapping, it becomes an accepting sink.
steps illustration
Complement = swap accepting states in a complete DFA.

Using complement to save work

“Strings that do not contain aba”: build contains-aba (4 states), swap F. Same 4 states. Complementing never changes the minimal state count.

contains aba
4 states
does not contain aba
the same 4 states, F swapped
Complementing never changes the minimal state count.

Putting it together

  • Run two DFAs in parallel on pairs of states; only the accepting set decides ∩, ∪ or −.
  • At most m × n states; build reachable pairs only.
  • Complement = complete the DFA, then swap F. Regular languages are closed under ∪, ∩, −, complement.

Visual

Product of “#a even” (E/O) with “ends with b” (P = last symbol not b or nothing read, Q = last symbol b). Intersection accepts only EQ.

Product: (#a even) ∩ (ends with b)

States: EP, EQ, OP, OQ

Transitions: EP>OP: a; EP>EQ: b; EQ>OP: a; EQ>EQ: b; OP>EP: a; OP>OQ: b; OQ>EP: a; OQ>OQ: b

          a      b          union F      = {EP, EQ, OQ}   (E accepts or Q accepts)
→ EP      OP     EQ         intersection = {EQ}
* EQ      OP     EQ         difference L₁−L₂ = {EP}   (even a's, not ending in b)
  OP      EP     OQ
  OQ      EP     OQ
trace "abab": EP ─a→ OP ─b→ OQ ─a→ EP ─b→ EQ   ACCEPT (2 a's, ends b)
trace "ab"  : EP ─a→ OP ─b→ OQ                 REJECT (odd a's)

Worked Examples

Easy

In the product above, which states are accepting for L₁ ∪ L₂ (“even a’s OR ends with b”)?

Show the full solution

Pairs where E holds or Q holds: EP, EQ, OQ. Only OP (odd a’s, not ending in b) rejects. Trace “a”: EP→OP reject ✓; “ab”: →OQ accept ✓.

Medium

Complement the starts-with-a DFA (1.1.1). What language results, and why must D be kept?

Show the full solution

Swap: q0 and D become accepting, q1 non-accepting. New language: strings that do not start with a = {ε} ∪ strings starting with b. If D had been omitted, “ba” would have nowhere to go and be rejected by both machines — but “ba” does not start with a, so the complement must accept it. D is what catches it.

GATE-level

M₁ (3 states) accepts strings with #a ≡ 0 (mod 3). M₂ (2 states) accepts strings ending in b. Upper bound and actual minimal states for L₁ − L₂?

Show the full solution

Upper bound 3 × 2 = 6. All 6 pairs are reachable (counts and last symbol vary independently) and distinguishable (a-count mod 3 matters; whether the last symbol is b matters for acceptance now). So the minimal DFA has 6 states.

GATE Traps

  • Complement by swapping F only works on a complete DFA — add the dead state first.
  • Swapping F in an NFA (next chapter) does not give the complement.
  • m × n is an upper bound; the minimal DFA can be smaller when pairs merge or are unreachable.
  • Union accepting set is not F₁ × F₂ — that is intersection.

Memory Hook

Product = two runners on the same track holding hands; you only decide at the finish line whether you needed one or both to win.

Connect the Dots

Phase 1, Chapter 1 complete: DFAs, their languages, design patterns, combining and complementing. But designing some DFAs is painful (try “third symbol from the end is 1”). Next chapter introduces a machine allowed to guess — and shows it is no more powerful, just far more convenient.

Self-Test

  1. NAT

    Product construction of a 4-state and a 5-state DFA has at most how many states?

    Write your answer before opening the key.

  2. MCQ

    In the product DFA, for L₁ − L₂ the accepting set is:

    1. F₁ × F₂
    2. F₁ × (Q₂ − F₂)
    3. (Q₁ − F₁) × F₂
    4. (F₁ × Q₂) ∪ (Q₁ × F₂)
  3. MSQ

    Which are true?

    1. Regular languages are closed under complement
    2. Swapping F in any DFA drawing (dead state omitted) gives the complement
    3. Complementing a DFA does not change its number of states
    4. Regular languages are closed under intersection
  4. NAT

    Minimal DFA states for strings over {a,b} that do NOT contain aa?

    Write your answer before opening the key.

  5. MCQ

    L₁ = strings of even length, L₂ = strings of odd length over {a,b}. Product DFA for L₁ ∩ L₂ — its language is:

    1. Σ*
    2. ∅
    3. {ε}
    4. even-length strings

Rule Card

  • Product: states Q₁×Q₂, δ((p,q),a) = (δ₁(p,a), δ₂(q,a)), start (s₁,s₂).
  • ∩: F₁×F₂. ∪: F₁×Q₂ ∪ Q₁×F₂. −: F₁×(Q₂−F₂). ≤ |Q₁|·|Q₂| states.
  • Complement: complete the DFA (add dead state), swap F ↔ Q−F; same state count.
  • Regular languages closed under ∪, ∩, −, complement.

Concept Ledger

  • product construction
  • pair state (p, q)
  • closure (an operation keeps the family)
  • closed under union, intersection, difference, complement
  • complement DFA (swap F)
  • complete DFA

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. 3.
  2. A ∩ B̅.
  3. ∅.

Self-test answers

  1. 20 — 4 × 5.
  2. B — Accepted by M₁, rejected by M₂.
    • A: Intersection.
    • C: That is L₂ − L₁.
    • D: Union.
  3. ACD — Complement and product constructions.
    • B: The DFA must be complete first.
  4. 3 — Contains aa has 3 states (k+1); complement keeps 3.
  5. B — No string has both even and odd length, so the accepting pair (even-accept, odd-accept) is never reached.
    • A: That would be the union.
    • C: ε has even length but not odd.
    • D: That is L₁.

Flashcards

  1. Product DFA accepting set for L₁ ∪ L₂?
    Reveal answer(F₁ × Q₂) ∪ (Q₁ × F₂)
  2. Product DFA accepting set for L₁ ∩ L₂?
    Reveal answerF₁ × F₂
  3. How do you complement a DFA?
    Reveal answerMake it complete (add dead state), then swap accepting and non-accepting states.
  4. Does complementing change the minimal state count?
    Reveal answerNo.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.