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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started