Imagine you are searching a dictionary for a word you can almost remember — say algorithm — but you might have typed algorythm or algoritm. Exact search fails. You need approximate matching: find every occurrence of the pattern within k edits (substitutions, insertions, deletions) of some substring of the text.
The Bitap algorithm (also called Shift-Or or Shift-And) cracks this with a beautiful trick: it encodes the entire pattern into one bitmask per character of the alphabet, then tracks all possible match positions simultaneously by shifting and OR-ing integers. Each character in the text costs exactly one bitwise shift, one OR and one AND — and modern CPUs do those in a single clock cycle.
The algorithm was invented by Udi Manber and Ricardo Baeza-Yates and published in 1992. It remains one of the fastest practical solutions for short-to-medium patterns, and is the engine inside grep -F, several spell-checkers and bioinformatics read-mappers. Its status: a solved algorithm with proven optimal worst-case complexity for its class.
Comments
Loading comments...