This repository contains C++17 implementations of algorithms and data structures from the classic textbook Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein (CLRS).
There are two goals for this repo:
- Provide clear, well-documented implementations for learners.
- Showcase C++ programming and algorithmic problem-solving skills.
cpp-algorithms/
│── README.md
│── LICENSE
│── .gitignore
│── CMakeLists.txt
│
├── docs/ # Explanations, notes, and complexity analysis
│ ├── 01-introduction.md
│ ├── 02-sorting.md
│ └── ...
│
├── include/ # Reusable headers
│ └── algorithms/
│ ├── sorting.hpp
│ ├── graph.hpp
│ └── dp.hpp
│
├── src/ # Algorithm implementations
│ ├── sorting/
│ │ ├── insertion_sort.cpp
│ │ ├── quicksort.cpp
│ │ └── heapsort.cpp
│ ├── data_structures/
│ │ ├── linked_list.cpp
│ │ └── red_black_tree.cpp
│ ├── graphs/
│ │ ├── bfs.cpp
│ │ ├── dfs.cpp
│ │ └── dijkstra.cpp
│ └── ...
│
└── tests/ # Unit tests
├── test_sorting.cpp
├── test_graphs.cpp
└── ...
Prerequisites
- C++ compiler (GCC, Clang, MSVC)
- C++17 or later
- CMake (optional, for easier builds)
g++ -std=c++20 -O2 src/sorting/insertion_sort.cpp -o insertion_sort
./insertion_sortmkdir build && cd build
cmake ..
make- Foundations
- Bubble Sort
- Insertion Sort
- Merge Sort
- Analyzing Algorithms
- Sorting & Order Statistics
- Heapsort
- Quicksort
- Counting Sort
- Radix Sort
- Bucket Sort
- Data Structures
- Linked List
- Binary Search Tree
- Red-Black Tree
- Hash Table
- Graph Algorithms
- BFS (Breadth-First Search)
- DFS (Depth-First Search)
- Dijkstra’s Algorithm
- Kruskal’s Algorithm
- Prim’s Algorithm
More algorithms will be added progressively — see Roadmap
This repo makes use of googletest, a Google Testing and Mocking Framework for C++
After building this project with cmake, you will find a binary file inside the build directory called runTests
Each algorithm includes:
- Source code in src/
- Explanation in docs/
- Complexity analysis
- Example usage in test cases
Example documentation:
- Complete all major Sorting algorithms
- Implement Dynamic Programming problems (Rod Cutting, LCS, Matrix Chain Multiplication)
- Implement Graph Algorithms (MSTs, Shortest Paths, Max Flow)
- Add Number Theory algorithms (GCD, Modular Arithmetic, RSA)
- Expand Advanced Data Structures (Red-Black Trees, B-Trees, Disjoint Sets)
- Add Unit Tests with GoogleTest / Catch2
- Provide Visualizations for key algorithms (via external tools or diagrams in
docs/)
Contributions are welcome!
- Open issues for bugs or suggestions
- Fork the repo & submit PRs with improvements
- Follow consistent coding style (C++20, clang-format recommended)
This project is licensed under the MIT License — see LICENSE
- Introduction to Algorithms (CLRS), 4th Edition
- Thomas H. Cormen
- Charles E. Leiserson
- Ronald L. Rivest
- Clifford Stein
- Open-source algorithm communities for inspiration