Below are links to two standard algorithms (from Problem Solving with Algorithms and Data Structures using Python):
Each has a counter to keep track of how many comparisons are made.
Test the code with the following input lists. Which algorithm makes fewer comparisons for:
- 9, 20, 8, 1, 3, 10, 6, 2, 15, 4
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
- 1, 5, 10, 15, 20, 2, 8, 12, 16, 30
Submit your groups' answers to the following questions:
- What input data is worst (i.e. takes the most number of comparisons to sort) for insertion sort?
- What input data is the best (i.e. takes the least number of comparisons to sort) for insertion sort?
- What input data is worst (i.e. takes the most number of comparisons to sort) for merge sort?
- What input data is the best (i.e. takes the least number of comparisons to sort) for merge sort?