Skip to content

This repository contains Python and C++ implementations of various sorting algorithms, including Bubble Sort, Quick Sort, Merge Sort, Heap Sort, Counting Sort, Radix Sort, and more. Each algorithm is optimized, well-documented, and includes time complexity analysis. Perfect for learning, interviews, and competitive programming! πŸš€

Notifications You must be signed in to change notification settings

CyberMatic-AmAn/Sorting

Repository files navigation

Sorting Algorithms in C++ & Python πŸ”’βš‘

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! πŸš€

πŸ“Œ Included Sorting Algorithms

1️⃣ Comparison-Based Sorting

πŸ”Ή 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).

2️⃣ Non-Comparison Sorting

πŸ”Ή 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).

πŸ“‚ Folder Structure

πŸ“‚ 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  

⏳ Time Complexity Comparison

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Β²)

πŸ’‘ How to Use?

1️⃣ Clone this repository

git clone https://github.com/CyberMatic-AmAn/Sorting.git

2️⃣ Compile and run any sorting program
For C++:

g++ merge_sort.cpp -o merge_sort
./merge_sort

For Python:

python merge_sort.py

πŸ“Œ Contributions

Feel free to fork this repo, improve the code, and submit pull requests! πŸš€

About

This repository contains Python and C++ implementations of various sorting algorithms, including Bubble Sort, Quick Sort, Merge Sort, Heap Sort, Counting Sort, Radix Sort, and more. Each algorithm is optimized, well-documented, and includes time complexity analysis. Perfect for learning, interviews, and competitive programming! πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published