Half and one-third

Division:

Binary, that is, binary search, it is a high efficient search method. However, binary search requires linear table must sequential storage structure, and the elements in the table by a keyword ordered.

That is, two points must satisfy the conditions for the number of columns or a sequential logic (monotone

The only way to carry out two.

Find Method:

First, assume that the table element is in ascending order, the key intermediate position table recorded with the lookup key comparison, if the two are equal, then the lookup is successful; otherwise, use of the recording table into an intermediate position before and after the two sub-tables, if keywords middle position of the recording is greater than the search key, then look further before a child table, or further search after a child table. The process is repeated until the record satisfies the condition is found, the search is successful, or until the child table does not exist, at which time search is unsuccessful.

Suitable topics: Quickly find the location, the lookup function zero. . .

Three points:

Third, to an ordered sequence that is divided into three equal parts, and the size ratio, discarding the most part not satisfy the condition continues wherein the third;

Scope: Find function peak apex

step:

1, the value of the entire first section lmid ← n of n / 3 in / 3 + left.

2, an intermediate section and then take the right value rmid ← lmid + right, so that the inter-section is divided into three cells.

3, we have A [lmid] compares the value of x, if equal output directly lmid end of the algorithm, x than A [lmid] value we give up big range into the left fourth step, or we give up the right range right ← lmid repeat 1,2,3.

4. We A [rmid] and x are compared, if equal output directly rmid end of the algorithm, large x than A [rmid] value we give up the left interval left ← rmid, repeat 1,2,3, or we give up the right interval left ← lmid, right ← rmid, repeat 1,2,3

For details, see an increase through version.

Guess you like

Origin www.cnblogs.com/lbssxz/p/10992986.html