Can ternary search always be replaced by binary search with compare of f(x) and f(x + eps)?
I mean what is the point of cutting 1/3 when we can cut 1/2 and have error = eps?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Can ternary search always be replaced by binary search with compare of f(x) and f(x + eps)?
I mean what is the point of cutting 1/3 when we can cut 1/2 and have error = eps?
Name |
---|
I don't really understand what you mean by f(x + eps),but check this blog :http://codeforces.me/blog/entry/11497
It might be useful.
thanks. it is exactly what im asking about
Going from f(x) to f(x + eps) or to f(x - eps) is neither binary nor ternary search. You don't get O(log) time in this case.
Binary*
Unimodal functions are functions with only one extreme point. Ternary search is, basically, a technique for finding the mode — e.g. the extreme point — of such a function. If the function is continuous and differentiable, which will probably be the case unless you work with discrete indices, the modified binary search basically searches for the x where f'(x) = 0, since (f(x + EPS) — f(x)) / EPS is a very good approximation to f'(x), for sufficiently small EPS. Because the derivative will always have a root at the extreme point, and there exists by definition of unimodality no other value that can have f'(x) = 0, the binary search you described is equivalent to ternary searching.
With infinitely precise calculation it should work.
the problem may be in that if you have x1 ≈ x2 = x1 + ε then f(x1) ≈ f(x2) and you may then go in wrong direction. It may be also the case for 1/3-division, but it will only happen when your range is too small, so that it almost won't affect the result
I've had that happen once before, but to be honest, it's probably not something to worry about unless the function changes very violently or the required precision is very, very tight (as in 10^-12).