Code that defines a custom list class (linked lists) and implements four sorting algorithms; then records their runtimes when sorting lists with increasing number of elements.
List of nodes
python-lists-in-python/main.py
Lines 7 to 9 in 56f69ac
Nodes have a item in them and point to another node
python-lists-in-python/main.py
Lines 15 to 18 in 56f69ac
Bubble | Selection | Merge | Quick | |
---|---|---|---|---|
Time Complexity | O(n2) | O(n2) | O(n log n) | O(n log n) |
Compares pairs of elements and swaps them if they are out of order.
Takes the smallest element of the main list and adds it to a sub-list until it get to the end of the list.
Splits the list into elements, then merges pairs of sub-lists keeping, the elements in order until it is one list again.
Selects a pivot and moves all smaller elements to one side of the list then does the same to each side of the list.