Question: (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location

(a) Write a program in Java to implement a recursive search function

int terSearch(int A[], int l, int r, int x)

that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1.

The terSearch search function, unlike the binary search, must consider two dividing points

int d1 = l + (r - l)/3

int d2 = d1 + (r - l)/3

For the first call of your recursive search function terSearch you must consider l = 0 and r = A.length - 1.

(b.1) Implement a sub-linear running time complexity function in Java long exponentiation(long x, int n) to calculate x n .

(b.2) What is the running time complexity of your exponentiation function? Justify.

Important Notes:

For items (a) and (b.1) you must add the main method in your program in order to test your implementation.

There are no data errors that need to be checked as all the data will be assumed correct.

For item (b.1) your function you can use only the basic arithmetic operators (+, -, *, %, and /).

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!