I need to find the longest non-overlapping repeated substring in a String. I have the suffix tree and suffix array of the string available.
When overlapping is allowed,
Generate suffix array and sort in O(nlogn).ps: There is more effective algorithm like DC3 and Ukkonen algorithm. example:
String : ababc
Suffix array:
start-index of substring | substring
0 - ababc
2 - abc
1 - babc
3 - bc
4 - c
compare each two consecutive substring and get common prefix with following constraint:
Say i1 is index of substring "ababc": 0
say i2 is index of substring "abc":2
common prefix is "ab" , length of common prefix is len
abs(i1-i2) >len //avoid overlap
go through suffix array with solution, and you will get the result of "ababc", which is "ab";
The whole solution will run O(nlogn)
However, there will be a special case: "aaaaa" that this solution can't solve thoroughly.
Welcome to discuss and come up to a solution of O(nlogn) but not O(n^2)