Everyone Writes Ternary Search Suboptimally (Even tourist)

Правка en1, от early-morning-dreams, 2022-07-24 05:35:05

When it comes to writing a ternary search, what you usually do is this:

repeat 30/60/100/200 times {
    double lm = l + (r - l) / 3;
    double rm = r - (r - l) / 3;
    if (f(lm) < f(rm))
        r = rm;
    else
        l = lm;
}

Sources (notice the authors): 154861075 154863973

I recommend everyone who still writes like this to read this article . It will improve your ability to fit nested ternary searches. Also, I hope I don't need to explain why it is strictly better than the shown code.

Please, refrain from writing in the comments "but still their code works and is accepted!!1!".

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский early-morning-dreams 2022-07-24 05:46:13 11
en1 Английский early-morning-dreams 2022-07-24 05:35:05 772 Initial revision (published)