In this assignment, you will write a program to test the performance of three operations
1. dictionary lookup using key (d[key])
2. list lookup, i.e. finding the index of the first occurrence of a value (lst.index(v))
3. list sort (sorted(lst))
Before writing any code, think about this question:
What is the time complexity of each operation? Assuming Python adopts the most efficient
[ Hint: Choose from O(1), O(n), O(n log(n) ), O(n^2) ]
Now, write a program to test the performance of each operation using five problem sizes:
1K, 10K, 100K, 1M, 10M
Use random.sample() to generate unique values in random order. For example.
will assign L a list of size 10 with values 0 to 9, ordered randomly.
For the test dictionaries, you may make each entry’s value the same as the key using a technique
shown in the following example:
In the example, the dictionary d will have keys and values taken from the two lists passed to the
An example output the program is shown in Figure 1. For dictionary lookup: simply test the time
taken for finding d (i.e., retrieving the value for key=42); for list lookup, test the time taken
for finding the index of the first occurrence of 42.
Figure 1. Example output of the program. The ratios are time taken between problem size 10x
and size x; the list sort over list lookup is time ratio between sort and lookup of the same list size.
Note: you may get a divide by 0 error when computing ratios if there are 0’s in measured time.
In your report, make sure that you analyze the results and relate them to your answer to the
question posted earlier. Do your measurements provide evidence about the time complexity of
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more