string - Efficient Data Structure For Substring Search? -


assume have set of strings s , query string q. want know if member of s substring of q. (for purpose of question substring includes equality, e.g. "foo" substring of "foo".) example assume function want called anysubstring:

s = ["foo", "baz"] q = "foobar" assert anysubstring(s, q)  # "foo" substring of "foobar"  s = ["waldo", "baz"] assert not anysubstring(s, q) 

is there easy-to-implement algorithm time complexity sublinear in len(s)? it's ok if s has processed clever data structure first because querying each s lot of q strings, amortized cost of preprocessing might reasonable.

edit: clarify, don't care which member of s substring of q, whether @ least 1 is. in other words, only care boolean answer.

i think aho-corasick algorithm want. think there solution simple implement, it's karp-rabin algorithm.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -