Skip to content

Add MaximumSubarrayAlgorithm#4158

Closed
klevinazeraj wants to merge 2 commits into
TheAlgorithms:masterfrom
klevinazeraj:master
Closed

Add MaximumSubarrayAlgorithm#4158
klevinazeraj wants to merge 2 commits into
TheAlgorithms:masterfrom
klevinazeraj:master

Conversation

@klevinazeraj
Copy link
Copy Markdown

  • [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.

@siriak
Copy link
Copy Markdown
Member

siriak commented Apr 20, 2023

@klevinazeraj
Copy link
Copy Markdown
Author

This algorithm is implemented here https://github.com/TheAlgorithms/Java/blob/1551b8f50ba485b5a7d34fe9ed1fbf650134fb9f/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java
Please make desired changes there

This algorithm falls under divide and conquer category, are you sure?

@siriak
Copy link
Copy Markdown
Member

siriak commented Apr 21, 2023

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.

@klevinazeraj
Copy link
Copy Markdown
Author

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

@siriak
Copy link
Copy Markdown
Member

siriak commented Apr 22, 2023

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label May 23, 2023
@siddhant2002
Copy link
Copy Markdown
Contributor

Can I work on this issue?

@github-actions github-actions Bot removed the stale label May 27, 2023
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Jul 11, 2023
@github-actions
Copy link
Copy Markdown

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!

@github-actions github-actions Bot closed this Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants