A comprehensive collection of 34 fundamental algorithms implemented in 13 programming languages. This repository serves as both a learning resource and a practical reference for algorithm implementations across different programming paradigms.
- 34 Algorithms ร 13 Languages = 442 Implementations
- 102 Test Files covering 166 test cases (Python, JavaScript, Java)
- 100% Test Coverage for Python and JavaScript implementations
- 100% Consistent structure across all languages
- Production-ready code with examples
- Educational comments and documentation
| Language | Extension | Paradigm |
|---|---|---|
| C | .c |
Procedural |
| C++ | .cpp |
Object-Oriented/Generic |
| C# | .cs |
Object-Oriented |
| Clojure | .clj |
Functional |
| Go | .go |
Concurrent |
| Java | .java |
Object-Oriented |
| JavaScript | .js |
Multi-paradigm |
| Kotlin | .kt |
Multi-paradigm |
| PHP | .php |
Web-focused |
| Python | .py |
Multi-paradigm |
| Ruby | .rb |
Object-Oriented |
| Rust | .rs |
Systems |
| TypeScript | .ts |
Typed JavaScript |
๐ก See ALGORITHMS.md for detailed complexity analysis, use cases, and implementation notes for each algorithm.
๐ See DIAGRAMS.md for visual flowcharts and decision trees.
| Algorithm | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|
| Binary Search | O(log n) | O(1) | Searching in sorted arrays |
| Linear Search | O(n) | O(1) | Searching in unsorted arrays |
| Two Pointers | O(n) | O(1) | Array problems, pair finding |
| Algorithm | Time Complexity | Space Complexity | Stability | Use Case |
|---|---|---|---|---|
| Bubble Sort | O(nยฒ) | O(1) | Stable | Educational, small datasets |
| Merge Sort | O(n log n) | O(n) | Stable | Large datasets, external sorting |
| Quick Sort | O(n log n) avg, O(nยฒ) worst | O(log n) | Unstable | General purpose, in-place sorting |
| Heap Sort | O(n log n) | O(1) | Unstable | Memory-constrained environments |
| Algorithm | Time Complexity | Space Complexity | Type | Use Case |
|---|---|---|---|---|
| Linear Regression | O(n) | O(1) | Supervised | Continuous prediction |
| Logistic Regression | O(nรiterations) | O(n) | Supervised | Binary classification |
| Decision Trees | O(n log n) | O(n) | Supervised | Classification/Regression |
| Random Forest | O(n log n ร trees) | O(n ร trees) | Ensemble | Robust classification |
| Support Vector Machines | O(nยฒ) to O(nยณ) | O(n) | Supervised | High-dimensional classification |
| K-Means Clustering | O(nรkรiterations) | O(n+k) | Unsupervised | Data clustering |
| K-Nearest Neighbors | O(n) per query | O(n) | Lazy Learning | Classification/Regression |
| Gradient Boosting | O(nรtreesรdepth) | O(nรtrees) | Ensemble | High-accuracy prediction |
| Algorithm | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|
| Depth-First Search | O(V + E) | O(V) | Graph traversal, pathfinding |
| Breadth-First Search | O(V + E) | O(V) | Shortest path, level-order traversal |
| Dijkstra's Algorithm | O((V + E) log V) | O(V) | Shortest path in weighted graphs |
| Topological Sort | O(V + E) | O(V) | Dependency resolution, scheduling |
| Structure | Access | Search | Insertion | Deletion | Use Case |
|---|---|---|---|---|---|
| Hash Table | O(1) avg | O(1) avg | O(1) avg | O(1) avg | Fast key-value storage |
| Binary Search Tree | O(log n) avg | O(log n) avg | O(log n) avg | O(log n) avg | Ordered data storage |
| Linked List | O(n) | O(n) | O(1) | O(1) | Dynamic size, frequent insertions |
| Trie | O(m) | O(m) | O(m) | O(m) | String prefix operations |
| Algorithm | Time Complexity | Space Complexity | Technique | Use Case |
|---|---|---|---|---|
| Dynamic Programming | Varies | Varies | Memoization/Tabulation | Optimization problems |
| Knapsack Problem | O(nรW) | O(nรW) | 2D DP | Resource allocation |
| Edit Distance | O(mรn) | O(mรn) | 2D DP | String similarity |
| Longest Common Subsequence | O(mรn) | O(mรn) | 2D DP | Sequence alignment |
| Coin Change | O(nรamount) | O(amount) | 1D DP | Making change optimally |
| Algorithm | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|
| KMP Algorithm | O(n + m) | O(m) | Pattern matching |
| Palindrome | O(n) | O(1) | String validation |
| Algorithm | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|
| Fibonacci | O(n) | O(1) | Mathematical sequences |
| Euclidean Algorithm | O(log min(a,b)) | O(1) | Greatest Common Divisor |
| Sieve of Eratosthenes | O(n log log n) | O(n) | Prime number generation |
| Matrix Multiplication | O(nยณ) | O(nยฒ) | Linear algebra operations |
| Fibonacci | O(n) | O(1) | Mathematical sequences |
| Palindrome | O(n) | O(1) | String validation |
git clone v-hansen/algorithms.git
cd algorithmscd linear-regression
python linear_regression.pycd merge-sort
node merge_sort.jscd quick-sort
javac QuickSort.java
java QuickSortcd binary-search-tree
g++ binary_search_tree.cpp -o bst
./bstโโโ README.md
โโโ binary-search/
โ โโโ binary_search.py
โ โโโ binary_search.js
โ โโโ BinarySearch.java
โ โโโ ... (13 implementations)
โโโ merge-sort/
โ โโโ merge_sort.py
โ โโโ merge_sort.js
โ โโโ MergeSort.java
โ โโโ ... (13 implementations)
โโโ ... (21 algorithm directories)
Each algorithm directory contains:
- Consistent naming across languages
- Working examples with test data
- Minimal but complete implementations
- Educational comments where helpful
- Start with Bubble Sort and Linear Search
- Progress to Merge Sort and Binary Search
- Explore DFS/BFS for graph concepts
- Two Pointers technique
- Dynamic Programming patterns
- Tree/Graph traversals
- Quick Sort for general sorting
- Hash Tables for fast lookups
- Dijkstra for pathfinding
- Linear/Logistic Regression for baselines
- Random Forest for robust models
- K-Means for clustering
- O(1) - Constant: Hash table operations
- O(log n) - Logarithmic: Binary search, balanced trees
- O(n) - Linear: Linear search, array traversal
- O(n log n) - Linearithmic: Efficient sorting algorithms
- O(nยฒ) - Quadratic: Simple sorting, nested loops
- O(2โฟ) - Exponential: Recursive algorithms without memoization
- In-place algorithms: O(1) extra space
- Recursive algorithms: O(depth) stack space
- Dynamic programming: O(n) for memoization tables
- โ Consistent style across languages
- โ Error handling where appropriate
- โ Test cases included
- โ Documentation in code
- โ Optimal algorithms chosen for each use case
- โ Language-specific optimizations
- โ Memory-efficient implementations
- Fork the repository
- Create a feature branch
- Implement the algorithm in all 13 languages
- Test all implementations
- Submit a pull request
- Follow the existing directory structure
- Implement in all 13 languages
- Include test cases and documentation
- Update this README
- "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein
- "Algorithm Design Manual" by Steven Skiena
- "Hands-On Machine Learning" by Aurรฉlien Gรฉron
- MIT 6.006 Introduction to Algorithms
- Stanford CS161 Design and Analysis of Algorithms
- Coursera Machine Learning Course
- Python: 34 test files, 71 test cases (63 passing, 8 skipped)
- JavaScript: 34 test files, 61 test cases (100% passing)
- Java: 34 test files (requires JDK)
Python:
cd tests/python
python3 -m pytest -vJavaScript:
cd tests/javascript
npx jestJava:
cd tests/java
bash run_tests.shSee tests/README.md for detailed testing documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
- Computer Science Community for algorithm development
- Open Source Contributors for language implementations
- Educational Institutions for algorithmic foundations
โญ Star this repository if you find it helpful!
๐ Share with fellow developers and students!
๐ Use for learning, teaching, and reference!