Searching is the process of looking for a certain item in a list. If the element is found in the list, the process is considered successful, and the location of that element is returned; otherwise, the search is considered unsuccessful. To search some items in the list, two prominent search strategies are extensively utilized. However, the algorithm chosen is determined by the list's organization.
Linear search, often known as sequential search, is the most basic search technique. In this type of search, we simply go through the entire list and match each element to the Item whose position has to be discovered. The algorithm delivers the Item's location; otherwise, NULL is returned.
Complexity | Best Case | Average Case | Worst Case |
---|---|---|---|
Time | O(1) | O(n) | O(n) |
Space | O(1) |
|