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

No packages published