This repository contains C++ and Python implementations of various sorting algorithms. Each algorithm is optimized for general use, well-documented, and includes time complexity analysis. Perfect for learning, interviews, and competitive programming! 🚀
🔹 Bubble Sort – Repeatedly swaps adjacent elements (O(n²)).
🔹 Selection Sort – Selects the smallest element iteratively (O(n²)).
🔹 Insertion Sort – Builds a sorted array one element at a time (O(n²)).
🔹 Merge Sort – A divide & conquer sorting algorithm (O(n log n)).
🔹 Quick Sort – Efficient sorting using pivot selection (O(n log n) avg).
🔹 Heap Sort – Sorts using a binary heap (O(n log n)).
🔹 Shell Sort – Improved Insertion Sort with gap sequences (O(n log n) avg).
🔹 Counting Sort – Works well for small-range integers (O(n + k)).
🔹 Radix Sort – Sorts numbers by digits (O(nk)).
🔹 Bucket Sort – Distributes elements into buckets (O(n) avg).
📂 Sorting-Algorithms
│── 📜 bubble_sort.cpp
│── 📜 selection_sort.cpp
│── 📜 insertion_sort.cpp
│── 📜 merge_sort.cpp
│── 📜 quick_sort.cpp
│── 📜 heap_sort.cpp
│── 📜 shell_sort.cpp
│── 📜 counting_sort.cpp
│── 📜 radix_sort.cpp
│── 📜 bucket_sort.cpp
│── 📜 bubble_sort.py
│── 📜 selection_sort.py
│── 📜 insertion_sort.py
│── 📜 merge_sort.py
│── 📜 quick_sort.py
│── 📜 heap_sort.py
│── 📜 shell_sort.py
│── 📜 counting_sort.py
│── 📜 radix_sort.py
│── 📜 bucket_sort.py
│── 📜 README.md
| Algorithm | Best Case | Average Case | Worst Case |
|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) |
| Selection Sort | O(n²) | O(n²) | O(n²) |
| Insertion Sort | O(n) | O(n²) | O(n²) |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) |
| Quick Sort | O(n log n) | O(n log n) | O(n²) |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) |
| Shell Sort | O(n log n) | O(n log n) | O(n²) |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) |
| Radix Sort | O(nk) | O(nk) | O(nk) |
| Bucket Sort | O(n) | O(n) | O(n²) |
1️⃣ Clone this repository
git clone https://github.com/CyberMatic-AmAn/Sorting.git2️⃣ Compile and run any sorting program
For C++:
g++ merge_sort.cpp -o merge_sort
./merge_sortFor Python:
python merge_sort.pyFeel free to fork this repo, improve the code, and submit pull requests! 🚀