3 ms·
You're asking a question that the experts have also asked, so it's definitely a good question. The algorithm you're talking about is also called the naive algor
by mtdewcmu 12y ago
You're asking a question that the experts have also asked, so it's definitely a good question. The algorithm you're talking about is also called the naive algorithm. It's much faster in practice than you might expect given its simplicity and poor worst-case performance. That's because pathological behavior doesn't actually happen that often, and most of the time it is quite efficient.
I'm not sure whether it or KMP would be faster. But it doesn't matter much in the real world, because even better algorithms, like Boyer-Moore and its derivatives are faster still, and they are used instead.