Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is binary search?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report