对于两个字符串搜索算法:KMP和后缀树,这是preferred在何种情况下?给出一些实际的例子。
For the two string searching algorithms: KMP and suffix tree, which is preferred in which cases? Give some practical examples.
推荐答案一个后缀树是更好,如果你必须回答很多,如查询是针present在草堆?。 KMP是更好,如果你只需要搜索一个字符串在另一个单独的字符串,而不必做了很多次了。
A suffix tree is better if you will have to answer a lot of queries such as "is the needle present in the haystack?". KMP is better if you only have to search for one string in another single string, and not have to do it a lot of times.
一个后缀树是一个更一般的数据结构,所以你可以做更多的事情吧。看看你可以用它做这里。 KMP是找到一个字符串是否在另一个字符串中的子串用。
A suffix tree is a much more general data structure, so you can do a lot more with it. See what you can do with it here. KMP is useful for finding if a string is a substring in another string.
您可能也想看看其他算法,如博耶 - 穆尔,拉宾,卡普甚至天真的算法,因为有一些情况(输入)在哪一个更好比其他
You might also want to check out other algorithms, such as Boyer-Moore, Rabin-Karp and even the naive algorithm, as there are situations (inputs) in which one is better than the others.
底线是:
更多推荐
字符串搜索算法
发布评论