feat: Add Edit Distance algorithm in Java #353
Merged
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.
Closes: #352
This pull request introduces a comprehensive Java implementation for the Edit Distance problem. This solution uses a bottom-up Dynamic Programming approach to find the minimum number of operations (insert, delete, or substitute) required to convert one string into another.
Summary of Changes
Added EditDistance.java (code): A new, thoroughly commented Java file located in Java/dynamic_programming/.
Implemented 2D Dynamic Programming: The solution builds a 2D DP table (dp[i][j]) that stores the minimum edit distance between the first i characters of word1 and the first j characters of word2.
Clear State Transitions: The logic for filling the DP table is clearly explained with comments, covering the base cases and the recursive relationship for matching and non-matching characters.
Included Demonstration: A main method is provided with multiple test cases to demonstrate the function's usage and verify its correctness.
Key Features
Introduces a Foundational DP Pattern: Adds the 2D DP on Strings pattern to the repository, a versatile technique applicable to many other problems.
High-Value Learning Problem: Edit Distance is a classic algorithm with wide-ranging applications in fields like spell checking and bioinformatics, making it an invaluable addition for learners.
Optimal and Well-Explained: The implementation runs in O(m⋅n) time and space. The code is structured for readability to ensure the DP logic is easy to follow.
Hope you liked my work As soon as my this PR is merged I'll make a new PR for some imp inerveiw question in cpp
do consider this one underhacktoberfest accepted
Thank you !!