|
4 | 4 | * algorithm](https://en.wikipedia.org/wiki/Binary_search_algorithm) |
5 | 5 | * @details |
6 | 6 | * Binary search is a search algorithm that finds the position of a target value |
7 | | - * within a sorted array. Binary search compares the target value to the middle |
8 | | - * element of the array. If they are not equal, the half in which the target |
| 7 | + * within a sorted array.Just like looking for a word in a dictionary, in binary search we compare the target value to the middle |
| 8 | + * element of the array. If they are not equal, then the half in which the target |
9 | 9 | * cannot lie is eliminated and the search continues on the remaining half, |
10 | 10 | * again taking the middle element to compare to the target value, and repeating |
11 | 11 | * this until the target value is found. If the search ends with the remaining |
12 | 12 | * half being empty, the target is not in the array. |
13 | 13 | * |
14 | 14 | * ### Implementation |
15 | 15 | * |
16 | | - * Binary search works on sorted arrays. Binary search begins by comparing an |
| 16 | + * Binary search works on sorted arrays. It begins by comparing an |
17 | 17 | * element in the middle of the array with the target value. If the target value |
18 | 18 | * matches the element, its position in the array is returned. If the target |
19 | 19 | * value is less than the element, the search continues in the lower half of |
|
28 | 28 | * Worst-case time complexity O(log n) |
29 | 29 | * Best-case time complexity O(1) |
30 | 30 | * Average time complexity O(log n) |
| 31 | + * space complexity 0(1) |
31 | 32 | * Worst-case space complexity 0(1) |
32 | 33 | * |
33 | 34 | * @author [Lajat Manekar](https://github.com/Lazeeez) |
|
0 commit comments