Let \(n=|keys|\). The sequential search (using a dictionary data structure) requires:
\(n+1=\mathcal O(n)\) (worst case) and
\(\frac{n+1}2=\mathcal O(n)\) (average case)
comparison operations.
def seqSearch(searchitem, dictionary): found = False # help variable found for k, v in dictionary.items(): if v == searchitem: found = True break
if found:
return k
else:
return False
dictionary = {1: "Zara", 2: "Tess", 3: "Bott", 4: "Dial"} print(seqSearch("Bott", dictionary)) 1. will output 1. will output