Algorithms implemented in Rust, explained.

Overview

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
You might also like...
Compare binary files using alignment algorithms

biodiff Compare binary files using alignment algorithms. What is this This is a tool for binary diffing. The tool is able to show two binary files sid

Genetic Algorithms Library

genx genx provides modular building blocks to run simulations of optimization and search problems using Genetic Algorithms (GA). The vision for genx i

DSP algorithms for embedded. Often integer math.

This crate contains some tuned DSP algorithms for general and especially embedded use.

ECFFT algorithms on the BN254 base field

ECFFT algorithms on the BN254 base field This crate implements structs and traits for the ECFFT algorithms from the paper Elliptic Curve Fast Fourier

A library that can be used as a building block for high-performant graph algorithms.

graph A library that can be used as a building block for high-performant graph algorithms. Graph provides implementations for directed and undirected

This library provides implementations of many algorithms and data structures that are useful for bioinformatics.

This library provides implementations of many algorithms and data structures that are useful for bioinformatics. All provided implementations are rigorously tested via continuous integration.

A small collection of procedural dungeon generation algorithms.

mapgen A small collection of procedural dungeon generation algorithms. Built with Rust & macroquad. WebAssembly build deployed here. Animated version

AI learns to play flappy bird using neuro-evolution, implemented in Rust using macroquad
AI learns to play flappy bird using neuro-evolution, implemented in Rust using macroquad

Flappy Bird AI AI learns to play flappy bird. This is a neuro-evolution simulation of flappy birds implemented in rust using macroquad Demo Usage Clon

Genetic Algorithm library in Rust

RsGenetic Summary and Features RsGenetic is a framework for executing genetic algorithms in Rust. It is designed to have a simple but modular API. Exa

Owner
Tianyi Shi
Biochemistry student; Open-source enthusiast; Rustacean
Tianyi Shi
darwin-rs, evolutionary algorithms with rust

darwin-rs This library allows you to write evolutionary algorithms (EA) using the Rust programming language. Written by Willi Kappler, License: MIT -

Willi Kappler 95 Jan 1, 2023
A tool used to evaluate the output of retrieval algorithms. Written in Rust.

Rusteval A tool used to evaluate the output of retrieval algorithms. Written in Rust. Building Install Rust with curl -sSf https://static.rust-lang.or

Giorgos Sfikas 17 Mar 22, 2022
This crate implements fast route planning algorithms in Rust.

This crate implements fast route planning algorithms in Rust. Algorithms Currently implemented: Contraction Hierarchies: The implementat

Payas Rajan 4 Aug 15, 2021
A browser app that evolves vehicles using genetic algorithms, written in Rust and Bevy

Vehicle Evolver Deluxe This is a simulation that uses AI (to be specific: genetic algorithms) to try to build better and better vehicles. The vehicles

null 95 Dec 26, 2022
"Algorithms for approximate string matching" in Rust, with Python bindings.

ukkonen Implementation of a bounded Levenshtein distance by Esko Ukkonen in "Algorithms for approximate string matching" in Rust, with Python bindings

Ethan Smith 1 Dec 1, 2021
Common data structures and algorithms for competitive programming in Rust

algorithm-rs algorithm-rs is common data structures and algorithms for competitive programming in Rust. Contents TBA How To Contribute Contributions a

Chris Ohk 16 Dec 21, 2022
zine/book about bitmap drawing algorithms and math with code examples in Rust

A Bitmapper's Companion - zine/book about bitmap drawing algorithms and math with code examples in Rust A small zine/book written in LaTeX. In progres

Manos Pitsidianakis 42 Nov 8, 2022
Bandit Algorithms in Rust

Multi-armed bandit algorithms in Rust Cargo [dependencies] bandit = "0.12.3" Description and Scope This library currently only implements the annealin

Michael Bohn 30 Nov 24, 2022
A Rust implementation the HOTP and TOTP Algorithms

xotp A Rust implementation the HOTP and TOTP Algorithms. HOTP was implemented in accordance with RFC4226 TOTP was implemented in accordance with RFC62

Tejas Mehta 3 Jan 21, 2022
Radiate is a parallel genetic programming engine capable of evolving solutions to many problems as well as training learning algorithms.

Radiate Coming from Evolutionary Radiation. Evolutionary radiation is a rapid increase in the number of species with a common ancestor, characterized

kalivas 109 Dec 18, 2022