Skip to content

Add dp algorithms #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hamadasyr
Copy link

This module implements two classic Dynamic Programming strategies to solve the Longest Common Subsequence (LCS) problem:

Top-Down (Memoization):
Uses recursion with caching to avoid redundant subproblem computations. The recursive function stores results in a dictionary to ensure efficiency.

Bottom-Up (Tabulation):
Builds a 2D table iteratively, where each cell stores the LCS length for prefixes of the two input strings.

Additionally, the module provides a function to reconstruct the actual LCS string by backtracking through the DP table.

Each function is modular, readable, and thoroughly commented, demonstrating best practices in applying DP for string problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant