Algorithm-1 (A:array[p..q] of integer)
sum, max: integer
sum = max = 0
for i = p to q
sum = 0
for j = i to q
sum = sum + A[j]
if sum > max then
max = sum
return max
How many times does the nested loop execute?
I'm aware that the first for loop has an O(n) complexity, and that the whole algorithm has a total complexity of O(n^2). However, I need the exact number of executions of the inner loop in order to prove this via a recurrence relation.