A C++ and Python project designed to implement, test, and benchmark various sorting algorithms.
This tool generates data arrays, sorts them using multiple techniques, and automatically logs performance metrics—such as execution time and memory usage into CSV files. The included Python tools can then be used to analyze and visualize the benchmark results.
The repository includes the following sorting algorithms:
- Bubble Sort
- Insertion Sort
- Shell Sort
- Merge Sort
- Hybrid Sort (Radix Sort + Insertion Sort)
src/: Contains all C++ source code, including algorithm implementations, array generation, memory management, and CSV handling.Tools/: Python scripts are used for analyzing, plotting, and visualizing the CSV benchmark data.Results/: The output directory where the generated CSV benchmark files are saved.Hybrid Sort/: Contains specific logic, data, or tests dedicated to the hybrid sorting approach.
To compile and run this project:
- C++ Compiler: Windows -
g++, macOS -clang++ - Windows PowerShell or standard command prompt.
- (macOS) OpenMP library - required for parallel execution.
brew install libomp
- Python 3.x (Optional: only needed if you want to run the analysis scripts in the
Tools/folder).
-
Download the Code: Click the green Code button at the top of this repository and select Download ZIP. Extract the folder to your computer.
-
Open the Project: Launch Visual Studio Code and open the extracted
Sorting-Algorithmsfolder. -
Open the Terminal: In the top menu, click Terminal > New Terminal (or press
Ctrl + `). -
Navigate to the Source Folder:
cd src -
Compile:
Windows:
g++ main.cpp BubbleSort.cpp InsertionSort.cpp ShellSort.cpp MergeSort.cpp HybridSort.cpp ArrayGenerator.cpp Files.cpp Memory.cpp CSV.cpp -o sort -lpsapi -fopenmp -O3
macOS
clang++ main.cpp BubbleSort.cpp InsertionSort.cpp ShellSort.cpp MergeSort.cpp HybridSort.cpp ArrayGenerator.cpp Files.cpp Memory.cpp CSV.cpp -O3 -std=c++17 -Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include -L$(brew --prefix libomp)/lib -lomp -o sort
-
Run:
Windows:
.\sort.exemacOS:
./sort
-
Clone the repository:
git clone https://github.com/mihu19/Sorting-Algorithms.git
-
Navigate to the
srcdirectory:cd Sorting-Algorithms/src -
Compile:
Windows:
g++ main.cpp BubbleSort.cpp InsertionSort.cpp ShellSort.cpp MergeSort.cpp HybridSort.cpp ArrayGenerator.cpp Files.cpp Memory.cpp CSV.cpp -o sort -lpsapi -fopenmp -O3
macOS
clang++ main.cpp BubbleSort.cpp InsertionSort.cpp ShellSort.cpp MergeSort.cpp HybridSort.cpp ArrayGenerator.cpp Files.cpp Memory.cpp CSV.cpp -O3 -std=c++17 -Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include -L$(brew --prefix libomp)/lib -lomp -o sort
-
Run:
Windows:
.\sort.exemacOS:
./sort