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

C language binary search (half search) algorithm and code

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Binary search is also known as half-and-half search, its advantage is that the search speed is fast, and the defect is that the data to be found by the request must be an ordered sequence. The basic idea of the algorithm is to compare the data of the two positions of the sequence you are looking for with the elements you are looking for. If they are equal, you will win. Otherwise, the sequence you are looking for will be divided into two parts based on that status. Then, according to the order discipline of the search sequence and the relationship between the two elements and the size of the element, we choose the local sequence where the element can exist, and take a different way to stop the search. Until you can be sure whether the element you are looking for can exist, the detailed usage can be understood in detail through the following code.

# include binarySearch (int a [], int n, int key) {int low = 0; int high = n-1; while (low

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

Network Security

Wechat

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

12
Report