Skip to content

v-hansen/algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Multi-Language Algorithm Library

Algorithms Languages Implementations License Completion Tests

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.

📊 Project Overview

  • 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

🔧 Supported Languages

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

📚 Algorithm Categories

💡 See ALGORITHMS.md for detailed complexity analysis, use cases, and implementation notes for each algorithm.

📊 See DIAGRAMS.md for visual flowcharts and decision trees.

🔍 Search & Basic Algorithms

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

🔄 Sorting Algorithms

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

🤖 Machine Learning Algorithms

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

🌐 Graph Algorithms

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

🏗️ Data Structures

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

🧮 Dynamic Programming

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

🔤 String Algorithms

Algorithm Time Complexity Space Complexity Use Case
KMP Algorithm O(n + m) O(m) Pattern matching
Palindrome O(n) O(1) String validation

📊 Mathematical Algorithms

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

🚀 Quick Start

Clone the Repository

git clone v-hansen/algorithms.git
cd algorithms

Run Examples

Python

cd linear-regression
python linear_regression.py

JavaScript

cd merge-sort
node merge_sort.js

Java

cd quick-sort
javac QuickSort.java
java QuickSort

C++

cd binary-search-tree
g++ binary_search_tree.cpp -o bst
./bst

📁 Project Structure

├── 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

🎯 Algorithm Selection Guide

For Learning:

  • Start with Bubble Sort and Linear Search
  • Progress to Merge Sort and Binary Search
  • Explore DFS/BFS for graph concepts

For Interviews:

  • Two Pointers technique
  • Dynamic Programming patterns
  • Tree/Graph traversals

For Production:

  • Quick Sort for general sorting
  • Hash Tables for fast lookups
  • Dijkstra for pathfinding

For Data Science:

  • Linear/Logistic Regression for baselines
  • Random Forest for robust models
  • K-Means for clustering

🔬 Complexity Analysis

Time Complexity Classes

  • 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

Space Complexity Considerations

  • In-place algorithms: O(1) extra space
  • Recursive algorithms: O(depth) stack space
  • Dynamic programming: O(n) for memoization tables

🛠️ Implementation Standards

Code Quality

  • Consistent style across languages
  • Error handling where appropriate
  • Test cases included
  • Documentation in code

Performance

  • Optimal algorithms chosen for each use case
  • Language-specific optimizations
  • Memory-efficient implementations

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement the algorithm in all 13 languages
  4. Test all implementations
  5. Submit a pull request

Adding New Algorithms

  • Follow the existing directory structure
  • Implement in all 13 languages
  • Include test cases and documentation
  • Update this README

📖 Educational Resources

Books

  • "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein
  • "Algorithm Design Manual" by Steven Skiena
  • "Hands-On Machine Learning" by Aurélien Géron

Online Courses

  • MIT 6.006 Introduction to Algorithms
  • Stanford CS161 Design and Analysis of Algorithms
  • Coursera Machine Learning Course

🧪 Testing

Test Coverage

  • 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)

Running Tests

Python:

cd tests/python
python3 -m pytest -v

JavaScript:

cd tests/javascript
npx jest

Java:

cd tests/java
bash run_tests.sh

See tests/README.md for detailed testing documentation.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🌟 Acknowledgments

  • 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!

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors