Skip to content
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

Adds new dynamic programming algorithm #2275

Open
wants to merge 5 commits into
base: master
from

Conversation

@kishan151999
Copy link

kishan151999 commented Aug 3, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
@cclauss
Copy link
Member

cclauss commented Aug 3, 2020

What is the use case for this algorithm? Where would we want to use it and why?

kishan151999 and others added 2 commits Aug 3, 2020
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
@TravisBuddy
Copy link

TravisBuddy commented Aug 3, 2020

Hey @kishan151999,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: b70aa2d0-d57c-11ea-8ca9-c37e1b84d109
@kishan151999
Copy link
Author

kishan151999 commented Aug 3, 2020

What is the use case for this algorithm? Where would we want to use it and why?
The uses are mostly to do with biology and more specifically DNA. They are used for DNA marking and permitting cutting. They can also be used to change a 1 dimensional DNA chain into a 2 or 3 dimensional structure. It can also be used to compress DNA sequences to save space.

--https://pubmed.ncbi.nlm.nih.gov/11700586/

--https://stackoverflow.com/questions/23861436/real-life-situations-using-palindrome-algorithm#:~:text=Palindromes%20are%20used%20in%20DNA,2%20or%203%20dimensional%20structure.&text=Palindromes%20are%20strings%20that%20read,plan%2C%20a%20canal%2C%20Panama!

@kishan151999
Copy link
Author

kishan151999 commented Aug 3, 2020

I have fixed all the issues and committed the changes. Thank you for letting me know.

"""

# creating an array to store the values generated
dp_table = [[1 for i in range(length)] for i in range(length)]

This comment has been minimized.

@cclauss

cclauss Aug 3, 2020

Member

Can we come up with a more self-documenting name than dp_table?

This comment has been minimized.

@kishan151999

kishan151999 Aug 3, 2020

Author

Would array be fine? If not what would you suggest?

This comment has been minimized.

@cclauss

cclauss Aug 3, 2020

Member

What would we call the value that is in each cell of this table? Are the weights or probabilities or angstroms or what?

"""


def longest_palindromic_subsequence(s: str, length: int) -> int:

This comment has been minimized.

@cclauss

cclauss Aug 3, 2020

Member
Suggested change
def longest_palindromic_subsequence(s: str, length: int) -> int:
def longest_palindromic_subsequence(s: str, length: int) -> str:

We should return the sequence, not the length of the sequence. The function is not named length_of_the_longest_palindromic_subsequence() so I would not expect an int result.

The caller can always call len(result) if they want the length.

>>> longest_palindromic_subsequence("ABACCG",6)
3
>>> longest_palindromic_subsequence("55055901565109",14)
9

This comment has been minimized.

@cclauss

cclauss Aug 3, 2020

Member

Please provide a negative test case that contains no palendrome. Also, a test case for the empty string.

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.