ALL > Computer and Education > courses > university courses > undergraduate courses > An Overview of Computer Science > ZSTU 2018-2019-1 class > student homework directory > 2018329621049_胡成一 >
homework6 Version 0
👤 Author: by 450766287qqcom 2018-11-10 16:21:22
Situation:

Binary search is faster than linear search except for small arrays, but the array must be sorted first.

 

Principle:

Binary search begins by comparing the middle element of the array with the target value. If the target value matches the middle element, its position in the array is returned. If the target value is less than the middle element, the search continues in the lower half of the array. If the target value is greater than the middle element, the search continues in the upper half of the array. By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration.

 

Time complexity:

Binary search runs in logarithmic time in the worst case, making O(log n) comparisons.

Please login to reply. Login

Reversion History

Loading...
No reversions found.