Question: Exercise 4 . Given an array A = [ a 0 , a 1 , . . . , an 1 ] , a sub

Exercise 4. Given an array A =[a0, a1,..., an1], a sub-array is an array of the form A[i, j]=
[ai, ai+1,..., aj ]. We want to design an algorithm that given A, find the largest sub-array such that
its elements sum to zero.
1. We define the prefix sum Si = Pi
j=0 aj as the sum of all elements in A[0, i]. Explain why if
there exists two values i1< i2 such that Si1= Si2, then it must be that Pi2
j=i1+1 aj =0, the
sum of elements in A[i1+1, i2] is zero. (Corrected 15 Oct)
2. Deduce a worst-case O(n log n) time algorithm that finds the largest sub-array of A which
sums to zero.
2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!