Question: Solve the following problem using balanced binary search trees (TreeSet or TreeMap whichever is appropriate). Given array A of integers, and integer x, find a

 Solve the following problem using balanced binary search trees (TreeSet or

Solve the following problem using balanced binary search trees (TreeSet or TreeMap whichever is appropriate). Given array A of integers, and integer x, find a pair of integers i #j with A[i] + AU] = x. The array is not sorted, but it does not contain duplicate elements. If there are multiple pairs that sum to x, choose a pair in which the smaller of two elements is as big as possible. For example, if A = {3, 6, 4, 1, 5, 2} then sumOf(A, 8) returns {0,4} corresponding to the pair A[0] = 3, A[4] = 5, whose sum is 8. Note that this pair is preferred to {1,5}, because min(A[O], A[4]) = 3, which is bigger than min(A[1], A[5]) = 2. Class Pair { int one, two; Pair (int a, int b) {one = a two two = b;} } } Pair sumof (int[] A, int x) { //code to solve the problem; RT should be on log 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!