Add MaximumSubarrayAlgorithm#4158
Conversation
klevinazeraj
commented
Apr 19, 2023
- [x ] I have read CONTRIBUTING.md.
- [ x] This pull request is all my own work -- I have not plagiarized it.
- [x ] All filenames are in PascalCase.
- [x ] All functions and variable names follow Java naming conventions.
- [x ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
|
This algorithm is implemented here https://github.com/TheAlgorithms/Java/blob/1551b8f50ba485b5a7d34fe9ed1fbf650134fb9f/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java |
This algorithm falls under divide and conquer category, are you sure? |
|
Why is it divide and conquer? I'd say that it's dynamic programming because it just goes over elements 1 by 1 and doesn't explicitly divide input in parts. |
|
It cuts down the array in half's the same way merge sort does and then finds the maximum subarray for each of those subarrays and it returns the greatest one. Here is a great video to visualize the process. https://youtu.be/3GD-3UZGsVI |
|
I see, it differs from what've linked to |
| * @param high the upper index of the subarray to search | ||
| * @return an array containing the indices and sum of the maximum subarray within the given range | ||
| */ | ||
| public static int[] findMaximumSubarray(int[] A, int low, int high) { |
There was a problem hiding this comment.
Please add a public function int[] findMaximumSubarray(int[] array) that only accepts array and returns only starting and ending indexes of the maximum subarray. And make these functions private, as those are implementation and not contract. They can be tested through the public function.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Can I work on this issue? |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions! |