Glushkov's construction algorithm
In computer science theory – particularly formal language theory – Glushkov's construction algorithm, invented by Victor Mikhailovich Glushkov, transforms a given regular expression into an equivalent nondeterministic finite automaton. Thus, it forms a bridge between regular expressions and nondeterministic finite automata: two abstract representations of the same class of formal languages.
A regular expression may be used to conveniently describe an advanced search pattern in a "find and replace"–like operation of a text processing utility. Glushkov's algorithm can be used to transform it into an NFA, which furthermore is small by nature, as the number of its states equals the number of symbols of the regular expression, plus one.
Subsequently, the NFA can be made deterministic by the powerset construction and then be minimized to get an optimal automaton corresponding to the given regular expression. The latter format is best suited for execution on a computer.
From another, more theoretical point of view, Glushkov's algorithm is a part of the proof that NFA and regular expressions both accept exactly the same languages; that is, the regular languages. The converse of Glushkov's algorithm is Kleene's algorithm, which transforms a finite automaton into a regular expression. The automaton obtained by Glushkov's construction is the same as the one obtained by Thompson's construction algorithm, once its ε-transitions are removed.
Glushkov's construction algorithm is also called The algorithm of Berry-Sethi, named after Gérard Berry and Ravi Sethi who worked on this construction.
Construction
Given a regular expression, the Glushkov Construction Algorithm creates a non-deterministic automaton that accepts the language accepted by. The construction uses four steps:Step 1
Linearisation of the expression. Each letter of the alphabet appearing in the expression is renamed, so that each letter occurs at most once in the new expression. Glushkov's construction essentially relies on the fact that represents a local language. Let be the old alphabet and let be the new one.Step 2a
Computation of the sets,, and. The first,, is the set of letters which occurs as first letter of a word of. The second,, is the set of letters that can end a word of. The last one,, is the set of letter pairs that can occur in words of, i.e. it is the set of factors of length two of the words of. Those sets are mathematically defined byThey are computed by induction over the structure of the expression, as explained below.
Step 2b
Computation of the set which contains the empty word if this word belongs to, and is the empty set otherwise. Formally, this is, where denotes the empty word.
Step 3
Computation of automaton recognizing the local language, as defined by,,, and. By definition, the local language defined by the sets,, and is the set of words which begin with a letter of, end by a letter of, and whose factors of length 2 belong to, optionally also including the empty word; that is, it is the language:Strictly speaking, it is the computation of the automaton for the local language denoted by this linearised expression that is Glushkov's construction.
Step 4
Remove the linearisation, replacing each indexed letter by the original letter of.Example
Consider the regular expressionComputation of the set of letters
The computation of the sets,,, and is done inductively over the regular expression. One must give the values for, the letters, and the results of the operations.The most costly operations are the products of sets for the computation of.