Information About ™Ternary Search |
| CATEGORIES ABOUT TERNARY SEARCH | |
| search algorithms | |
| optimization | |
|
THE FUNCTION Assume we are looking for a maximum of f(x) and that we know the maximum lies somewhere between A and B. For the algorithm to be applicable, there must be some value ''x'' such that
THE ALGORITHM function 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
if (f(leftThird) < f(rightThird)) return ternarySearch(f, leftThird, right, absolutePrecision) else return ternarySearch(f, left, rightThird, absolutePrecision) |
|
|