Yahoo Interview Question
Software Engineer / Developersyeah suffix tree would do the job..
create a suffix tree of the string of length N.then for each of M small strings of length L ,do the search in this tree and if the small string gets exhausted while reaching the leaf of suffix tree,then it means that the small string is present in the larger string..
alternatively,bulid generalized suffix tree of the big string of length N and all M small strings of length L.maintain a bit vector b[1...M] at each internal node of suffixtree.now go to each internal node if the subtree at the node contains part of the small string Mi,and bigstring then set b[i]=1;now in more traversal caliculate b[i] in that path if b[i]=M there is occurence of the small string.do this for all values of i
suffix tree
- Anonymous September 13, 2010