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

Implementation of binary search in C language

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Binary search, also known as half search (Binary Search), is a more efficient search method. However, half-and-half lookup requires that the linear table must have a sequential storage structure, and the elements in the table are arranged in order by keyword.

Usually when you look up an array, you will find that finding one by one is a waste of resources, so it is realized by binary lookup.

Algorithm requirements:

1. A sequential storage structure must be adopted.

two。 Must be arranged in order by keyword size.

First of all, assuming that the elements in the table are arranged in ascending order, compare the keywords recorded in the middle of the table with the search keywords, and if the two are equal, the search is successful; otherwise, the table is divided into the first and the last two sub-tables by using the intermediate location records. if the keyword of the intermediate location record is greater than the search keyword, then further look for the previous sub-table, otherwise further look for the latter sub-table. 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.

(above is a mind map)

# include#include / / while, do while, goto, for, Recursive void digui (int shang,int xia,int zhong,int num) {zhong = (shang + xia) / 2; if (shang

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

Internet Technology

Wechat

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

12
Report