字符串搜索算法

编程入门 行业动态 更新时间:2024-10-19 04:29:55
本文介绍了字符串搜索算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于两个字符串搜索算法: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.

底线是:

  • 如果你有很多像我上面提到的查询,这是值得建立一个后缀树,然后回答每个查询速度更快。
  • 如果你需要比那些类型的查询做多,后缀树也值得建设。
  • 如果你只在乎偶尔找到一个字符串是否是另一个字符串的子串,然后用KMP。
  • 更多推荐

    字符串搜索算法

    本文发布于:2023-11-29 16:23:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1646932.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:字符串   算法

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!