• String
  • Substring
  • Search

For each character of the alphabet, a bucket collects all the positions of that character in x. When a character occurs k times in the pattern, there are k corresponding positions in the bucket of the character. When the word is much shorter than the alphabet, many buckets are empty.

The preprocessing phase of the Skip Search algorithm consists in computing the buckets for all the characters of the alphabet: for c in Sigma  z[c] = {i :  0 leq i leq m-1 and x[i] = c} The space and time complexity of this preprocessing phase is O(m+sigma).

The main loop of the search phase consists in examining every m-th text character, y[j] (so there will be n / m main iterations). For y[j], it uses each position in the bucket z[y[j]] to obtain a possible starting position p of x in y. It performs a comparison of x with y beginning at position p, character by character, until there is a mismatch, or until all match.

The Skip Search algorithm has a quadratic worst case time complexity but the expected number of text character inspections is O(n).

Main features:

  • uses buckets of positions for each character of the alphabet;
  • preprocessing phase in O(m+sigma) time and space complexity;
  • searching phase in O(mn) time complexity;
  • O(n) expected text character comparisons.


Preprocessing phase

Skip search Z table
Z table used by Skip Search algorithm.

Searching phase

First attempt
 2     1 
 1   - 

Shift by: 8

Second attempt

Shift by: 8

Third attempt
 2      1

The Skip Search algorithm performs 14 character comparisons on the example.