maximum of given function

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-20T14:09:09Z Indexed on 2010/05/20 14:10 UTC
Read the original article Hit count: 218

Filed under:

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

© Stack Overflow or respective owner

Related posts about algorithm