4. Here is a modified version of Kadane's Algorithm which starts from the right side and goes to [9 pts] the left: n = length (A) i = n - 1 maxoverall = A[i] maxendingati = A[i] print (A[i], maxendingati, maxoverall) for i = n-2 down to 0 inclusive: end maxendingati = max (maxendingati+A[i],A[i]) maxoverall = max (maxoverall, maxendingati) print (A[i], maxendingati, maxoverall) We run this algorithm on an unknown list of length 5 and look at the results of the print statements. The print statement executes five times. Fill in the missing information below: Which Print A[i] maxendingati First Time Second Time Third Time -8 Fourth Time Fifth Time 2 10 6 maxoverall 3 3

icon
Related questions
Question

READ THE FULL TABLE BEFORE AWNSERING
DO NOT USE AI LIKE THE LAST PERSON DID

4. Here is a modified version of Kadane's Algorithm which starts from the right side and goes to [9 pts]
the left:
n = length (A)
i = n - 1
maxoverall = A[i]
maxendingati = A[i]
print (A[i], maxendingati, maxoverall)
for i = n-2 down to 0 inclusive:
end
maxendingati = max (maxendingati+A[i],A[i])
maxoverall = max (maxoverall, maxendingati)
print (A[i], maxendingati, maxoverall)
We run this algorithm on an unknown list of length 5 and look at the results of the print
statements. The print statement executes five times. Fill in the missing information below:
Which Print
A[i]
maxendingati
First Time
Second Time
Third Time
-8
Fourth Time
Fifth Time
2
10
6
maxoverall
3
3
Transcribed Image Text:4. Here is a modified version of Kadane's Algorithm which starts from the right side and goes to [9 pts] the left: n = length (A) i = n - 1 maxoverall = A[i] maxendingati = A[i] print (A[i], maxendingati, maxoverall) for i = n-2 down to 0 inclusive: end maxendingati = max (maxendingati+A[i],A[i]) maxoverall = max (maxoverall, maxendingati) print (A[i], maxendingati, maxoverall) We run this algorithm on an unknown list of length 5 and look at the results of the print statements. The print statement executes five times. Fill in the missing information below: Which Print A[i] maxendingati First Time Second Time Third Time -8 Fourth Time Fifth Time 2 10 6 maxoverall 3 3
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer