AI engineering glossary · Data structures algorithms
What is kadane's algorithm?
Kadane's algorithm (also called maximum subarray): A one-pass algorithm that finds the contiguous stretch of a numeric array with the largest sum by tracking the best sum ending at each position and the best seen overall. It runs in O(n) time and O(1) space.
Kadane's algorithm: an example
For [-2, 1, -3, 4, -1, 2, 1, -5, 4] the best stretch is 4, -1, 2, 1 with sum 6.
Related terms
More Data structures algorithms terms
- Knapsack problem
- Knuth-Morris-Pratt algorithm
- Kruskal's algorithm
- Linear search
- Linked list
- Load factor
- Longest common subsequence
- Longest increasing subsequence
Where you learn it
Kadane's algorithm is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.