Question: What is the correct loop invariant for the below code: for i in range(len(A): # in pseudo-code for i=0,..., len(A)-1 answer += A[1] return answer
What is the correct loop invariant for the below code: for i in range(len(A): # in pseudo-code for i=0,..., len(A)-1 answer += A[1] return answer The loop stops when i reaches the last element of the array. At the start of iteration i of the loop, the variable answer should contain the sum of the numbers from the subarray A[0:1-1). The loop iterates from i ranging from 0 to length of the array. The result of this code will be sum of all the elements of the array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
