Binary search algorithm:
Binary search algorithm is used to find an element in an already sorted array.
STEPS 1:
It finds the middle element of the array and compare the element with the element to be searched, if
it matches then return true.
STEPS 2:
If not, then divide the array into two halves in which if element to be search is less than middle
element then search takes place in left part otherwise search in right half.
STEP 3:
Repeat this process, until you get the element.
Explanation:
Best case of Binary search occurs when element to be searched is the middle element of the array.
Then in that case, it just simply compares the element with the middle element, if matches then return
true. Comparing with the one element will take only O(1) time complexity.
Best Case: Search 35 in below give array
|
11 |
12 |
15 |
24 |
35 |
50 |
51 |
63 |
17 |
T(n) = O(1)

