Binary search vs Linear search
The idea
Binary search vs Linear search
!Binary search vs Linear search_image_1.svg
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
- [uses:: Big O Notation]
- [uses:: Double Bubble map]
- [scenarios:: Using database indexes can decrease performance]
- [is supported by:: Common algorithm complexities]