A comprehensive collection of fundamental algorithms with C++ implementations, based on:
- Algorithms by Dasgupta, Papadimitriou, and Vazirani
- Artificial Intelligence: A Modern Approach by Russell and Norvig (Search Algorithms)
This repository provides battle-tested algorithm implementations with:
- Clean, readable C++ code
- Detailed modification guides for interview problems
- Real-world examples and use cases
- Time/space complexity analysis
Each algorithm includes:
algorithm_name.cpp- Base implementationREADME.md- Theory, modifications, and problem-solving patternsexamples/- Practical applications and variations
algorithms-repo/
├── divide-and-conquer/
│ ├── merge-sort/
│ ├── quick-sort/
│ ├── binary-search/
│ ├── master-theorem/
│ └── fast-fourier-transform/
├── greedy/
│ ├── huffman-coding/
│ ├── minimum-spanning-tree/
│ ├── dijkstra/
│ └── interval-scheduling/
├── dynamic-programming/
│ ├── longest-common-subsequence/
│ ├── knapsack/
│ ├── edit-distance/
│ ├── shortest-paths/
│ └── matrix-chain-multiplication/
├── graph-algorithms/
│ ├── dfs/
│ ├── bfs/
│ ├── topological-sort/
│ ├── strongly-connected-components/
│ └── max-flow/
├── search-algorithms/
│ ├── uninformed/
│ │ ├── depth-first-search/
│ │ ├── breadth-first-search/
│ │ ├── uniform-cost-search/
│ │ └── iterative-deepening/
│ └── informed/
│ ├── a-star/
│ ├── greedy-best-first/
│ └── bidirectional-search/
├── number-theory/
│ ├── gcd-euclidean/
│ ├── modular-arithmetic/
│ └── primality-testing/
└── data-structures/
├── heap/
├── union-find/
└── segment-tree/
g++ -std=c++17 -O2 -Wall algorithm_name.cpp -o algorithm_name
./algorithm_nameEach algorithm includes test cases:
cd algorithm-name/
make test- Start with the algorithm's README to understand the theory
- Study the base implementation
- Review the modification patterns
- Attempt the example problems
- Focus on the "Common Modifications" section in each README
- Practice the example problems
- Time yourself implementing variations
- Review complexity analysis
- Use the search function to find specific algorithms
- Check modification patterns for similar problems
- Reference the complexity analysis tables
- Merge Sort: O(n log n) sorting, useful for counting inversions
- Quick Sort: In-place sorting with average O(n log n)
- Binary Search: O(log n) searching in sorted arrays
- FFT: O(n log n) polynomial multiplication
- Dijkstra's Algorithm: Single-source shortest paths
- Prim's/Kruskal's: Minimum spanning trees
- Huffman Coding: Optimal prefix codes
- Interval Scheduling: Activity selection
- LCS: Longest common subsequence - O(mn)
- Knapsack: 0/1 and unbounded variants
- Edit Distance: String similarity and transformations
- Bellman-Ford: Shortest paths with negative edges
- DFS/BFS: Graph traversal fundamentals
- Topological Sort: Ordering with dependencies
- SCC: Strongly connected components (Kosaraju's)
- Max Flow: Ford-Fulkerson, Edmonds-Karp
- A*: Optimal pathfinding with heuristics
- Uniform Cost Search: Dijkstra variant for AI
- Iterative Deepening: Memory-efficient search
- Bidirectional Search: Meet-in-the-middle approach
- C++17 compatible compiler (g++ 7.0+, clang++ 5.0+)
- Make (optional, for build automation)
cd algorithm-name/
g++ -std=c++17 -O2 -Wall algorithm_name.cpp -o algorithm_name
./algorithm_namecd algorithm-name/examples/
g++ -std=c++17 -O2 -Wall example1.cpp -o example1
./example1Each algorithm should include:
- Clean, commented C++ implementation
- Comprehensive README with:
- Algorithm explanation
- Time/space complexity
- Common modifications
- Example problems with solutions
- Test cases covering edge cases
- Dasgupta et al. - Algorithms
- AIMA - Artificial Intelligence: A Modern Approach
- CP-Algorithms
- LeetCode - Practice problems
- Codeforces - Competitive programming
- Google: Graph algorithms, DP, system design with algorithms
- Meta: DFS/BFS variations, tree algorithms, optimization
- Amazon: Array/string manipulation, graph traversal, greedy
- Apple: Data structures, search algorithms, optimization
- Microsoft: DP, graph algorithms, tree problems
- Optimization algorithms
- Search algorithms with constraints
- Advanced DP
- Computational complexity analysis
coming soon
This repository is for educational purposes. Algorithm implementations are based on published works in the public domain.
- Sanjoy Dasgupta, Christos Papadimitriou, Umesh Vazirani - Algorithms
- Stuart Russell, Peter Norvig - Artificial Intelligence: A Modern Approach
Last Updated: December 2025
Maintained by: me!