Write a brief advantages of binary search over linear search
Answers
Answered by
2
Linear search
In linear search we start from one end and traverse or visit every element , until we find that searched item or we run out of the list. Thus , if size of list is n then it would take at max n, and at least one comparison. So that for an average case , the number of comparisons is close to n. We can say that the complexity of linear search is O .
Binary search
This algorithm can only be used in a sorted list .The idea behind binary search is dividing the problems into smaller ones. We divide the list in two parts from the mid point of the list and compare the mid point with searched element .
In linear search we start from one end and traverse or visit every element , until we find that searched item or we run out of the list. Thus , if size of list is n then it would take at max n, and at least one comparison. So that for an average case , the number of comparisons is close to n. We can say that the complexity of linear search is O .
Binary search
This algorithm can only be used in a sorted list .The idea behind binary search is dividing the problems into smaller ones. We divide the list in two parts from the mid point of the list and compare the mid point with searched element .
Similar questions