https://github.com/misaghmomenib/sorting-algorithms-python
A Collection of Sorting Algorithms Implemented in Python. This Project Provides Efficient and Easy-to-understand Implementations of Five Fundamental Sorting Techniques.
https://github.com/misaghmomenib/sorting-algorithms-python
algorithms git open-source python sorting-algorithms
Last synced: about 2 months ago
JSON representation
A Collection of Sorting Algorithms Implemented in Python. This Project Provides Efficient and Easy-to-understand Implementations of Five Fundamental Sorting Techniques.
- Host: GitHub
- URL: https://github.com/misaghmomenib/sorting-algorithms-python
- Owner: MisaghMomeniB
- Created: 2025-03-14T14:18:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-14T14:28:51.000Z (over 1 year ago)
- Last Synced: 2025-03-14T15:32:09.957Z (over 1 year ago)
- Topics: algorithms, git, open-source, python, sorting-algorithms
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π’ Sorting Algorithms in Python
A curated collection of classic **sorting algorithm implementations** in Python, designed for learning, comparison, and educational use.
---
## π Table of Contents
1. [Overview](#overview)
2. [Algorithms Implemented](#algorithms-implemented)
3. [Installation & Setup](#installation--setup)
4. [Usage & Examples](#usage--examples)
5. [Performance Comparison](#performance-comparison)
6. [Code Structure](#code-structure)
7. [Testing](#testing)
8. [Contributing](#contributing)
9. [License](#license)
---
## π‘ Overview
This repository presents a series of **classical sorting algorithms** implemented in plain Python. Each algorithm includes:
- Clean functional or class-based structure
- Docstrings and inline comments explaining the key steps
- Example usage and testcase scaffolding
Great for algorithm study, teaching, or benchmarking.
---
## β
Algorithms Implemented
- **Bubble Sort**
- **Insertion Sort**
- **Selection Sort**
- **Merge Sort**
- **Quick Sort**
- **Heap Sort**
- **Counting Sort** (integer arrays)
- **Radix Sort** (integer arrays)
- **TimSort**-like built on Pythonβs built-in `sorted()` (for reference)
---
## βοΈ Installation & Setup
```bash
git clone https://github.com/MisaghMomeniB/Sorting-Algorithms-Python.git
cd Sorting-Algorithms-Python
python3 --version # Requires Python 3.7+
````
No external dependenciesβeverything runs with the Python standard library.
---
## π Usage & Examples
Each algorithm script can be run directly or imported:
```bash
python bubble_sort.py
```
Example of using it in your code:
```python
from merge_sort import merge_sort
arr = [5, 2, 9, 1, 5, 6]
sorted_arr = merge_sort(arr)
print(sorted_arr) # [1, 2, 5, 5, 6, 9]
```
Compare algorithms in `benchmark.py` with configurable input sizes:
```bash
python benchmark.py --size 10000 --runs 5
```
---
## π Performance Comparison
Benchmarks are provided in `benchmark.py` to measure:
* Time complexity (best/average/worst cases)
* Memory usage
* Behavior with randomized vs. nearly-sorted data
Results output to console and saved as `benchmark_results.csv`.
---
## π Code Structure
```
Sorting-Algorithms-Python/
βββ bubble_sort.py
βββ insertion_sort.py
βββ selection_sort.py
βββ merge_sort.py
βββ quick_sort.py
βββ heap_sort.py
βββ counting_sort.py
βββ radix_sort.py
βββ tim_sort.py
βββ benchmark.py # Compare runtimes
βββ README.md
```
Each algorithm implements:
* A function (e.g., `def quick_sort(arr)`)
* Docstrings explaining time/space complexity
* Standalone `__main__` for demo
---
## π§ͺ Testing
Basic assertions included in each algorithmβs `__main__`. To run all tests:
```bash
python benchmark.py --test
```
Or add **pytest** later:
```bash
pip install pytest
pytest .
```
---
## π€ Contributing
Contributions welcomed! Ideas:
* Add additional sorts (e.g., Shell Sort, Bucket Sort)
* Implement in in-place vs. functional variants
* Enhance performance profiling
* Add visualizations (e.g., Matplotlib animation)
To contribute:
1. Fork the repo
2. Create a feature branch (`feature/...`)
3. Submit a clean Pull Request with descriptive title
---
## π License
Distributed under **MIT License**. See `LICENSE` file for details.