0

I am looking for naming/literature/implementations for a variation on the longest repeated substring problem. In the cited problem you find the longest (consecutive) substring with at least 2 (non-overlapping) repetitions:

max len(s) | rep(s) > 1

In my problem, I am looking for a substring with length greater than 1, that is repeated at least 2 times, and has the greatest (length times repetitions), thus "heftiest" (but surely there is a better name):

max len(s)*rep(s) | rep(s) > 1, len(s) > 1

o17t H1H' S'k
  • 2,541
  • 5
  • 31
  • 52

1 Answers1

1

This can also be done with a suffix tree. Annotate each node in the suffix tree with the number of leaves in its subtree. That takes time O(n) since the tree has n nodes. Now, run a DFS over the tree, along the lines of the classical longest repeated substring algorithm, keeping track of the length of the string represented by each node. As you do, compute the product of that length with the number of leaves in the subtree. That will give you the product of the number of occurrences of the substring and the length of the substring. Finally, return the max out of everything you find.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065