LCS contraction addition in dynamic programming #81
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.
The contract has two functions:
The lcs function takes two strings and the lengths of the strings as input and returns the length of the LCS of the strings. The view keyword specifies that this function does not modify the state of the contract, so it does not need to be executed on the blockchain.
The max function is a helper function that takes two unsigned integers and returns the maximum of the two. The private keyword specifies that this function can only be called from within the contract.
The lcs function first checks if the result for the input strings is already stored in the cache mapping. If it is, the function returns the cached result. If the result is not in the cache, the function calculates the result using the standard recursive definition of the LCS problem and stores the result in the cache before returning it.