This homework assignment must be submitted in Gradescope by Noon central time on Tuesday March 26, 2024.
Collaboration is prohibited, and while working on this you should only consult the resources (books, online, etc.) listed below.
This assignment corresponds to Worksheet 10 and is about matplotlib
.
The materials you may refer to for this homework are:
Most likely useful
This homework assignment has two problems. The grading breakdown is:
Points | Item |
---|---|
4 | Autograder syntax checks (problem 1) |
5 | Problem 2 |
5 | Problem 3 |
14 | Total |
Ask your instructor or TA a question by email, in office hours, or on discord.
Here are links to two CSV files you should download:
Each one contains timing data for three sorting algorithms:
mergesort
we wrote in classquicksort
we wrote in classEach row of file timing-random.csv
shows the time taken by each algorithm to sort a list that is randomly shuffled. The first column of the file, n
, is the length of the list for that test.
The file timing-nearlysorted.csv
is similar, but for those tests the list used is in "nearly sorted order".
Write a Python script that does the following:
timing-plot-random.png
and timing-plot-nearlysorted.png
.In each plot there should be a title, axes labels, a legend, and the data for each algorithm should appear in a different color. Use dots as markers, and do not have the data points connected by lines.
Choose limits on the y
axis so that if one of the tests takes much longer than all the others, it doesn't prevent the other two from being seen in detail. (It's OK if that means the long-running one goes off the top of the plot.)
Put your code in hwk10prob2.py
. Upload the code and both images timing-plot-random.png
and timing-plot-nearlysorted.png
to gradescope.
Work in hwk10prob3.py
.
Write a Python script to generate a plot as similar to the one below as you can manage. Try to do it with as few for
loops as you can manage, favoring numpy
features instead. (The code I used to generate it has no loops.)
Hint: You should use plt.scatter
.
Put your code in hwk10prob3.py
. Upload the code and a PNG image of your plot to gradescope.