Searching
Searching algorithms check elements or retrieve an element from a data structure.
Based on search operations they can be divided into the following categories:
- Sequential Search
- Interval Search
Sequential Search
The list is traversed sequentially, and all the elements are checked. One example of sequential search is linear search.
Interval Search
They are used to search in sorted data structures. It is more efficient than sequential search. One of the examples of interval search is a binary search.
Linear search vs Binary search
| Linear Search | Binary Search |
| It accesses the data in sequential order. | It accesses the data randomly. |
| Data does not need to be sorted in linear search. | Data needs to be sorted in binary search. |
| Time complexity is -O(n) | Time complexity is O(log n). |
Reference
