...

/

Introduction to Longest Common Substring

Introduction to Longest Common Substring

Let's get introduced to the Longest Common Substring pattern.

Overview

In this pattern, we will be discussing 12 problems related to this pattern. The following diagram shows an overview of this pattern.

Problems explored in Longest Common Substring pattern

The Longest Common Substring (LCS) is defined as the longest substring that is common in the given two strings. In the longest common substring problems, the elements of a substring must be consecutive as in the original strings. A slight variation of LCS is the Longest Common Subsequence, in which the elements of the substrings are not necessarily required to occupy consecutive positions within the original strings. In either case, the indices of the common substring must be in strictly increasing order. A strictly increasing order means that the indices of the substring taken from the original string must be in ascending order.

A substring, X, is considered as the maximum common substring of strings, S1 and S2, if it exists in both S1 and S2 and no other common substring is greater in length than X.

If we take two strings, “BCDAACD” and “ACDBAC”, there could be many common subsequences of different lengths like “BC”, “CDAC”, “DAC”, “AAC”, “AC”, “CD” and so on, but the longest common subsequence is of length 4 which is “CDAC”.

Mathematically, it can be written as:

Given two strings XX and ...

Access this course and 1400+ top-rated courses and projects.