Блог пользователя Serh.kry

Автор Serh.kry, история, 8 лет назад, По-английски

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?

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится -10 Проголосовать: не нравится

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.

»
8 лет назад, # |
  Проголосовать: нравится -35 Проголосовать: не нравится

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.

»
8 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Binary*

»
8 лет назад, # |
Rev. 3   Проголосовать: нравится +9 Проголосовать: не нравится

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.

»
8 лет назад, # |
  Проголосовать: нравится +21 Проголосовать: не нравится

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

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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).