One Pager Cheat Sheet
- We're going to learn about
Kadane's Algorithm
and its implementation in Python, JavaScript, and Java, in order to solve the Maximum Subarray Problem. - Kadane's Algorithm is a form of Dynamic Programming developed by Joseph Born Kadane which provides an optimal solution for the
Maximum Subarray Problem
. - The
Maximum Subarray Problem
is to find the largest sum of a contiguous subarray in an input array of size n. - The Brute Force approach can be used to calculate the largest sum of a contiguous subarray in an array by comparing all possible subarrays and setting the max sum to a globalMaxSum variable, with a time complexity of
O(n^2)
. - The time complexity of this algorithm is O(n2), as it requires two loops (
outer loop with index
ifrom 0 to n-1
andinner loop with index
jfrom j set to i to n-1
). - Kadene's Algorithm is an
optimal approach
with time complexityO(n)
, to the maximum subarray problem which is found by looping through the array, comparing thelocal Max Sums
, and updating theglobal Max Sum
at each iteration. - Kadene's Algorithm to find the largest sum of a contiguous subarray has a time complexity of O(n) due to its single loop iteration from
index 0
toindex n-1
. - We solved the
Maximum Subarray Problem
in an optimal way usingKadene's Algorithm
.