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 177 times
-4
-
KMP definitely, find is O(n*k) – Maras Jul 11 '18 at 17:06
1 Answers
1
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
- 505,946
- 29
- 409
- 696
Incisor
- 168
- 15