0
869views
Compare binary search and linear search algorithm
1 Answer
3
45views



Linear Search Algorithm Binary Search Algorithm
Linear search is an algorithm to find an element in a list by sequentially checking the elements of the list until finding the matching element. Binary search is an algorithm that finds the position of a target value within a sorted array.
It is based on the sequential approach. It is based on the divide and conquer approach.
It is less efficient in the case of large-size data sets. It is more efficient in the case of large-size data sets.
It is not required to sort the array before searching the element. It is necessary to sort the array before searching the element.
It can be implemented on both a single and multidimensional array. It can be implemented only on a multidimensional array.
In the linear search, worst case scenario for searching an element is equivalent to O(n) number of comparison. In the binary search, the worst case scenario is O(Log2n) number of similarities.
The best case scenario in a linear search is to find the element in the first position O(1). The best case scenario is to find the element in the middle position O(1).
Time complexity of linear search is O(n). Time complexity of Binary search is O(log2n).
Please log in to add an answer.