maximum of given function
- by davit-datuashvili
first of all i am doing programs in java language this code is merely taken from web site
i have not question about divide and conqurer but about function and it's argument here is code of ternary search
def ternarySearch(f, left, right, absolutePrecision):
#left and right are the current bounds; the maximum is between them
if (right - left) < absolutePrecision:
return (left + right)/2
leftThird = (2*left + right)/3
rightThird = (left + 2*right)/3
if f(leftThird) < f(rightThird):
return ternarySearch(f, leftThird, right, absolutePrecision)
return ternarySearch(f, left, rightThird, absolutePrecision)
i am not asking once again how implement it in java i am asking for example how define function?for example let y=x^+3 yes we can determine it as
public static int y(int x){
return x*x+3;
}
but
here
return ternarySearch(f, leftThird, right, absolutePrecision)
function f does not have argument and how do such?please help me