The Quadratic Combine
This maximum-subarray-sum solution is correct but slow. The helper crossing uses a double loop, so it costs on a slice of length ; everything else in best is .
def best(a, lo, hi):
if hi - lo == 1:
return a[lo]
mid = (lo + hi) // 2
return max(best(a, lo, mid),
best(a, mid, hi),
crossing(a, lo, mid, hi))
What is the total running time on elements?
Sign in to answer questions and track your progress
Sign In