I have learned that finding the minimum/maximum of an unimodal function can be done with ternary search, an algorithm that runs in O(logN)
time (where N
is the size of the given search range).
However, I recently had the thought that maybe we could accomplish finding the max/min of an unimodal function with binary search as well. Specifically, for functions that have a definite maximum, we could find and return the first x-value for which f(x) >= f(x+Epsilon)
(where Epsilon is the allowed error bound). On the other hand, for functions that have a definite minimum, we could find and return the first x-value such that f(x) <= f(x+Epsilon)
.
Overall, my question is, why is ternary search used at all for this search operation if binary search can accomplish the same applications? Am I missing something here, or have I made some other logical mistake?