Lably
Skip to content

Kleene's algorithm

  • 3 min read
  • 2 chapters

Explore on Lably

ToursExplore Lably’s 3D tours

Algorithm description

According to Gross and Yellen (2004), the algorithm can be traced back to Kleene (1956). A presentation of the algorithm in the case of deterministic finite automata (DFAs) is given in Hopcroft and Ullman (1979). The presentation of the algorithm for NFAs below follows Gross and Yellen (2004).

Given a nondeterministic finite automaton M = (Q, Σ, δ, q0, F), with Q = { q0,...,qn } its set of states, the algorithm computes

the sets Rk
ij of all strings that take M from state qi to qj without going through any state numbered higher than k.

Here, "going through a state" means entering and leaving it, so both i and j may be higher than k, but no intermediate state may. Each set Rk
ij is represented by a regular expression; the algorithm computes them step by step for k = -1, 0, ..., n. Since there is no state numbered higher than n, the regular expression Rn
0j represents the set of all strings that take M from its start state q0 to qj. If F = { q1,...,qf } is the set of accept states, the regular expression Rn
01 | ... | Rn
0f represents the language accepted by M.

The initial regular expressions, for k = -1, are computed as follows for i≠j:

R−1
ij = a1 | ... | am where qj ∈ δ(qi,a1), ..., qj ∈ δ(qi,am)

and as follows for i=j:

R−1
ii = a1 | ... | am | ε where qi ∈ δ(qi,a1), ..., qi ∈ δ(qi,am)

In other words, R−1
ij mentions all letters that label a transition from i to j, and we also include ε in the case where i=j.

After that, in each step the expressions Rk
ij are computed from the previous ones by

Rk
ij = Rk-1
ik (Rk-1
kk)* Rk-1
kj | Rk-1
ij

Another way to understand the operation of the algorithm is as an "elimination method", where the states from 0 to n are successively removed: when state k is removed, the regular expression Rk-1
ij, which describes the words that label a path from state i>k to state j>k, is rewritten into Rk
ij so as to take into account the possibility of going via the "eliminated" state k.

By induction on k, it can be shown that the length of each expression Rk
ij is at most ⁠1/3⁠(4k+1(6s+7) - 4) symbols, where s denotes the number of characters in Σ. Therefore, the length of the regular expression representing the language accepted by M is at most ⁠1/3⁠(4n+1(6s+7)f - f - 3) symbols, where f denotes the number of final states. This exponential blowup is inevitable, because there exist families of DFAs for which any equivalent regular expression must be of exponential size.

In practice, the size of the regular expression obtained by running the algorithm can be very different depending on the order in which the states are considered by the procedure, i.e., the order in which they are numbered from 0 to n.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Topics in mathematics