Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All of my data is coming back as constant and I don't know why, I should be getting constant, O(log n), and O(n) running times

All of my data is coming back as constant and I don't know why, I should be getting constant, O(log n), and O(n) running times

In python btwimage text in transcribedscreenshot of the csv is for bench(listAppend)

csv file is automatically created for whichever method is ran

import time import random import csv

listData = [] subList = []

for i in range(20): for n in range(1000000): subList.append(random.randrange(1000000000,1000000000000)) listData.append(subList) subList = []

#Runs the bench function 20 times on the listData list #Increments list length by 1mil each iterration starting at 1mil def bench(f): f_out = open('results.csv', 'w+') ######Uncomment this portion for benching lists for i in range(20): t1 = time.time() ans = f(listData[i]) t2 = time.time() t = t2-t1 t = "%.5f" %t f_out.write(str((i) * 1000000) + "," + str(t) + " ") ######Uncomment this portion for benching lists ######Uncomment this portion for benching dictionaries #for i in range(20): #dictData = {} #for line in listData[i]: #dictData[line] = None; #t1 = time.time() #ans = f(dictData) #t2 = time.time() #t = t2-t1 #t = "%.5f" %t #f_out.write(str(i) + " , " + str(t) + " ") f_out.close() print("Done") #List operations: (List is a collection which is ordered and changeable. Allows duplicate members) #append #remove #search 'in'

#Dictionary operations: (Dictionary is a collection which is unordered and changeable. No duplicate members) #add key, value #remove key #search 'in'

#This function appends a number to a list def listAppend(data): data.append(651612395876)

#This function inserts an element at the end of a list def listInsertLast(data): data.insert(-1, 651612395876)

#This function inserts an element at the beginning of a list def listInsertFirst(data): data.insert(0, 651612395876)

#This function inserts an element in the middle of a list def listInsertMiddle(data): middle = int(len(data) / 2) data.insert(middle, 651612395876)

#This function removes the last element from a list def listRemoveLast(data): data.remove(data[-1])

#This function removes the first element from a list def listRemoveFirst(data): data.remove(data[1])

#This function removes the middle element from a list def listRemoveMiddle(data): middle = int(len(data) / 2) data.remove(data[middle])

#This function searches for the last element in a list def listSearch(data): if data[-1] in data: return True else: return False

#This function adds a key and value to a dictionary def dictAppend(data): data[651612395876] = None

#This function tries to remove a key from a dictionary def dictRemove(data): data.pop(651612395876, None)

#This function searches for a key in a dictionary def dictSearch(data): if 651612395876 in data: return True else: return False

0 0 Chart Title 1 2 3 0 0 1 4 0 0.9 5 0 0.8 6 0 0.7 0 0.6 7 8 0 0.5 9 0 0.4 10 0 0.3 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 11000000 12000000 13000000 1400000 15000000 16000000 17000000 18000000 11 0.2 0 0.1 0 0 0 0 500 00 00 10000 000 150 00 000 200 00 000 0 12 13 14 15 16 17 0 0 0 18 0 0 19 20 19000000 0 0 0 Chart Title 1 2 3 0 0 1 4 0 0.9 5 0 0.8 6 0 0.7 0 0.6 7 8 0 0.5 9 0 0.4 10 0 0.3 1000000 2000000 3000000 4000000 5000000 6000000 7000000 8000000 9000000 10000000 11000000 12000000 13000000 1400000 15000000 16000000 17000000 18000000 11 0.2 0 0.1 0 0 0 0 500 00 00 10000 000 150 00 000 200 00 000 0 12 13 14 15 16 17 0 0 0 18 0 0 19 20 19000000 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

State three examples of a static load application.

Answered: 1 week ago

Question

What is dividend payout ratio ?

Answered: 1 week ago

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago