Longest Non-Overlapping Repeated Substring using Suffix Tree/Array (Algorithm Only)

后端 未结 8 2066
遇见更好的自我
遇见更好的自我 2021-02-13 16:30

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,

8条回答
  •  粉色の甜心
    2021-02-13 17:27

    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)

提交回复
热议问题