This project compares the performance of Insertion Sort and Merge Sort in finding the k-th smallest element of a randomly generated list. The goal is to evaluate how each sorting algorithm behaves as the list size increases, using repeated measurements for benchmarking.
insertion.py– Uses Insertion Sort to sort the list and find the k-th smallest element.merge.py– Uses Merge Sort to sort the list and retrieve the k-th smallest element.
Each script:
-
Generates random lists of different sizes.
-
Selects a random valid
kfor each list. -
Sorts the list using the chosen algorithm.
-
Retrieves the
k-thsmallest element. -
Measures and prints:
- Average execution time
- Maximum execution time
- List size
- Tested
kvalues (for Merge Sort)
List size: 5000
Average time: 0.4321 seconds
Max time: 0.4902 seconds
-----------------------------
- Python 3.x
- No external dependencies (uses only
random,timeand built-in functions)
Cláudio Alves Gonçalves de Oliveira Email: hi@claudioav.com
This project is licensed under the MIT License.