The Galil-Giancarlo algorithm is a variant of the Colussi algorithm. The change intervenes in the searching phase. The method applies when x is not a power of a single character. Thus x cm with c in .
Let be the last index in the pattern such that for 0 i , x=x[i] and x x[+1]. Assume that during the previous attempt all the noholes have been matched and a suffix of the pattern has been matched meaning that after the corresponding shift a prefix of the pattern will still match a part of the text. Thus the window is positioned on the text factor y[j .. j+m-1] and the portion y[j .. last] matches x[0 .. last-j]. Then during the next attempt the algorithm will scanned the text character beginning with y[last+1] until either the end of the text is reached or a character x y[j+k] is found.
In this latter case two subcases can arise:
- x[+1] y[j+k] or too less x have been found (k ) then the window is shifted and positioned on the text factor y[k+1 .. k+m], the scanning of the text is resumed (as in the Colussi algorithm) with the first nohole and the memorized prefix of the pattern is the empty word.
- x[+1]=y[j+k] and enough of x has been found (k > ) then the window is shifted and positioned on the text factor y[k--1 .. k-+m-2], the scanning of the text is resumed (as in the Colussi algorithm) with the second nohole (x[+1] is the first one) and the memorized prefix of the pattern is x[0 .. +1].
The preprocessing phase is exactly the same as in the Colussi algorithm and can be done in O(m) space and time.
The searching phase can then be done in O(n) time complexity and furthermore at most n text character comparisons are performed during the searching phase.
- refinement of Colussi algorithm;
- preprocessing phase in O(m) time and space complexity;
- searching phase in O(n) time complexity;
- performs n text character comparisons in the worst case.