Let's populate an array with random integers:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
As you can see we can search for an item in an array data structure. We start at the first element and step through the array looking for the item.
This is known as linear search. There are a few different strategies for performing Linear Search. Here are two:
found = False
searchItem = int(input("Enter a search item: "))
for i in range (len(numArray)):
if numArr[i] = searchItem:
found = True
#end of loop
if found == False
print(f"{searchItem} is not in the array!")
else:
print(f"{searchItem} is in the array!")
data type INTEGER pseudocode ← array assign STRING index linear search BOOLEAN variable