3.2. Homework 1: Analysis of Algorithms and Hashtables¶
Due Date: 11:59pm February 2, 2025 Homework should be submitted as a single Jupyter notebook to Dropbox |
3.2.1. Exercises¶
Complete the exercises embedded in the Homework 2 notebook.
What happens if you pop from the end of a the list? Write a function called
pop_right_listthat pops the last element instead of the first. Userun_timing_testto characterize its performance. Then useplot_timing_testwith a few different values ofexpto 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_dictandlookup_dict, based onappend_listandpop_left_list. What is the order of growth for adding and looking up elements in a dictionary?Go back and run
run_timing_testwith a larger value ofmax_timeand see if the run time converges to the line with slope 2. Just be careful not to makemax_timetoo 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 thatnlookups is linear, which means that each lookup is constant time. Which is pretty much magic.
3.2.2. Submission¶
Please submit a single Jupyter notebook which completes the above exercises. It should contain:
Your
pop_right_listmethod, your analysis withrun_timing_test, your plot usingplot_timing_testand conclusion about its order of growthYour
add_dictandlookup_dictmethods, and your analysis of their order of growthYour plot for
run_timing_testwith a larger value ofmax_timeYour
lookup_hash_mapmethod and your analysis of its run time