Linear search is one of the simplest search algorithms. It sequentially checks each element in a list until the desired element (the target) is found or the list ends. This approach works on both sorted and unsorted lists, making it versatile for small datasets.
-1
).Scenario | Time Complexity | Explanation |
---|---|---|
Best Case | O(1) | The target is the first element in the list. |
Average Case | O(n) | The target is somewhere in the middle of the list. |
Worst Case | O(n) | The target is the last element or is not present at all. |
https://drawtocode.vercel.app/problems/linear-search
Loading component...
Loading component...