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.

Level: advancedTopic: Data structures algorithms

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.