Is there any faster way to search for a string in a file?
Asked
Active
Viewed 1,901 times
3 Answers
5
Look at this site, where you can also see the matching time for each of the algorithms.

Aykut Çevik
- 2,060
- 3
- 20
- 27
2
The Turbo Boyer-Moore algorithm is faster, but requires more space. http://www-igm.univ-mlv.fr/~lecroq/string/node15.html

aaaa bbbb
- 3,003
- 2
- 23
- 23
2
If you know anything specific about the file, there could be faster algorithms.
For example, if the file contains many repeating characters/patterns and you need to do a large number of searches, you could try using Suffix Trees: http://marknelson.us/1996/08/01/suffix-trees/
Depending on your file and the quantity of searches you need on that one file, the answer for the fastest search algorithm may change.

Yuf
- 610
- 2
- 6
- 14