Overview
Longest Common Substring uses a recurrence that extends only matching adjacent characters, resetting when characters differ.
Finds the longest contiguous block shared by two strings.
Compact metadata for implementation and discovery.
Longest Common Substring uses a recurrence that extends only matching adjacent characters, resetting when characters differ.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n m)
Average
O(n m)
Worst
O(n m)
Space
O(min(n, m))
dp[i][j] = text1[i] == text2[j] ? dp[i-1][j-1] + 1 : 0Extends a common substring only through matching adjacent characters.
Show matched positions, dynamic-programming cells, or candidate buckets.
Longest Common Substring should be used with the assumptions and tradeoffs of dynamic Programming in mind.
What each reference supports for this entry.
String algorithms reference covering Longest Common Substring recurrences, automata/indexing structures, or exact/approximate matching role.
Good next jumps from the relationship graph, ranked for useful discovery.
Pattern Matching · Extended
Suffix automatons can compute longest common substrings efficiently.
Compare with thisLongest common substring requires contiguous matches.
Suffix automatons can compute longest common substrings efficiently.