The ternary search algorithm is a fast algorithm for finding the minimum or maximum of a unimodal function , a function that either increases, or then decreases or decreases, and then increases. Suppose we are dealing with a function that decreases, then increases, and we want to find the minimum value. Triple search works using the following recursion:
- If the window size is "small enough," just return its midpoint.
- Otherwise:
- Rate the function on the left and right borders; call the values of l and r.
- Rate the function at points 1/3 and 2/3; call the values m 1 and m 2
- If m 1 <m 2 , then we are in an increasing region of the function, and the minimum cannot be between m 2 and r.
- If m 1 > gt; m 2 , then we are in a decreasing region of the function, if the minimum cannot be between l and m 1
- Recursively look for 2/3 that were not dropped.
This algorithm is fast because it can continue to drop 1/3 of the values at each iteration.
, - , , . , , . , . 1/3 , , 2/3 . , 1/3 2/3 1/2 - & epsilon; 1/2 + & epsilon; & epsilon;? , 1/2 - & epsilon; , , , 1/3 .
, & epsilon; = 1/1000, , 999/2000 . , ( , ):
1 : 1.0 >= 1.0
2 : 0.666666666667 >= 0.5005
3 : 0.444444444444 >= 0.25050025
4 : 0.296296296296 >= 0.125375375125
5 : 0.197530864198 >= 0.0627503752501
6 : 0.131687242798 >= 0.0314065628127
7 : 0.0877914951989 >= 0.0157189846877
8 : 0.0585276634659 >= 0.00786735183621
9 : 0.0390184423106 >= 0.00393760959402
10 : 0.0260122948737 >= 0.00197077360181
11 : 0.0173415299158 >= 0.000986372187705
12 : 0.0115610199439 >= 0.000493679279947
13 : 0.00770734662926 >= 0.000247086479613
14 : 0.00513823108617 >= 0.000123666783046
15 : 0.00342548739078 >= 6.18952249147e-05
16 : 0.00228365826052 >= 3.09785600698e-05
17 : 0.00152243884035 >= 1.55047693149e-05
18 : 0.00101495922690 >= 7.76013704213e-06
19 : 0.000676639484599 >= 3.88394858959e-06
"", ? - , , ?