【问题标题】:Can you find all substrings of a string in faster than O(N^2) time if your constrained about what sub strings your looking for?如果您受限于要查找的子字符串,您能否在比 O(N^2) 时间更快的时间内找到字符串的所有子字符串?
【发布时间】:2022-01-25 02:05:08
【问题描述】:

根据这个答案 (Find all possible substring in fastest way)。查找字符串的所有可能子字符串的最快方法是O(N^2)。但是,如果假设我有一个单词列表,并且我不想查看某个字符串 x 是否具有该单词列表中的子字符串,这仍然是正确的。例如,创建一个单词列表的 trie,让我可以最佳地忽略某些子字符串。从而使运行时间更好?

【问题讨论】:

  • 检查一个字符串(单词)是否是一个较大字符串的子字符串是线性的。检查 K 个单词仍然是线性的。

标签: algorithm recursion substring big-o trie


【解决方案1】:

是的,这就是string searching algorithms 的用途。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-05
    • 2020-07-19
    • 1970-01-01
    • 2017-05-15
    • 2013-07-01
    • 2016-12-12
    • 2011-10-02
    • 2014-12-07
    相关资源
    最近更新 更多