Question: public static int findPair(int[] a, int x) The method will receive as parameters an array of integers sorted in ascending order and a number X.

public static int findPair(int[] a, int x)

The method will receive as parameters an array of integers sorted in ascending order and a number X. The method will check whether there are two numbers in adjacent cells in the array whose sum is equal to X. if present,

The method will return the index of the first cell. If not, the method will return -1.

For example, for the following array:

32 20 19 15 10 8 5 3 -1 -2

If we call the method with the given array and 13 = x it will return 3, because in the array there are two numbers in adjacent cells whose sum is equal to 13 (the numbers 5 and 8 that are in cells 3 and 4 respectively) and therefore it

Returns the index of the first (index 3). If we call the method with the given array and 39 = x the method will return 7 (the sum of the numbers 19 and 20 is equal to

39 and they are in adjacent cells, the first of which is in cell 7).

If we call the method with the given array - 11 = x the method will return 1- because there is no pair of members in adjacent cells

whose sum is equal to 11,

Note - the method should have the best possible runtime efficiency, and the best possible memory efficiency. A method that is not maximally efficient will not receive full points b. (5 points) What is the efficiency of the running time of the method you wrote! Explain your answer about Windows n

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!