Editing Ternary search

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 32: Line 32:
 
The loop runs about <math>\log_{3/2}\frac{b-a}{\epsilon}</math> times, since each iteration reduces the length of the interval <math>[l,r]</math> by a factor of <math>\frac{3}{2}</math>. Each iteration involves two evaluations of the function, so the total number of evaluations is about <math>2\log_{3/2}\frac{b-a}{\epsilon}</math>. This is <math>\Theta\left(\log(b-a) + \log\frac{1}{\epsilon}\right)</math>, so the smaller the epsilon, the longer the search takes, but overall the time is logarithmic in the length of the initial interval.
 
The loop runs about <math>\log_{3/2}\frac{b-a}{\epsilon}</math> times, since each iteration reduces the length of the interval <math>[l,r]</math> by a factor of <math>\frac{3}{2}</math>. Each iteration involves two evaluations of the function, so the total number of evaluations is about <math>2\log_{3/2}\frac{b-a}{\epsilon}</math>. This is <math>\Theta\left(\log(b-a) + \log\frac{1}{\epsilon}\right)</math>, so the smaller the epsilon, the longer the search takes, but overall the time is logarithmic in the length of the initial interval.
  
An example application of ternary search is finding a point <math>Q_0</math> on a line segment <math>\ell</math> such that the distance <math>|PQ_0|</math> is minimal (where point <math>P</math> is given). Although there is a direct mathematical solution to this problem, an easier solution that allows us to approximate <math>Q_0</math> is to parameterize the line segment: let <math>Q(t)</math> be the point on the line segment that is a distance <math>t</math> from one of the endpoints, and then notice that <math>|PQ(t)|</math> is a bitonic function whose minimum we wish to find (this can easily be proven using the Pythagorean theorem). Thus, ternary search can be used to find the point. Intuitively, we divide the line segment into thirds, and measure the distance from <math>P</math> to each of the two dividing points, thus discarding one third of the segment, and repeating as far as necessary.
+
[[Category:Pages needing example problems]]

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)