3.3. Lab 2: Analysis of Algorithms and Hashtables¶
Due Date: 11:59pm February 4, 2024 Labs should be submitted as a single Jupyter notebook to CourseLink Dropbox This lab counts for 4% of the final grade |
3.3.1. Exercises¶
Complete the exercises embedded in the Lab 2 notebook.
What happens if you pop from the end of a the list? Write a function called
pop_right_list
that pops the last element instead of the first. Userun_timing_test
to characterize its performance. Then useplot_timing_test
with a few different values ofexp
to find the slope that best matches the data. What conclusion can you draw about the order of growth for popping an element from the end of a list?Write methods called
add_dict
andlookup_dict
, based onappend_list
andpop_left_list
. What is the order of growth for adding and looking up elements in a dictionary?Go back and run
run_timing_test
with a larger value ofmax_time
and see if the run time converges to the line with slope 2. Just be careful not to makemax_time
too big.Write a function called
lookup_hash_map
, based onlookup_better_map
, and characterize its run time. If things go according to plan, the results should converge to a line with slope 1. Which means thatn
lookups is linear, which means that each lookup is constant time. Which is pretty much magic.
3.3.2. Submission¶
Please submit a single Jupyter notebook which completes the above exercises. It should contain:
Your
pop_right_list
method, your analysis withrun_timing_test
, your plot usingplot_timing_test
and conclusion about its order of growthYour
add_dict
andlookup_dict
methods, and your analysis of their order of growthYour plot for
run_timing_test
with a larger value ofmax_time
Your
lookup_hash_map
method and your analysis of its run time