One claim is that for sufficiently large lists, some sorting algorithms are faster than others. For this project, you will demonstrate the speed difference between sorting algorithms listed below. You will implement the first 4 sorts yourself, and time the results. You will need to use lists large enough to show a difference in speed of 2 significant digits.
sufficiently large means it does not take too long and you have 2 significant digits of output for each search algorithm.
This project is about important theoretical and practical algorithms, rather than abstract data types. Sorting and searching are at the heart of many ideas and algorithms in Computing as a Science. Like Project 1, this will help train your intuition for using the more abstract Big-O notation to analyze algorithms. Expected runtimes assume that you implement good versions of the algorithms.
Implement the following sort functions. Each function should return the list, even though most of these are in-place, destructive sorts. Use of "lyst" as an identifier is NOT a typo since "list" is a Python type.
You must also use the builtin timsort--don't write this one yourself
quicksort and mergesort are typically recursive, and helper functions are often used internally. Any helper functions should be nested inside the function that uses it, NOT at module scope. Helper functions should not be directly callable outside the parent function.
Create a non-interactive main function that runs each each sort, times each run, and reports the results to the console. Be sure to randomize the list between calling successive sort functions.
Figure 1. Example timing report for sorting routines. Actual sorting routines and times will be different. see image.
Use the functions in the random module for generating lists of numbers.
DATA_SIZE = 100000
seed(0)
DATA = sample(range(DATA_SIZE * 3), k=DATA_SIZE)
test = DATA.copy() # don't sort DATA, sort a copy of DATA
print("starting insertion_sort")
start = perf_counter()
test = insertion_sort(test)
Use the Python 3 time.perf_count() to calculate runtimes.