DSA II · Three algorithms, one problem

Maximum Subarray Comparison Lab

Find a nonempty contiguous subarray with maximum sum using incremental brute force, divide and conquer, or Kadane’s algorithm. Inspect candidate intervals, recursive calls, and running sums. All three use the same tie rule: earliest start, then earliest end.

Apply array after editing. Changing the algorithm replays the same array. One Step is an addition, call/split, return, or result decision—not a fixed amount of CPU time.

Current interval and action

Current candidateBest foundActive recursive interval

Recursive call stack · bottom → top

Complete-run comparison for this array

AlgorithmGrowthElement-sum additionsMaximum sumInterval

This table summarizes completed executions on the current input, independently of playback. Counts include only additions used to form element sums, including left-sum + right-sum in divide and conquer. Comparisons, recursion, assignments, and initialization are excluded, so these counts are not total runtime.

Reading the three approaches

The answer must contain at least one element. An all-negative input therefore returns its largest element, not an empty interval with sum zero.