Question: Given an integer array A and an integer k , we want to find all pairs of elements in the array that add up to
Given an integer array A and an integer k we want to find all pairs of elements in the array that add up to k For each pair found, print the two numbers. If it is not possible to find any such combination, print "Not possible." The elements in A are unique. The array elements and k could be positive, zero, or negative. You do not need to print the other permutation that represents the same pair.
Sample Run
Enter size of array:
Enter the elements:
Enter the value of k:
Sample Run
Enter size of array:
Enter the elements:
Enter the value of k:
Not possible.
There are two to four algorithms to solve this problem. One is a brute force algorithm, while the others are more efficient but require more code to implement. Design and analyze the bigO time complexity of two algorithms, then implement them.
public void findPairsBruteForceint input, int target
TODO
public void findPairsImprovedint input, int target
mergeSortinput; On log n sort given to you
Efficiency should be better than the brute force algorithm!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
