由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - About Longest repeated substring
相关主题
help on longest common substringTIJ上写错了?
问一个简单问题的算法 (转载)如何动态分配内存来存储输入的不定长的字符串,char not string类型的
这个有更好的算法吗?内存管理的问题
请教一个字符串比较排序的问题设计一个string class,是应该用linked list还是array?
[合集] 问2个微软电话面试题目C#方案里两个程序传递字符串问题
what is the most efficient way to trim a string in C++?多文本搜索多个字符串
C++ string类输入数据的问题std::string 是8 bit clean的吗?
whitespace 问题[合集] 问个面试题
相关话题的讨论汇总
话题: ana话题: repeated话题: longest话题: substring话题: about
进入Programming版参与讨论
1 (共1页)
c*********t
发帖数: 2921
1
Hi,
I have a question about Longest repeated substring.
Given a string "BANANA", is the longest repeated substring "ANA" or just "AN
" or "NA"?
According to the definition in Wikipedia. It seems that the longest repeated
string is "ANA".
http://en.wikipedia.org/wiki/Longest_repeated_substring_problem
http://en.wikipedia.org/wiki/Suffix_tree
I guess this is how it works for these two different answers.
For the answer ANA
BANANA
|||
|||
Here ANA is repeated twice. However these two ANA overlap
j*****h
发帖数: 62
2
Programming pearls里好像是提到过这个问题,没记错的化,它是用suffix array
来作的。算法很简单,假设string长度为n,以‘\0'结尾。开辟一个字符指针数组长度
为n,每个指针依次指向string的一个suffix。把该数组看成n个字符串的数组,排序。
再scan一遍,找相邻两个字符串最长的common prefix,即可。复杂度O(n^2lgn).
这种算法是允许overlap的,也就是说'ANA'是BANANA的最长重复子串。

AN
repeated

【在 c*********t 的大作中提到】
: Hi,
: I have a question about Longest repeated substring.
: Given a string "BANANA", is the longest repeated substring "ANA" or just "AN
: " or "NA"?
: According to the definition in Wikipedia. It seems that the longest repeated
: string is "ANA".
: http://en.wikipedia.org/wiki/Longest_repeated_substring_problem
: http://en.wikipedia.org/wiki/Suffix_tree
: I guess this is how it works for these two different answers.
: For the answer ANA

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] 问个面试题[合集] 问2个微软电话面试题目
VC++ 6.0 弱问,多谢解答what is the most efficient way to trim a string in C++?
Pattern matchingC++ string类输入数据的问题
[合集] c++的题whitespace 问题
help on longest common substringTIJ上写错了?
问一个简单问题的算法 (转载)如何动态分配内存来存储输入的不定长的字符串,char not string类型的
这个有更好的算法吗?内存管理的问题
请教一个字符串比较排序的问题设计一个string class,是应该用linked list还是array?
相关话题的讨论汇总
话题: ana话题: repeated话题: longest话题: substring话题: about