Python icon indicating copy to clipboard operation
Python copied to clipboard

added iterative solution for product sum problem

Open negi153 opened this issue 2 years ago • 4 comments

Describe your change:

This contribution includes an iterative approach to solve product sum problem. Recursion may run into Stack overflow if array has many nested arrays but iterative approach won't run into this problem.

  • [X] Add an algorithm?
  • [ ] Fix a bug or typo in an existing algorithm?
  • [ ] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • [ ] Documentation change?

Checklist:

  • [X] I have read CONTRIBUTING.md.
  • [X] This pull request is all my own work -- I have not plagiarized.
  • [X] I know that pull requests will not be merged if they fail the automated tests.
  • [X] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [X] All new Python files are placed inside an existing directory.
  • [X] All filenames are in all lowercase characters with no spaces or dashes.
  • [X] All functions and variable names follow Python naming conventions.
  • [X] All function parameters and return values are annotated with Python type hints.
  • [X] All functions have doctests that pass the automated testing.
  • [ ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

negi153 avatar Nov 01 '23 04:11 negi153

@cclauss Could you or someone please review it .

negi153 avatar Nov 06 '23 12:11 negi153

Please add a timeit benchmark so we can understand the performance differences between the two implementations.

  • https://github.com/search?q=repo%3ATheAlgorithms%2FPython%20timeit&type=code

cclauss avatar Nov 06 '23 13:11 cclauss

Hi @cclauss , as you suggested i have added benchmarking. Kindly take a look at this. There is small difference in execution time but it overcomes the stack overflow problem which happen in recursion approach.

negi153 avatar Nov 08 '23 06:11 negi153

Hi @cclauss any update on this ?

negi153 avatar Nov 14 '23 07:11 negi153