Linear search is a simple searching algorithm that sequentially checks each element in the list until a match is found or the whole list has been searched. It has a time complexity of O(n).
Explore Linear search AlgorithmBinary search is an efficient searching algorithm for sorted lists. It divides the list into two halves and compares the middle element with the target value. If they match, the search is successful. Otherwise, the search continues in the left or right half, depending on whether the middle element is smaller or larger than the target. Binary search has a time complexity of O(log n).
Explore Binary Search AlgorithmAlgorithm | Time Complexity | Advantages | Disadvantages |
---|---|---|---|
Linear Search | O(n) | Simple, works on unsorted lists | Slow for large datasets |
Binary Search | O(log n) | Efficient for sorted lists | Requires a sorted list |