Question: In Java Suppose you are given an array of h integers, and you need to Tind all palrs oT Vaiues in the array (if any)

In Java

In Java Suppose you are given an array of h integers, and

Suppose you are given an array of h integers, and you need to Tind all palrs oT Vaiues in the array (if any) that sum to a given integer k. In a class named PairFinder, write code that performs this task for you and outputs all of the pairs that it finds. For example, if k is 12 and the array is [10, 4, 7, 7, 8, 5, 151, your code should output something like the following 4+8=12 7+5=12 7+5=12 Note that we get two 75 sums because 7 appears twice in the array. However, while the methods that you write may print a given pair of values more than once in such cases, it is not necessary to do so. In addition, the order in which the sums (and the terms within each sum) are printed does not matter. If no pairs are found, the methods do not need to print anything. 1. Implement a static method named findPairSums that requires O(n2) steps to solve this problem. The method should have the following header: public static void findPairSums(int k, int[] arr) In addition, you should add test code for it to a main method. You may find it helpful to call the randomArrayO method from our SortCount class to generate test arrays, although it also makes sense to use literal arrays that you define. 2. Implement a static method named findPairSumsFaster) that takes the same parameters as findPairSums, but that requires only O(nlogn) steps in the average case to solve this problem. (Hint: you should begin by sorting the array using one of the methods from our Sort class. Once you have done so, only O(n) additional steps are needed to find the pairs.) Here again, you should add test code to the main method

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!