Different between Linear search vs Binary search
Linear search | Binary search |
It follows a sequential approach. | This follows a divide and conquer approach. |
It works well on unsorted data. | To apply binary search, data has to be sorted. |
Its worst-case time complexity is O(n). | Its worst-case time complexity is O(log n) |
It is slower in comparison to binary search. | It is more efficient than linear search. |
In linear search, we compare an element with every other element. | In binary search, we don’t compare an element with all other elements. We leave a few comparisons. |
We prefer linear search only for small-sized data. | It is preferred for large-sized data. |
We can implement linear search on all linear data structures like arrays and linked lists. | We can implement binary search only on those data structures that permit 2-way traversal. |
Comments
Post a Comment
If you have any doubts, Please let me know