Binary search, also known as binary search, is a highly efficient search method. However, the halved search requires that the linear table must adopt a sequential storage structure, and the elements in the table are arranged in order by key.
Description of the steps of the bisection algorithm
① First determine the middle position of the entire search interval mid = ( left + right ) / 2
② Compare the keyword value to be checked with the keyword value in the middle position;
If they are equal, the search succeeds
If it is greater than, continue to search in half in the last (right) half area
If it is less than, continue to search in half in the first (left) half area
③ Repeat the above steps according to the halving formula for the determined reduced area.
Finally, the result is obtained: either the search succeeds or the search fails. The storage structure of the halved search is stored in a one-dimensional array. Example of halving search algorithm
For a given sequence (ordered) { 3, 5, 11, 17, 21, 23, 28, 30, 32, 50, 64, 78, 81, 95, 101}, according to the halved search algorithm, find the key value of 81 data element.