Sub topic 13
Decision Problems for Regular Languages
Prerequisites and the working model
Assume you know basic set operations, functions, relations, finite automata, regular expressions, and elementary proof by contradiction. This chapter uses a DFA as the main representation.
A decision problem asks whether a property has a yes-or-no answer. For regular languages, the key idea is to replace an abstract language question with a finite graph search or a product construction.
Membership and emptiness
For a DFA \(M=(Q,\Sigma,\delta,q0,F)\), membership asks whether a given string \(w\) belongs to its language. Start at \(q0\), follow the transition for every symbol, and accept exactly when the final state is in \(F\). This takes time proportional to the length of \(w\).
Emptiness asks whether \(L(M)=\varnothing\). Search the DFA graph from \(q_0\). If no accepting state is reachable, the language is empty. Otherwise, the path to an accepting state gives a witness string.
Universality asks whether \(L(M)=\Sigma^*\). Complete the DFA with a sink state if necessary, then check whether every reachable state is accepting. Equivalently, test whether the complement DFA accepts any string.
from collections import deque
def accepts(dfa, word):
state, transitions, accepting = dfa
for symbol in word:
state = transitions[(state, symbol)]
return state in accepting
def is_empty(dfa, alphabet):
start, transitions, accepting = dfa
seen = {start}
queue = deque([start])
while queue:
state = queue.popleft()
if state in accepting:
return False
for symbol in alphabet:
nxt = transitions[(state, symbol)]
if nxt not in seen:
seen.add(nxt)
queue.append(nxt)
return True
transitions = {
(0, "a"): 1, (0, "b"): 0,
(1, "a"): 1, (1, "b"): 0,
}
dfa = (0, transitions, {1})
print(accepts(dfa, "baa")) # True
print(is_empty(dfa, {"a", "b"})) # FalseEquivalence and containment
Two regular languages \(L1\) and \(L2\) are equivalent when they contain exactly the same strings. The most useful reduction is
\[ L1=L2 \quad\text{if and only if}\quad (L1\setminus L2)\cup(L2\setminus L1)=\varnothing. \]
The language on the left is the symmetric difference. Build a product DFA whose states are pairs \((p,q)\), one state from each original DFA. From \((p,q)\), reading symbol \(a\) moves to
\[ (\delta1(p,a),\delta2(q,a)). \]
Mark a pair accepting when exactly one component is accepting. If no such pair is reachable, the languages are equivalent.
Containment uses the same method:
\[ L1\subseteq L2 \quad\text{if and only if}\quad L1\cap\overline{L2}=\varnothing. \]
For NFAs or regular expressions, first convert them to equivalent DFAs, or use the corresponding automata constructions directly.
A decision-problem checklist
| Property | DFA method |
|---|---|
| Membership | Simulate one input string |
| Emptiness | Search for reachable accepting state |
| Equivalence | Test product DFA for symmetric difference |
| Containment | Test \(L_1\cap\overline{L_2}\) for emptiness |
Common errors
- Checking only states reachable in one DFA when testing equivalence.
- Forgetting to complete a DFA before taking its complement.
- Treating an NFA state set as one DFA state without applying subset construction.
- Proving that two machines have different structures instead of proving that their languages differ.
- Confusing universality with non-emptiness. A language can contain many strings without containing every string.
Exercise
How can you decide whether two complete DFAs accept the same language?
Show answer
Construct their product DFA. Mark a pair accepting when exactly one component state is accepting. If no marked pair is reachable from the initial pair, the two DFAs are equivalent.