<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
the	O
Boyer	B-Algorithm
–	I-Algorithm
Moore	I-Algorithm
–	I-Algorithm
Horspool	I-Algorithm
algorithm	I-Algorithm
or	O
Horspool	O
's	O
algorithm	O
is	O
an	O
algorithm	O
for	O
finding	O
substrings	O
in	O
strings	O
.	O
</s>
<s>
It	O
is	O
a	O
simplification	O
of	O
the	O
Boyer	B-Algorithm
–	I-Algorithm
Moore	I-Algorithm
string-search	I-Algorithm
algorithm	I-Algorithm
which	O
is	O
related	O
to	O
the	O
Knuth	O
–	O
Morris	O
–	O
Pratt	O
algorithm	O
.	O
</s>
<s>
The	O
algorithm	O
trades	O
space	O
for	O
time	O
in	O
order	O
to	O
obtain	O
an	O
average-case	B-General_Concept
complexity	O
of	O
O(n )	O
on	O
random	O
text	O
,	O
although	O
it	O
has	O
O(nm )	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
,	O
where	O
the	O
length	O
of	O
the	O
pattern	O
is	O
m	O
and	O
the	O
length	O
of	O
the	O
search	B-Algorithm
string	I-Algorithm
is	O
n	O
.	O
</s>
<s>
Like	O
Boyer	O
–	O
Moore	O
,	O
Boyer	B-Algorithm
–	I-Algorithm
Moore	I-Algorithm
–	I-Algorithm
Horspool	I-Algorithm
preprocesses	O
the	O
pattern	O
to	O
produce	O
a	O
table	O
containing	O
,	O
for	O
each	O
symbol	O
in	O
the	O
alphabet	O
,	O
the	O
number	O
of	O
characters	O
that	O
can	O
safely	O
be	O
skipped	O
.	O
</s>
<s>
The	O
best	B-General_Concept
case	I-General_Concept
is	O
the	O
same	O
as	O
for	O
the	O
Boyer	B-Algorithm
–	I-Algorithm
Moore	I-Algorithm
string-search	I-Algorithm
algorithm	I-Algorithm
in	O
big	O
O	O
notation	O
,	O
although	O
the	O
constant	O
overhead	O
of	O
initialization	O
and	O
for	O
each	O
loop	O
is	O
less	O
.	O
</s>
<s>
The	O
worst	B-General_Concept
case	I-General_Concept
behavior	O
happens	O
when	O
the	O
bad	O
character	O
skip	O
is	O
consistently	O
low	O
(	O
with	O
the	O
lower	O
limit	O
of	O
1	O
byte	O
movement	O
)	O
and	O
a	O
large	O
portion	O
of	O
the	O
needle	O
matches	O
the	O
haystack	O
.	O
</s>
<s>
The	O
worst	B-General_Concept
case	I-General_Concept
is	O
significantly	O
higher	O
than	O
for	O
the	O
Boyer	B-Algorithm
–	I-Algorithm
Moore	I-Algorithm
string-search	I-Algorithm
algorithm	I-Algorithm
,	O
although	O
obviously	O
this	O
is	O
hard	O
to	O
achieve	O
in	O
normal	O
use	O
cases	O
.	O
</s>
<s>
It	O
is	O
also	O
worth	O
noting	O
that	O
this	O
worst	B-General_Concept
case	I-General_Concept
is	O
also	O
the	O
worst	B-General_Concept
case	I-General_Concept
for	O
the	O
naive	O
(	O
but	O
usual	O
)	O
memcmp( )	O
algorithm	O
,	O
although	O
the	O
implementation	O
of	O
that	O
tends	O
to	O
be	O
significantly	O
optimized	O
(	O
and	O
is	O
more	O
cache	O
friendly	O
)	O
.	O
</s>
<s>
A	O
tuned	O
version	O
of	O
the	O
BMH	B-Algorithm
algorithm	I-Algorithm
is	O
the	O
Raita	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Also	O
see	O
String-searching	B-Algorithm
algorithm	I-Algorithm
which	O
has	O
detailed	O
analysis	O
of	O
other	O
string	B-Algorithm
searching	I-Algorithm
algorithms	I-Algorithm
.	O
</s>
