Question
In Java Step 1. Write a method pairSearch(int [ ] value, int sum) that takes a sorted array and an integer sum as input, returns
In Java Step 1. Write a method pairSearch(int [ ] value, int sum) that takes a sorted array and an integer sum as input, returns 1 if there is a pair of elements that adds up to sum and returns -1 if there is no pair of element whose sum is equal to sum. ( for implementing this method you need to implement a version of linear search algorithm) Step 2. Write a method fasterPairSearch(int [ ] value, int sum) that takes a sorted array and an integer number sum as input, returns 1 if there is a pair of elements that adds up to sum and returns -1 if there is no pair of element whose sum is equal to sum. (for implementing this method you need to implement a version of binary search algorithm) Step 3. Implement a main method that asks user to enter 10 integer numbers as well as an integer value forsumanddisplaytheresults. Theoutputshouldbesimilartofollows: Enter 10 numbers: 1234567789 Enter a value for sum: 3 pairSearch result: found fasterPairSearch result: found Step 4. [Optional Step] Is there any faster way (that requires less comparisons) to implement the same method in Step 1 and Step 2? Implement it as a method called fastestPairSearch(int [ ] value, int sum)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started