10

So I've been doing regular languages a while and still need a better understanding of why all finite languages A ⊆ Σ* are regular? Is there a formal proof of it or is it just because a DFA can represent any finite language since the states would be finite as well?

James Pekon
  • 141
  • 1
  • 1
  • 4

2 Answers2

16

The proof goes something like this:

  • If $A$ is a finite language, then it contains a finite number of strings $a_0, a_1, \cdots , a_n$.
  • The language $\{a_i\}$ consisting of a single literal string $a_i$ is regular.
  • The union of a finite number of regular languages is also regular.
  • Therefore, $A = \{a_0\} \cup \{a_1\} \cup \cdots \cup \{a_n\}$ is regular.
Draconis
  • 7,216
  • 1
  • 19
  • 28
4

There is also a direct proof. Let $P$ be the set of all prefixes of words in $A$. Since $A$ is finite, so is $P$. We construct a DFA whose states are $\{ q_p : p \in P \} \cup \{ q' \}$. The initial state is $q_\epsilon$. A state $q_p$ is final if and only if $p \in A$. When at state $q_p$ and reading $\sigma$, if $p\sigma \in P$ then we move to $q_{p\sigma}$, otherwise we move to $q'$. When at state $q'$, we always stay in $q'$.

What I described above is the minimal DFA. You can get a somewhat simpler DFA by taking an arbitrary superset of $P$, such as the set of all words of length at most $n$, where $n$ is the length of the longest word in $A$.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514