Question: The O(n)-time algorithm below searches a sorted array data for two values dataleftl and datafright) uch that datalleft] + datalright] t, for a given value

 The O(n)-time algorithm below searches a sorted array data for two

The O(n)-time algorithm below searches a sorted array data for two values dataleftl and datafright) uch that datalleft] + datalright] t, for a given value of t. Answer the following questions about he algorithm in the case where the array data has two values that add up to t, datalL] and data R here 1SLSRs n. Input: data: sorted array with n integers Input: n: size of data Input: t: integer representing a target value Output: (i,j): indices such that datali + datal]t 1 Algorithm: SumSearch 2 left 1; 3 right = n; 4 while data[left] + data[right]?t do s while dataleft + datafrightt do 6 | | left-left + 1; end s while datalle ft+ datalright]>t do | right = right-1; 10 end 11 end 12 return (left, right); (a) [10 points] Use proof by contradiction to show that if left L and right 2 R and datalle ftl + data[right

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 Databases Questions!