Using binary searchinterval halving prepare a method that


Question: Using binary search/interval halving, prepare a method that will guess the root of a number (JAVA)

We will be provided the subsequent method where int n is the number and p is the power you want the number to be raised to..

private static int power(int n, int p)

In JAVA, You need to write a method using the subsequent parameters and using the above method:

private static int root(int n, int r) {...}

I am thinking something along the lines of setting the high to n and the low to 0. 

The middle of the interval would then be n/2 = some number... 

Use this result raised to a power of r.. if is bigger than our high, which cannot be.  So the low stays at 0, and the high is now set to n/2 and so on. 

Please do proper documentation of code. I just cannot understand how to implement it.

 

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Using binary searchinterval halving prepare a method that
Reference No:- TGS0954012

Expected delivery within 24 Hours