This repository contains an efficient implementation of the Timsort algorithm in Python. Timsort is a hybrid sorting algorithm derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data.
- Efficient implementation of Timsort
- Demonstrates advanced Python concepts
- Includes example usage and performance testing
Clone this repository to your local machine:
git clone https://github.com/LMouhssine/Timsort.git
cd Timsort
To use the Timsort implementation in your project, import the timsort
function from timsort.py
:
from timsort import timsort
# Example usage
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = timsort(arr)
print(sorted_arr)
Timsort has a time complexity of O(n log n) in the worst and average cases, and O(n) in the best case. It is designed to take advantage of partial ordering in the input data, making it particularly efficient for real-world datasets.
To run the unit tests, execute the following command in the project directory:
python -m unittest test_timsort.py
Contributions are welcome! Please feel free to submit a Pull Request.
This project is currently provided without a specific license. All rights are reserved by the project owner. If you wish to use, modify, or distribute this code, please contact the project owner for permission.
- Tim Peters for creating the Timsort algorithm
- Python Software Foundation for incorporating Timsort into Python's standard library