Ternary search

Ternary search

A ternary search algorithm is a computer science technique for finding the minimum or maximum of a function that is either strictly increasing and then strictly decreasing or vice versa. A ternary search determines either that the minimum or maximum cannot be in the first third of the domain or that it cannot be in the last third of the domain, then repeats on the remaining two-thirds. A ternary search is an example of a divide and conquer algorithm (see search algorithm).

The function

Assume we are looking for a maximum of "f"("x") and that we know the maximum lies somewhere between "A" and "B". For the algorithm to be applicable, there must be some value "x" such that
* for all "a","b" with A ≤ "a" < "b" ≤ "x", we have "f"("a") < "f"("b"), and
* for all "a","b" with "x" ≤ "a" < "b" ≤ B, we have "f"("a") > "f"("b").

The algorithm

function ternarySearch(f, left, right, absolutePrecision) //left and right are the current bounds; the maximum is between them if (right-left < absolutePrecision) return (left+right)/2 leftThird := (left*2+right)/3 rightThird := (left+right*2)/3 if (f(leftThird) < f(rightThird)) return ternarySearch(f, leftThird, right, absolutePrecision) else return ternarySearch(f, left, rightThird, absolutePrecision) end

ee also

*Binary search (can be used to search for where the derivative changes in sign)
*Newton's method in optimization (can be used to search for where the derivative is zero)
*Golden section search (similar to ternary search, useful if evaluating f takes most of the time per iteration)
*Interpolation search
*Linear search

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Ternary search tree — In computer science, a ternary search tree (trie,TST) is a ternary (three way) tree data structure which combines the time efficiency of digital tries with the space efficiency of binary search trees. The resulting structure is faster than… …   Wikipedia

  • Ternary — (from Latin ternarius ) can mean:* Ternary complex, a complex formed by the interaction of three molecules * Ternary compound, a type of chemical compound * Ternary computer, a computer using a ternary numeral system * Ternary form, a form used… …   Wikipedia

  • Search algorithm — In computer science, a search algorithm, broadly speaking, is an algorithm that takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions. Most of the algorithms studied by computer… …   Wikipedia

  • Binary search tree — In computer science, a binary search tree (BST) is a binary tree data structurewhich has the following properties: *each node (item in the tree) has a value; *a total order (linear order) is defined on these values; *the left subtree of a node… …   Wikipedia

  • Linear search — In computer science, linear search is a search algorithm, also known as sequential search, that is suitable for searching a list of data for a particular value. It operates by checking every element of a list one at a time in sequence until a… …   Wikipedia

  • Interpolation search — is an algorithm for searching for a given key value in an indexed array that has been ordered by the values of the key. It parallels how humans search through a telephone book for a particular name, the key value by which the book s entries are… …   Wikipedia

  • Trie — A trie for keys A , to , tea , ted , ten , i , in , and inn . In computer science, a trie, or prefix tree, is an ordered tree data structure that is used to store an associative array where the keys are usually strings. Unlike a binary search… …   Wikipedia

  • List of mathematics articles (T) — NOTOC T T duality T group T group (mathematics) T integration T norm T norm fuzzy logics T schema T square (fractal) T symmetry T table T theory T.C. Mits T1 space Table of bases Table of Clebsch Gordan coefficients Table of divisors Table of Lie …   Wikipedia

  • Троичные алгоритмы — Троичные алгоритмы  алгоритмы, в которых применяется деление или умножение на 3 или на 3 в степени n и применяется троичная логика анализа результата. Хорошо подходят для реализации на троичных компьютерах, при эмуляции на двоичных… …   Википедия

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”