Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions