First I know very little about algorithms, so bear with me.
As I understand it, the Boyer Moore algorithm is fastest with a long key. So what if I have a very shor key (example 10 chars), and alot of text to search (over 10,000 chars).
Would Boyer Moore be the best search algorithm for this scenario?
If not what would be?
According to String searching algorithm, “The Boyer–Moore string search algorithm has been the standard benchmark for the practical string search literature.” It’s not always the fastest, but in general it’s the way to go.
Knuth-Morris-Pratt and Boyer-Moore are very close in running time when you’re talking about a small text buffer like 10,000 characters. Even a naive string search will be blindingly fast on a 10K buffer when run on a modern computer. I suspect you’ll find that the difference between the KMP and Boyer-Moore two searching for a 10-character string in a 10,000 character buffer will be on the order of nanoseconds.
The best search algorithm in this scenario? That’s going to depend on how often you need to call it. If it’s something that gets called a few times a second (at most), I’d probably write a naive search and leave it at that. The difference between Boyer-Moore and naive search on that small buffer would be insignificant compared to the running time of your program, and your optimization effort would be better spent somewhere else. If I had to call it hundreds or thousands of times a second, I’d take the time to write an optimized Boyer-Moore search.