|
| 1 | +# C++ Algorithms and Data Structures |
| 2 | + |
| 3 | +A compact C++20 review library for interview fundamentals. It favors explainable implementations, edge-case tests, and complexity notes over a large dump of copied problem solutions. |
| 4 | + |
| 5 | +## Included implementations |
| 6 | + |
| 7 | +| Category | Implementations | Time complexity | |
| 8 | +| --- | --- | --- | |
| 9 | +| Search/sort | binary search, merge sort, quick sort, heap sort | `O(log n)` search; `O(n log n)` sort average/guaranteed as documented in code | |
| 10 | +| Data structures | binary min-heap, trie, disjoint set, LRU cache | heap `O(log n)`; trie `O(k)`; DSU amortized `O(alpha(n))`; LRU `O(1)` | |
| 11 | +| Graphs | BFS, DFS, Dijkstra, topological sort, cycle detection, connected components | `O(V + E)` except Dijkstra `O((V+E) log V)` | |
| 12 | +| Arrays/strings | two sum, sliding-window maximum, longest unique substring, KMP | `O(n)` | |
| 13 | +| Dynamic programming | coin change, LIS, 0/1 knapsack, edit distance | from `O(n log n)` LIS to `O(mn)` edit distance | |
| 14 | +| Trees | BST validation, level-order traversal, BST lowest common ancestor | `O(n)` or `O(h)` | |
| 15 | + |
| 16 | +There are 25 focused implementations across two header files. The tests cover normal behavior, duplicates, missing values, graph cycles, deep BST violations, and cache eviction. |
| 17 | + |
| 18 | +## Build and test |
| 19 | + |
| 20 | +```bash |
| 21 | +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release |
| 22 | +cmake --build build --config Release |
| 23 | +ctest --test-dir build -C Release --output-on-failure |
| 24 | +``` |
| 25 | + |
| 26 | +The GitHub Actions matrix runs on both Linux and Windows. |
| 27 | + |
| 28 | +## Repository layout |
| 29 | + |
| 30 | +- `include/portfolio/data_structures.hpp` — heap, trie, disjoint set, and LRU cache. |
| 31 | +- `include/portfolio/algorithms.hpp` — search, sorting, graphs, arrays, strings, DP, and tree algorithms. |
| 32 | +- `tests/test_main.cpp` — dependency-free executable test harness. |
| 33 | + |
| 34 | +## My contributions |
| 35 | + |
| 36 | +- Selected a bounded set of fundamentals relevant to new-graduate SDE interviews. |
| 37 | +- Implemented each algorithm from first principles in modern C++20. |
| 38 | +- Added explicit edge-case behavior and a cross-platform warning-enabled build. |
| 39 | +- Documented complexity and kept the test harness dependency-free for quick review. |
| 40 | + |
| 41 | +## Study approach |
| 42 | + |
| 43 | +For each implementation I practice explaining the invariant, complexity, failure cases, and one alternative—not memorizing the source. This repository supports interview preparation; it is not a substitute for timed problem solving. |
0 commit comments