Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey guys, I sure could use some help on this. I tried my very best and am beyond confused at this point. PROVIDED CODE: from

Hey guys, I sure could use some help on this. I tried my very best and am beyond confused at this point.

image text in transcribed

PROVIDED CODE:

from time import time

''' The ArrayList class simulates a fixed array in Python, ala ArrayList in Java. Here we specify a growth function when we create the ArrayList. You may not modify any of the code here, but you may add additional code that does not affect the functioning of this code. ''' class ArrayList: def __init__(self, growfn): '''Initializes the empty ArrayList with the specified growth function.''' self.size = 0; self.used = 0; self.array = [] self.grow = growfn;

def get(self, index): if index

def add(self, value): if self.used == self.size: newSize = self.grow(self.size) if newSize

''' Growth Functions Here is the basic growth function. You should add those from the assignment afterwards. ''' def double(size): if size == 0: return 1 return size + size

''' Additional growth functions for the solution. Three that were included in the assignment. '''

''' The analyzePerformance function accepts three parameters: * a list of N values for which results should be returned. * a growth function that returns the new size of the array given the old size. * the number of tries used to average the time. The analyzePerformance function returns a list of values, one for each value of N. Each of the values in the list is a dictionary {"grow": ..., "N":..., "seconds":..., "sizes":...} containing: * the growth function * the value of N * the decimal number of seconds required to add N elements to a new Array averaged over the specified number of tries. * the list of sizes the array grows through while adding the N elements Do not include the creation of the initial ArrayList object in the time. ''' def analyzePerformance(nList, gfn, tries): data = [] return data

''' Here is a sample main program for your testing purposes. We will use a different main program to call your analyze function with various lists and growth functions of our choice. You might graphs the values returned for the various functions to compare their actual versus expected behavior. ''' def main(): for result in analyzePerformance([1,10,100],double,11): print(result)

if __name__ == '__main__': main()

Assignment The supplied program implernents a form of ArrayList in Python. You will write a function to characterize its performance considering time anc space. You will need to complete the analyzePerformance function to gather the date in the requested format. You will be given a list of values for N, a function to use for array growth, and the number of tries to average the time result wer. This function returns a list of dictionaries, specified in the template code. dezanalyzePerformance(nlist,gfn,tries):data-11returndata Fur example, a cell of the form analyzePerformance( [10,100],fn,13) would produce the following resull, a list containing a dictionary for each of the values in the list. The sample main program prints this out, each on a separate line. [{grow:,N:20,seconds:,sizes:[]},{grow:,N:100,seconds:,aizea:[]}] We have provided a doub le function. You are encouraged to add the additional growth functions listed in 1.6.65 and test them out. You must create an additional growth function of your own design to discuss in the Canvas assignment along with those in 1.5.65. We will not use the the growth functions you create in the grading. You may not modify the existing code in the ArrayList class, but you may acd additional acde to this class to capture and return the requested values for the different sizes of the array. Do not include the 0 in the sizes list, only the sizes createc by the grow function. You will need to aralyze this code to decide how to instrument it corrently and have na impect on the expected results. You may also modify the main function to print the results from your other functions. Only the main function should do any printing. We do not use your main program in grading, it is ignored Grading We do not use your main program, grewth functicns, or printed output in the grading of this assignmert. We will unit test your analyzePerformance function by calling it directly using the following values and testing the list of dictionaries that your function returns. - different lists af N. - different growth functions defined in our test code. - different numbers of tries. Do your own coding, and do not look at other students' code You may discuss the assignment and your approaches with other students, but you may not share code or obtain it from outside scurces. 4535821527G1q Qn3758

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions