The idea

Binary search vs Linear search

Binary SearchLinear SearchLogarithmictime complexity:O(log n)collection needsto be sorted toworkcollection doesnot need to besortedused to find atarget value in acollectionis an algorithmLinear timecomplexity:O(n)time complexityincreases ifcollection needsto be sortedWorks on bothsorted andunsortedcollections

The Binary Search algorithm) is more efficient than the (compares:: Linear search algorithm) when the input collection is sorted. It has O(log n) time complexity, while the latter has O(n time complexity.

If the list is not sorted, that changes. Because then, one would need to [use:: a sorting algorithm] before binary search, which could increase time complexity considerably.

So, depending on whether the input collection size and whether it is already sorted, using Linear Search might be better than using Binary search.

Relations

Sources