Create an Analysis experiment program using simple Python code

Analysis program

Create an Analysis experiment program using simple Python code (Introductory Python).

Assignment list below:

-Devise an Analysis experiment to verify that get item and set item are O(1) for dictionaries.

-Measure the execution time for get and set for various size dictionaries of n entries. (Have the program create a table of executions times for each size output. Each line will have the size, set time, and get time with tabs (\t) between the numbers.)

-Run the program with different sizes to show that the times are constant with respect to the size.

The program below can be used as an example.

{`import time
def timeInsert(n):
l = list(range(n))
times = 750
lists = [ list(l) for i in range(times)]
t1 = time.time()
for i in range(times):
x = lists[i]
x.insert(n-1,"x")
x.insert(n//2,"x")
x.insert(0,"x")
t2 = time.time()
return (t2-t1)
zeros = 0
for n in range(1,50000,150):
t = timeInsert(n)
print( "%d\t%f" % (n,t))
if t == 0.0:
zeros = zeros + 1
print("zeros: ", zeros)
`}

The code below can be used as an example for creating a dictionary.

{`
d = dict()
for i in range(n):
d[i] = i
dicts = [ dict(d) for i in range(times) ]
`}
citation generator
citaion generator
make money online