import random import time deforderedSequentialSearch(alist, item): pos = 0 found
ID: 3612149 • Letter: I
Question
import random
import time
deforderedSequentialSearch(alist, item):
pos = 0
found = False
stop = False
while pos < len(alist) and not found and notstop:
if alist[pos] ==item:
found = True
else:
if alist[pos] > item:
stop = True
else:
pos = pos+1
returnfound
def main():
start = time.clock()
for count in range(1,100):
printrandom.randint
count =orderedSequentialSearch(alist)
random.randint =orderedSequentialSearch(item)
elapsed = (time.clock()- start)
if found == False:
print item, ("was not found in the list . Time : "),elapsed
else:
print item, ("was found in the the list. Time : "), elapsed
start = time.clock()
for count in range(1,1000):
printrandom.randint
count =orderedSequentialSearch(alist)
random.randint =orderedSequentialSearch(item)
elapsed = (time.clock()- start)
if found == False:
print item, ("was not found in the list . Time : "),elapsed
else:
print item, ("was found in the the list. Time : "), elapsed
start = time.clock()
for count in range(1,10000):
print random.randint
elapsed = (time.clock()- start)
count =orderedSequentialSearch(alist)
random.randint =orderedSequentialSearch(item)
if found == False:
print item, ("was not found in the list . Time : "),elapsed
else:
print item, ("was found in the the list. Time :"),elapsed
main()