B
B
BitNeBolt2022-01-12 19:17:59
Algorithms
BitNeBolt, 2022-01-12 19:17:59

How to find the maximum value of such a function?

61defd29bfa8a271411731.png
The answer should be in [lo; hi]

How can beansearch be adapted to it? How to check if the largest value is to the left or right of mid?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-01-12
@BitNeBolt

If your function is unimodal (first increasing, then decreasing), then you can use ternary search .
True, there it is required that the function should increase storgo and then strictly decrease.
If you have a horizontal function on segments of length 1 (i.e. from integer arguments), then ternary search can still be applied.
But if the function can take the same values ​​on an arbitrary interval, then there are no logarithmic algorithms for finding the maximum here. If both intermediate points give the same value, then there is no way to determine which of the three intervals contains the maximum.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question