Overview
Longest Common Subsequence uses dynamic programming to compare prefixes and keep the best match length when characters either match or are skipped.
Finds the longest sequence that appears in two inputs without requiring contiguous positions.
Compact metadata for implementation and discovery.
Longest Common Subsequence uses dynamic programming to compare prefixes and keep the best match length when characters either match or are skipped.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n m)
Average
O(n m)
Worst
O(n m)
Space
O(n m)
dp[i][j] = dp[i-1][j-1] + 1 if a[i] == b[j], else max(dp[i-1][j], dp[i][j-1])Extends a match or skips one item from either sequence.
Show a matrix where matching characters extend diagonal paths.
A subsequence may skip characters; it is not the same as a substring.
What each reference supports for this entry.
Textbook support for Longest Common Subsequence invariants, recurrences, relaxation rules, or asymptotic analysis.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Both compare shared sequence structure, but substring requires contiguity.
Both use dynamic programming on sequence pairs.