Notes
The sequential search is also called the linear search. It searches the element one by one in the order they existed in a list until a match is found or until the end of the list without a match.
Example
Let's search the number 5 in the list below
6, 8, 5, 4, 1, 3 Check the value at index 0; it is not 5; move to the next number
6, 8, 5, 4, 1, 3 Check the value at index 1; it is not 5; move to the next number
6, 8, 5, 4, 1, 3 Check the value at index 2; it is 5; end search.
Sample Code in Python
#Searching the number 5 in the list [6,8,5,4,1,3]
list1 = [6,8,5,4,1,3]
search_num = 5
def sequential_search(search_list, value):
for i in range(len(search_list)):
if search_list[i] == value:
return i
return -1
result = sequential_search(list1, search_num)
if result == -1:
print("the number " + str(search_num) + " cannot be found!")
else:
print("the number " + str(search_num) + " is found at index " + str(result))