Question: Java-Algorithms Create an encapsulated private 1D integer array named arr. This is the only global variable allowed. Create a constructor that takes 1 parameter, a

Java-Algorithms

Create an encapsulated private 1D integer array named arr. This is the only global variable allowed.

Create a constructor that takes 1 parameter, a 1D integer array. The constructor initializes arr to have the same length as the parameter & copy all elements of the parameter to the array. Do not assign the reference of the parameter to the instance variable.Then, use the Arrays.sort method to sort the instance variable.(This is an in place method).

Create an instance method named findLeftBoundary that takes an integer parameter x and returns an integer. The method should find the largest value in arr that is <= x. If there is no left boundary value return -1.

This has to be recursive.

It may be helpful to create a private helper method to track value and indices during recursion.

Code should run in O(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!