Hi so the goal here is to improve the number of steps needed to find an element in a list using Sequential Search
.
So I have an unsorted List numbers = [5, 2, 1, 0, 3]
and i'm trying to find lets say element 3
. It takes 5 steps
to find it.
My task here is to create a new function called sortedSequentialSearch()
that takes in a sorted list in ascending order and improve it to reduce the steps needed to find element 3
.
Here's my code for the normal Sequential Search:
def sequentialSearch(theValues, target):
n = len(theValues)
count = 0
for i in range(n):
count = count + 1
if theValues[i] == target:
print(f"Found, {count} steps needed")
return True
return False
How can I improve this if I lets say pass in numbers.sort()
?