Sequential Search
Sequential Search
Sequential search, also known as linear search, is a simple searching algorithm used to find an
element in a list or array.
It works by checking each element in the list one by one until the target element is found or the
entire list has been searched.
How It Works:
Start from the first element of the list.
Compare the current element with the target element.
If they match, return the index of the element.
If they don’t match, move to the next element.
Repeat the process until the element is found or the list ends.
If the element is not found, return a message indicating it is not in the list.
Time Complexity:
Best case: O(1)O(1)O(1) (if the target is the first element)
Worst case: O(n)O(n)O(n) (if the target is at the end or not in the list)
Average case: O(n)O(n)O(n) (since we may have to check half of the elements on average)