Kleene's Algorithm

Get Kleene's Algorithm essential facts below. View Videos or join the Kleene's Algorithm discussion. Add Kleene's Algorithm to your PopFlock.com topic list for future reference or share this resource on social media.
## Algorithm description

## Example

## See also

## References

This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

Kleene's Algorithm

In theoretical computer science, in particular in formal language theory, **Kleene's algorithm** transforms a given nondeterministic finite automaton (NFA) into a regular expression.
Together with other conversion algorithms, it establishes the equivalence of several description formats for regular languages. Alternative presentations of the same method include the "elimination method" attributed to Brzozowski and McCluskey, the algorithm of McNaughton and Yamada,^{[1]} and the use of Arden's lemma.

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

Given a nondeterministic finite automaton *M* = (*Q*, ?, ?, *q*_{0}, *F*), with *Q* = { *q*_{0},...,*q*_{n} } its set of states, the algorithm computes

- the sets
*R*^{k}_{ij}of all strings that take*M*from state*q*_{i}to*q*_{j}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 *R*^{k}_{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 *R*^{n}_{0j} represents the set of all strings that take *M* from its start state *q*_{0} to *q*_{j}. If *F* = { *q*_{1},...,*q*_{f} } is the set of accept states, the regular expression *R*^{n}_{01} | ... | *R*^{n}_{0f} represents the language accepted by *M*.

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

*R*^{-1}_{ij}=*a*_{1}| ... |*a*_{m}where*q*_{j}? ?(*q*_{i},*a*_{1}), ...,*q*_{j}? ?(*q*_{i},*a*_{m})

and as follows for *i*=*j*:

*R*^{-1}_{ii}=*a*_{1}| ... |*a*_{m}| ? where*q*_{i}? ?(*q*_{i},*a*_{1}), ...,*q*_{i}? ?(*q*_{i},*a*_{m})

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 *R*^{k}_{ij} are computed from the previous ones by

*R*^{k}_{ij}=*R*^{k-1}_{ik}(*R*^{k-1}_{kk})^{*}*R*^{k-1}_{kj}|*R*^{k-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 *R*^{k-1}_{ij}, which describes the words that label a path from state *i*>*k* to state *j*>*k*, is rewritten into *R*^{k}_{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^{[5]} of each expression *R*^{k}_{ij} is at most (4^{k+1}(6*s*+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 (4^{n+1}(6*s*+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.^{[6]}

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*.

The automaton shown in the picture can be described as *M* = (*Q*, ?, ?, *q*_{0}, *F*) with

- the set of states
*Q*= {*q*_{0},*q*_{1},*q*_{2}}, - the input alphabet ? = {
*a*,*b*}, - the transition function ? with ?(
*q*_{0},*a*)=*q*_{0}, ?(*q*_{0},*b*)=*q*_{1}, ?(*q*_{1},*a*)=*q*_{2}, ?(*q*_{1},*b*)=*q*_{1}, ?(*q*_{2},*a*)=*q*_{1}, and ?(*q*_{2},*b*)=*q*_{1}, - the start state
*q*_{0}, and - set of accept states
*F*= {*q*_{1}}.

Kleene's algorithm computes the initial regular expressions as

*R*^{-1}_{00}= *a*| ?*R*^{-1}_{01}= *b**R*^{-1}_{02}= ? *R*^{-1}_{10}= ? *R*^{-1}_{11}= *b*| ?*R*^{-1}_{12}= *a**R*^{-1}_{20}= ? *R*^{-1}_{21}= *a*|*b**R*^{-1}_{22}= ?

After that, the *R*^{k}_{ij} are computed from the *R*^{k-1}_{ij} step by step for *k* = 0, 1, 2.
Kleene algebra equalities are used to simplify the regular expressions as much as possible.

- Step 0

*R*^{0}_{00}= *R*^{-1}_{00}(*R*^{-1}_{00})^{*}*R*^{-1}_{00}|*R*^{-1}_{00}= ( *a*| ?)( *a*| ?)^{*}( *a*| ?)| *a*| ?= *a*^{*}*R*^{0}_{01}= *R*^{-1}_{00}(*R*^{-1}_{00})^{*}*R*^{-1}_{01}|*R*^{-1}_{01}= ( *a*| ?)( *a*| ?)^{*}*b*| *b*= *a*^{*}*b**R*^{0}_{02}= *R*^{-1}_{00}(*R*^{-1}_{00})^{*}*R*^{-1}_{02}|*R*^{-1}_{02}= ( *a*| ?)( *a*| ?)^{*}? | ? = ? *R*^{0}_{10}= *R*^{-1}_{10}(*R*^{-1}_{00})^{*}*R*^{-1}_{00}|*R*^{-1}_{10}= ? ( *a*| ?)^{*}( *a*| ?)| ? = ? *R*^{0}_{11}= *R*^{-1}_{10}(*R*^{-1}_{00})^{*}*R*^{-1}_{01}|*R*^{-1}_{11}= ? ( *a*| ?)^{*}*b*| *b*| ?= *b*| ?*R*^{0}_{12}= *R*^{-1}_{10}(*R*^{-1}_{00})^{*}*R*^{-1}_{02}|*R*^{-1}_{12}= ? ( *a*| ?)^{*}? | *a*= *a**R*^{0}_{20}= *R*^{-1}_{20}(*R*^{-1}_{00})^{*}*R*^{-1}_{00}|*R*^{-1}_{20}= ? ( *a*| ?)^{*}( *a*| ?)| ? = ? *R*^{0}_{21}= *R*^{-1}_{20}(*R*^{-1}_{00})^{*}*R*^{-1}_{01}|*R*^{-1}_{21}= ? ( *a*| ?)^{*}*b*| *a*|*b*= *a*|*b**R*^{0}_{22}= *R*^{-1}_{20}(*R*^{-1}_{00})^{*}*R*^{-1}_{02}|*R*^{-1}_{22}= ? ( *a*| ?)^{*}? | ? = ?

- Step 1

*R*^{1}_{00}= *R*^{0}_{01}(*R*^{0}_{11})^{*}*R*^{0}_{10}|*R*^{0}_{00}= *a*^{*}*b*( *b*| ?)^{*}? | *a*^{*}= *a*^{*}*R*^{1}_{01}= *R*^{0}_{01}(*R*^{0}_{11})^{*}*R*^{0}_{11}|*R*^{0}_{01}= *a*^{*}*b*( *b*| ?)^{*}( *b*| ?)| *a*^{*}*b*= *a*^{*}*b*^{*}*b**R*^{1}_{02}= *R*^{0}_{01}(*R*^{0}_{11})^{*}*R*^{0}_{12}|*R*^{0}_{02}= *a*^{*}*b*( *b*| ?)^{*}*a*| ? = *a*^{*}*b*^{*}*ba**R*^{1}_{10}= *R*^{0}_{11}(*R*^{0}_{11})^{*}*R*^{0}_{10}|*R*^{0}_{10}= ( *b*| ?)( *b*| ?)^{*}? | ? = ? *R*^{1}_{11}= *R*^{0}_{11}(*R*^{0}_{11})^{*}*R*^{0}_{11}|*R*^{0}_{11}= ( *b*| ?)( *b*| ?)^{*}( *b*| ?)| *b*| ?= *b*^{*}*R*^{1}_{12}= *R*^{0}_{11}(*R*^{0}_{11})^{*}*R*^{0}_{12}|*R*^{0}_{12}= ( *b*| ?)( *b*| ?)^{*}*a*| *a*= *b*^{*}*a**R*^{1}_{20}= *R*^{0}_{21}(*R*^{0}_{11})^{*}*R*^{0}_{10}|*R*^{0}_{20}= ( *a*|*b*)( *b*| ?)^{*}? | ? = ? *R*^{1}_{21}= *R*^{0}_{21}(*R*^{0}_{11})^{*}*R*^{0}_{11}|*R*^{0}_{21}= ( *a*|*b*)( *b*| ?)^{*}( *b*| ?)| *a*|*b*= ( *a*|*b*)*b*^{*}*R*^{1}_{22}= *R*^{0}_{21}(*R*^{0}_{11})^{*}*R*^{0}_{12}|*R*^{0}_{22}= ( *a*|*b*)( *b*| ?)^{*}*a*| ? = ( *a*|*b*)*b*^{*}*a*| ?

- Step 2

*R*^{2}_{00}= *R*^{1}_{02}(*R*^{1}_{22})^{*}*R*^{1}_{20}|*R*^{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*^{1}_{21}|*R*^{1}_{21}= (( *a*|*b*)*b*^{*}*a*| ?)(( *a*|*b*)*b*^{*}*a*| ?)^{*}( *a*|*b*)*b*^{*}| ( *a*|*b*)*b*^{*}= ( *a*|*b*) (*a*(*a*|*b*) |*b*)^{*}*R*^{2}_{22}= *R*^{1}_{22}(*R*^{1}_{22})^{*}*R*^{1}_{22}|*R*^{1}_{22}= (( *a*|*b*)*b*^{*}*a*| ?)(( *a*|*b*)*b*^{*}*a*| ?)^{*}(( *a*|*b*)*b*^{*}*a*| ?)| ( *a*|*b*)*b*^{*}*a*| ?= (( *a*|*b*)*b*^{*}*a*)^{*}

Since *q*_{0} is the start state and *q*_{1} is the only accept state, the regular expression *R*^{2}_{01} denotes the set of all strings accepted by the automaton.

- Floyd-Warshall algorithm — an algorithm on weighted graphs that can be implemented by Kleene's algorithm using a particular Kleene algebra
- Star height problem — what is the minimum stars' nesting depth of all regular expressions corresponding to a given DFA?
- Generalized star height problem — if a complement operator is allowed additionally in regular expressions, can the stars' nesting depth of Kleene's algorithm's output be limited to a fixed bound?
- Thompson's construction algorithm — transforms a regular expression to a finite automaton

**^**McNaughton, R.; Yamada, H. (March 1960). "Regular Expressions and State Graphs for Automata".*IRE Transactions on Electronic Computers*.**EC-9**(1): 39-47. doi:10.1109/TEC.1960.5221603. ISSN 0367-9950.- ^
^{a}^{b}Jonathan L. Gross and Jay Yellen, ed. (2004).*Handbook of Graph Theory*. Discrete Mathematics and it Applications. CRC Press. ISBN 1-58488-090-2. Here: sect.2.1, remark R13 on p.65 **^**Kleene, Stephen C. (1956). "Representation of Events in Nerve Nets and Finite Automate" (PDF).*Automata Studies, Annals of Math. Studies*. Princeton Univ. Press.**34**. Here: sect.9, p.37-40**^**John E. Hopcroft, Jeffrey D. Ullman (1979).*Introduction to Automata Theory, Languages, and Computation*. Addison-Wesley. ISBN 0-201-02988-X. Here: Section 3.2.1 pages 91-96**^**More precisely, the number of regular-expression symbols, "*a*_{i}", "?", "|", "^{*}", "·"; not counting parentheses.**^**Gruber, Hermann; Holzer, Markus (2008). Aceto, Luca; Damgård, Ivan; Goldberg, Leslie Ann; Halldórsson, Magnús M.; Ingólfsdóttir, Anna; Walukiewicz, Igor (eds.). "Finite Automata, Digraph Connectivity, and Regular Expression Size".*Automata, Languages and Programming*. Lecture Notes in Computer Science. Springer Berlin Heidelberg.**5126**: 39-50. doi:10.1007/978-3-540-70583-3_4. ISBN 9783540705833.. Theorem 16.

This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

Popular Products

Music Scenes

Popular Artists