Introduction to algorithm – binary search algorithm

Algorithm premise:

The algorithm idea is:

1. Compare the middle value in the array with the searched value each time

2. If the intermediate value is less than the searched value, select the array to the right of the intermediate value and repeat 1 until an array element equal to the searched value is found or a value is returned, indicating that the searched value does not exist in the array.

3. If the intermediate value is greater than the searched value, select the array to the left of the intermediate value and repeat 1 until an array element equal to the searched value is found or a value is returned, indicating that the searched value does not exist in the array.

Here is my personal code implementation:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>