The running time of the algorithm is of the order of N cubed, where N is the length of the input string W. Incidentally, there is another algorithm due to J Early that also runs in time order n-cubed. 