Linear search
The most common and simple method of searching through an array, which is to go through each element of an array and compare it to whatever you're searching for. Only needs one counter, 'i', to go through the array with. Breaks the loop after either the element is found or the end of the array has been reached.
def linear(numberlist, item):
for x in range(0, len(numberlist)):
if item == numberlist[x]:
return x
return None
Comments
Post a Comment