# Two Kadane Algorithms for the Maximum Sum Subarray Problem

## Abstract

**:**

## 1. History

## 2. Growing Champions

- (a)
- A maximal adjacent subsequence cannot have a starting sub-subsequence with a negative sum. Eliminating such a starting sub-subsequence and starting over must result in a larger sum for the subsequence, so the original subsequence cannot be optimal.
- (b)
- After eliminating starting sub-subsequences with negative sums, the ensuing sub-subsequence must start non-negatively, so including it in the subsequence must increase (zeros do not affect the sum) the resulting sum. Thus, an optimal subsequence must start immediately after the elimination of starting sub-subsequences with negative sums.

Algorithm 1 Linear algorithm based on Champ |

Algorithm 2 Algorithm 1 modified to report the start and end of the first interval whose sum is maximum |

## 3. The Linear Algorithm Bentley Gave Me Credit for

Algorithm 3 Same as Algorithm 4 in Bentley [5] |

Algorithm 4 Algorithm 3 modified to report the start and end of an optimal subsequence |

## 4. Comparing Algorithms 1 and 3

## 5. Discussion

## Funding

## Data Availability Statement

## Conflicts of Interest

## Appendix A. Proof of Proposition 4

**Proof.**

**Proof.**

## References

- von Neumann, J.; Morgenstern, O. Theory of Games and Economic Behavior; Princeton University Press: Princeton, NJ, USA, 1944. [Google Scholar]
- Savage, L. Foundations of Statistics; J. Wiley and Sons: New York, NY, USA, 1954. [Google Scholar]
- Dantzig, G. Linear Programming and Extensions; Princeton University Press: Princeton, NJ, USA, 1963. [Google Scholar]
- Klee, V.; Minty, G.J. How good is the simplex algorithm? In Inequalities III, Proceedings of the Third Symposium on Inequalities, Los Angeles, CA, USA, 1–9 September 1969; Dedicated to the Memory of Theodore S. Motzkin; Oved, S., Ed.; Academic Press: New York, NY, USA; London, UK, 1972; pp. 159–175. [Google Scholar]
- Bentley, J. Algorithm Design Techniques. Commun. ACM
**1984**, 27, 865–871. [Google Scholar] [CrossRef] - Maximum Sum Rectangle in a 2D Matrix. Available online: https://www.geeksforgeeks.org/maximum-sum-rectangle-in-a-2d-matrix-dp-27 (accessed on 2 November 2023).
- Maximum Sum Rectangle in a 2D Matrix—Kadane’s Algorithm Application (Dynamic Programming). Available online: https://www.youtube.com/watch?V=FgseNO-6Gk (accessed on 2 November 2023).
- Ray, T. Maximum Sum Rectangular Submatrix in Matrix Dynamic Programming/2D Kadane. Available online: https://www.youtube.com/watch?v=yCQN096CwWM (accessed on 2 November 2023).
- Saleh, S.; Abdellah, M.; Abdel Raouf, A.; Kadah, Y. High Performance CUDA-based Implementation for the 2D Version of the Maximum Subarray Problem (MSP). In Proceedings of the 2012 Cairo International Biomedical Engineering Conference, Giza, Egypt, 20–21 December 2012. [Google Scholar]
- Waddell, S.; Takaoka, T.; Read, T.; Candy, R. Maximum subarray algorithms for use in optical and radio astronomy. In Proceedings of the SPIE 8500 Image Reconstruction from Incomplete Data VII, San Diego, CA, USA, 12–16 August 2012. [Google Scholar] [CrossRef]
- Rakocevic, G.; Semenyuk, V.; Lee, W.; Spencer, J.; Browning, J.; Johnson, I.J.; Arsenijevic, V.; Nadj, J.; Ghose, K.; Suciu, M.C.; et al. Fast and accurate genomic analyses using genome graphs. Nat. Genet.
**2019**, 51, 354–362. [Google Scholar] [CrossRef] [PubMed] - Zhao, J.; Song, X.; Wang, K. IncScore: Alignment-free identification of long noncoding RNA from assembled novel transcripts. Sci. Rep.
**2016**, 6, 34838. [Google Scholar] [CrossRef] [PubMed] - Wu, J.; Lee, W.P.; Ward, A.; Walker, J.A.; Konkel, M.K.; Batzer, M.A.; Gabor, T. Tangram: A comprehensive toolbox for mobile element insertion detection. BMC Genom.
**2014**, 15, 795. [Google Scholar] [CrossRef] [PubMed] - Xiang, J.; Dong, Y.; Xue, X.; Xiang, H. Transactions on Biomedical Circuits and Systems; IEEE: New York, NY, USA, 2019; Volume 13, pp. 68–79. [Google Scholar]
- Aygun, R. Using Maximum Sum Subarrays for Approximate String Matching. Ann. Data Sci.
**2017**, 4, 503–531. [Google Scholar] [CrossRef] - Available online: https://leetcode.com/problems/maximum-subarray/ (accessed on 2 November 2023).
- Miriello, B. Kadane’s Algorithm: Gateway to Dynamic Programming. 2020. Available online: https://levelup.gitconnected.com/kadanes-algorithm-gateway-to-dynamic-programming-26e95ec13c7f (accessed on 2 November 2023).

Algorithm 1 | Algorithm 3 | |
---|---|---|

Time | 0 (n) | 0 (n) |

Space | 0 (1) | 0 (1) |

Correct? | Yes | Yes |

Modify to report start and end | Algorithm 2 | Algorithm 4 |

Negative input | Either empty set or | |

largest element | Empty set only |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2023 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Kadane, J.B.
Two Kadane Algorithms for the Maximum Sum Subarray Problem. *Algorithms* **2023**, *16*, 519.
https://doi.org/10.3390/a16110519

**AMA Style**

Kadane JB.
Two Kadane Algorithms for the Maximum Sum Subarray Problem. *Algorithms*. 2023; 16(11):519.
https://doi.org/10.3390/a16110519

**Chicago/Turabian Style**

Kadane, Joseph B.
2023. "Two Kadane Algorithms for the Maximum Sum Subarray Problem" *Algorithms* 16, no. 11: 519.
https://doi.org/10.3390/a16110519