4 ms·
I'm a little surprised to not be seeing some classical search algorithms. For online pattern searching, I'd want Boyer-Moore with the the Galil rule for guaran
by stochastic_monk 9y ago
I'm a little surprised to not be seeing some classical search algorithms.
For online pattern searching, I'd want Boyer-Moore with the the Galil rule for guaranteed linear search. [Due to an unfortunate accident in C++ history, Boost and C++17 skip the Galil rule, leading to O(n+m) runtime vs. O(nm).]
For offline, Burrows-Wheeler has performance linear with query string and independent of the length of the searched document.
- kbr 9y agoThis isn't an exact pattern searching library. Wade originally used Boyer-Moore, but has since switched to a trie [1] structure to search for _terms_ rather than the whole query. This allows for result documents that can contain some of the terms, all of the terms, or a prefix of a term. It's also pretty fast as it doesn't need to run a linear search through the documents. I'm not sure what you mean by "classical" search algorithms, but a trie based search is a pretty standard way of doing it. [1] https://en.wikipedia.org/wiki/Trie https://en.wikipedia.org/wiki/Trie
- stochastic_monk 9y agoI understand, thank you. (Though a lot of inexact pattern matching is done with using exact pattern matching of substrings with the pidgeonhole principle.) Tries led to suffix trees led to suffix arrays led to Burrows-Wheeler transform led to FM index, which is probably the best way to do an offline search. If you haven't looked at BWT indexing, it's worth at least checking out. It preserves the advantages you speak of with linear memory cost with the search space. It's a lot more hairy to implement, unfortunately.
- stochastic_monk 9y agoA nice summary can be found here: http://www.cs.jhu.edu/~langmea/resources/lecture_notes/bwt_and_fm_index.pdf http://www.cs.jhu.edu/~langmea/resources/lecture_notes/bwt_a....