Jump to content

Longest repeated substring problem

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Micsthepick (talk | contribs) at 03:45, 27 May 2016 (Split the paragraph, added big-theta notation, edited last sentence.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
A suffix tree of the letters ATCGATCGA$

In computer science, the longest repeated substring problem is the problem of finding the longest substring of a string that occurs at least twice.

This problem can be solved in linear time and space [ Θ(n) ] by building a suffix tree for the string, and finding the deepest internal node in the tree. Depth is measured by the number of characters traversed from the root. The string spelled by the edges from the root to such a node is a longest repeated substring. The problem of finding the longest substring with at least occurrences can be solved by first preprocessing the tree to count the number of leaf descendants for each internal node, and then finding the deepest node with at least leaf descendants that have no children.

In the figure with the string "ATCGATCGA$", the longest substring that repeats at least twice is "ATCGA".

  • Allison, L. "Suffix Trees". Retrieved 2008-10-14.
  • C implementation of Longest Repeated Substring using Suffix Tree