Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Everyone Writes Continuous Ternary Search Suboptimally (Even tourist)

Revision en2, by early-morning-dreams, 2022-07-24 05:46:13

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!".

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English early-morning-dreams 2022-07-24 05:46:13 11
en1 English early-morning-dreams 2022-07-24 05:35:05 772 Initial revision (published)