Git Product home page Git Product logo

algorithms-2's Introduction

Rusty Algorithms & Data Structures for Learners

Crates.io Crates.io Continuous Integration Coverage Status lines of code

This repository presents Rust implementations of common algorithms and data structures, many of which are based on William Fiset's Java implementation: https://github.com/williamfiset/Algorithms . I highly recommend his YouTube channel, where he explains many of these algorithms in detail using illustrations, animations and pseudocode. I recommend that you implement these algorithms by yourself before comparing them to my or William's implementations, since the best way to learn is by doing, and it's likely that you discover ways in which the code can be written in a more efficient, robust and/or readable way, in which case you're welcome to submit a PR!

I also write algorithms that's not yet available in William's repository. When I do so I attach references (most of which are freely accessible) that I used and hopefully they should be sufficient to guide you to write your own implementations.

Usage

The implementation details are explained in comments and docs and the example usage is implied in unit tests. To run tests:

cargo test

I use LaTeX to write some math expression in docs. To render them correctly in docs, run:

RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps --open

or an alias for this command:

./doc

Recommended Environment

This simple setup provides most features a decent IDE would provide (importantly, jump to definition and type labelling)

Contents

Search Algorithms

  • Binary Search
  • Interpolation Search
  • Ternary Search

Sort Algorithms

  • Merge sort
  • Selection sort
  • Bubble sort
  • Insertion sort
  • Counting sort
  • Heap sort
  • Radix sort
  • Bucket sort
  • Quick sort
    • Hoare partition

Graph

Graph Representations

  • Adjacency Matrix (Weighted & Unweighted)
  • Adjacency List (Weighted & Unweighted)
  • Condensed Adjacency Matrix (Weighted)

Fundamental Graph Algorithms

  • Depth-first search (iterative and recursive)
  • Breadth-first search (iterative)

Tree Algorithms

  • Tree representation: with or without pointer to parent
  • Fundamentals (DFS, tree height, tree sum, etc.)
  • Tree Center
  • Tree rooting
  • Tree isomorphism
  • Lowest common ancestor (LCA)

Minimum Spanning Tree/Forest

  • Prim's Algorithm
  • Kruskal's Algorithm

Network Flow

  • Ford-Fulkerson + DFS
  • DFS with capacity scaling
  • Edmonds-Karp Algorithm (BFS)
  • Dinic's Algorithm (BFS + DFS)

Shortest Path

  • BFS (unweighted)
  • DAG shortest path with topological sorting
  • Dijkstra's algorithm (non-negative weights, SSSP)
  • Bellman-Ford algorithm (SSSP)
  • Floyd-Warshall algorithm (APSP)

Others

  • Bipartite check
  • Topological sorting of DAG graphs and DAG shortest path
  • Eulerian path/circuit
  • Strongly connected components (Tarjan's algorithm)

Data Structures

  • Bit manipulation
  • Priority queue (binary heap)
  • Balanced tree
    • AVL tree
  • Disjoin set (union-find)
  • Sparse table (range query) (generic)
  • Quadtree
  • k-dimensional tree (k-d tree)

Machine Learning

Clustering

  • Hierarchical clustering (WIP, almost done)

K Nearest Neighbour (KNN)

  • in quad tree (docs/annotations WIP)
  • in k-d tree (docs/annotations WIP)

Math

  • GCD
    • Euclidean algorithm
    • Coprime
    • Extended euclidean algorithm
  • LCM
  • log2
  • Prime numbers
    • Prime check
    • Sieve of Eratosthenes
    • Prime factorization (Pollard's rho algorithm)

Linear Algebra (docs/annotations WIP)

  • Basics (matrix representation, matrix/vector arithmetics)
  • Determinant of square matrix (Laplace expansion)
  • Gauss-Jordan Elimination
  • LU Decomposition
  • Cholesky Decomposition

Problems

Dynamic Programming

  • Edit distance
  • Knapsack 0/1

Back Tracking

  • Sudoku
  • N-Queens

Graph

  • Travelling salesman problem (brutal force & DP)

Network Flow

  • Mice and owls

algorithms-2's People

Contributors

tianyishi2001 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.