Skip to content

Conversation

maxwell-aladago
Copy link
Contributor

No description provided.

1. A naive recursive implementation which has an exponential runtime
2. Two dynamic programming implementations which have quadratic runtime
def rod_cutting(prices: List[int],length: int) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A List[int] is more strict than a list of anything.

Copy link
Contributor Author

@maxwell-aladago maxwell-aladago Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a list[int] is too restrictive since the prices can be floats as well.
You can also have mixed prices like [1, 1.2, 3].

If values which do not work well with addition are provided, then a ValueError will be thrown. That's something a user should handle, I think.

Edit: Also, the return type can be float or int depending on the prices.

@cclauss

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a list[int] is too restrictive since the prices can be floats as well.
You can also have mixed prices like [1, 1.2, 3].

If values which do not work well with addition are provided, then a ValueError will be thrown. That's something a user should handle, I think.

Edit: Also, the return type can be float or int depending on the prices.

@cclauss

@cclauss, do you insist that I enforced the values of the prices to be integers?

Copy link
Member

@cclauss cclauss Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I am fine with supporting both int and float

@cclauss cclauss merged commit 2dfe01e into TheAlgorithms:master Sep 5, 2019
neelu065 added a commit to neelu065/Python that referenced this pull request May 23, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* changing typo

* fully refactored the rod-cutting module

* more documentations

* rewording
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.

2 participants