We need a sorted array to perform a binary search in that case the time complexity already became greater than the linear search, so isnt linear search a better option in that case?
We need a sorted array to perform a binary search in that case the time complexity already became greater than the linear search, so isnt linear search a better option in that case?
Consider having Q Queries. Binary search complexity is O(NlogN + QlogN), but normal linear search is O(QN), a pretty big difference.
If you only have one search, then linear search would be faster. But if you're doing a bunch of searches, then you can sort the array once and do each of the searches in $$$O(\log n)$$$.