Add Longest Common Subsequence (LCS) dynamic programming algorithm [HACKTOBERFEST 2025]#158
Merged
siriak merged 4 commits intoTheAlgorithms:masterfrom Oct 7, 2025
Conversation
- Implement complete LCS solution with O(m*n) time complexity - Include space-optimized O(min(m,n)) version for large inputs - Add path reconstruction to return actual LCS string - Support for both string and array sequences - Multiple LCS finding for cases with multiple solutions - Create new Dynamic Programming category - Comprehensive examples including DNA analysis and file diff simulation
There was a problem hiding this comment.
Pull Request Overview
This PR implements the Longest Common Subsequence (LCS) dynamic programming algorithm with multiple variants and optimizations. The implementation includes both basic and advanced features for finding common subsequences between strings and arrays.
- Complete LCS implementation with O(m*n) time complexity and path reconstruction
- Space-optimized version using O(min(m,n)) space for memory efficiency
- Multiple LCS finder and array support for different data types
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dynamic_programming/longest_common_subsequence.r | Complete LCS algorithm implementation with multiple variants, optimizations, and comprehensive test cases |
| DIRECTORY.md | Added entry for the new dynamic programming section and LCS algorithm |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
siriak
requested changes
Oct 6, 2025
siriak
approved these changes
Oct 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Overview
This PR implements the Longest Common Subsequence (LCS) algorithm - a fundamental dynamic programming solution used in bioinformatics, version control, and text analysis.
✨ Features
🎯 Why This Matters
LCS algorithm is essential for:
📚 Implementation Details
🔧 Advanced Functions
lcs_string()- Complete solution with path reconstructionlcs_length_optimized()- Space-efficient O(min(m,n)) versionfind_all_lcs()- Finds all possible LCS solutionslcs_array()- Works with integer arrays, not just stringsprint_dp_table()- Educational DP table visualization🧬 Bioinformatics Application
DNA Sequence Analysis: