Get the App
SLTechnology News&Howtos  ›  Development  › 

What is binary search?

Shulou Source: shulou.com Published: 2022-06-01 14:36:35 09月19日 Update

This article mainly explains "what is binary search". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is binary search"?

Binary search, also known as half search (Binary Search), is a more efficient search method. However, half-and-half search requires that the linear table must adopt a sequential storage structure, and the elements in the table are arranged in order by keywords, so the half-and-half search method is suitable for ordered lists that change infrequently and find frequent ordered lists.

First of all, assume that the elements in the table are arranged in ascending order, and compare the keyword recorded in the middle of the table with the lookup keyword. If the two are equal, the search is successful.

Otherwise, the table is divided into two sub-tables by using the intermediate location record, and if the keyword of the intermediate location record is greater than the search keyword, the former sub-table is further searched, otherwise the latter sub-table is further searched.

Repeat the above process until a record that meets the criteria is found, making the search successful, or until the child table does not exist, where the lookup is not successful.

# includeusing namespace std;int binary_search (int * A left int nint key) {int left=0,right=n-1;while (left > 1 if (key== A [mid]) return mid;else if (key > key;cout) so far, I believe you have a better understanding of "what is binary search", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Key keyword success location method order element content one learning practical deeper frequent two interest ascending order practicality practical simple operation efficiency Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft MariaDB Apple OPPO Reno