Dynamic ProgrammingIntermediate

Longest Common Subsequence (LCS)

Finds the longest subsequence present in two sequences in the same order. Uses dynamic programming to build a solution table. Applications include DNA sequence alignment, file difference tools (diff), and plagiarism detection.

#dynamic-programming#strings#sequences#optimization

Complexity Analysis

Time (Average)

O(m × n)

Expected case performance

Space

O(m × n)

Memory requirements

Time (Best)

O(m × n)

Best case performance

Time (Worst)

O(m × n)

Worst case performance

📚 CLRS Reference

Introduction to AlgorithmsChapter 15Section 15.4

LCS finds the longest subsequence common to both strings

Step: 1 / 0
500ms
SlowFast
Keyboard Shortcuts
Space Play/Pause StepR Reset1-4 Speed

Real-time Statistics

Algorithm Performance Metrics

Progress0%
Comparisons
0
Swaps
0
Array Accesses
0
Steps
1/ 0

Algorithm Visualization

Step 1 of 0

Initialize array to begin

Default
Comparing
Swapped
Sorted

Code Execution

Currently executing
Previously executed

Implementation

Longest Common Subsequence (LCS) - Algorithm Vision