The correct option is Linear Search
CONCEPT:
Consider a given sorted list =[2,4,6,8,10 ] where key=2 which is present at the first index
In linear search, every element of a given list is compared one by one with the given key.
We will match every element of the list with the given key=2 and we find element 2 at index 0 after performing 1 comparison.
Whereas, In binary search, the key to be searched is compared with the middle element of a sorted list:
i) If the element at the middle position matches the key the search is successful
ii) If the element at the middle position is greater than the key then the key element may be present in the left part of the list
iii) If the element at the middle position is smaller than the key, then the key element may be present in the right part of the list
This process continues till the element is found or the list is traversed completely.
Left index |
Right Index |
Middle |
Middle vs Key |
Number of Comparisons |
Logic |
0 |
4 |
(0+4)/2=2 |
6>2 |
1 |
As middle is > key then we set right = mid-1 |
0 |
1 |
(0+1)/2=0 |
2==2 |
2 |
As the middle = key then Search is successful.
|
In binary search, the number of comparisons required is 2.
Thus Number of Comparisons required by linear search is less than binary search.