I need to search for a sub-string in a given string. C++ provides library function 'find' for this. What is the algorithm used by this library function? For purpose of competitive programming, should I use this function or use KMP search algorithm?
Asked
Active
Viewed 272 times
-3
-
KMP definitely, find is O(n*k) – Maras Jul 11 '18 at 17:06
1 Answers
2
With a quick search, I found this:
- KMP is
O(n + k)
- Find is
O(n * k)
So KMP is a faster search algorithm.

Remy Lebeau
- 555,201
- 31
- 458
- 770

Incisor
- 328
- 1
- 16