Question: 2 (15 points) Given a Python list (array) a: [ a[0], ..., a[n-1] ] of >2 floating point numbers, we would like to find two

2 (15 points) Given a Python list (array) a: [ a[0], ..., a[n-1] ] of >2 floating point numbers, we would like to find two elements a[i] and a[j] such that < and the absolute value of the difference |[][]| is minimized. The input to the function a list a and output should be a tuple of indices (i,j), wherein 0<< and the absolute difference |[][]| is the minimized. If there are multiple pairs (,) that produce the same absolute difference your algorithm can output any one of them. Example: Input a : [ 1, 9, 18, 14, 17, 11] Output: i,j = (2,4) Note that a[2] = 18 and a[4] = 17. The absolute difference 1 is the minimum possible among all pairs. First, describe the algorithm briefly in pseudocode or the main idea in words. Write down the complexity. Your algorithm must have a complexity (2) . In other words, the trivial (2) algorithm of going through all pairs of indices is not acceptable. You may use the solution to the previous problem assuming that it's complexity is (log()) . YOUR ANSWER HERE Implement your algorithm: You can use any in-built python list API function, including functions to sort a list in python. https://www.w3schools.com/python/python_ref_list.asp def findMinAbsDiff(a): # you must return a tuple (i,j) -- see instructions above. assert (len(a) > 2) in python code

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