Lably
Skip to content

Longest common substring

Computer science problem

  • 3 min read
  • 3 chapters

Related on Lably

Through Computer science, String (computer science) and Big O notation

Unlike the longest common subsequence problem, which finds insertions or deletions within the common text, the longest common substring problem seeks a contiguous substring shared by both texts.

Examples

The picture shows two strings where the problem has multiple solutions. Although the substring occurrences always overlap, it is impossible to obtain a longer common substring by "uniting" them.

The strings "ABABC", "BABCA" and "ABCBA" have only one longest common substring, viz. "ABC" of length 3. Other common substrings are "A", "AB", "B", "BA", "BC" and "C".

ABABC ||| BABCA ||| ABCBA

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication