Maximum Subarray
Source Code
Description
This project compares two approaches to the max subarray problem. That is, given an array of integers, find the contiguous subarray with the largest sum. I compared the brute force approach, trying every possible subarray and taking the one with the largest sum, and Kadane's algorithm, which more or less keeps a running record of the current max subarray as you iterate through the array. This project really opened my eyes to the importance of complexity as it pertains to runtime. The results tell the story.
Main Takeaways
  • Complexity of algorithms
  • Understanding what a brute force approach is
  • Helper functions to keep code clean