• This repository has been archived on 28/Dec/2023
  • Stars
    star
    403
  • Rank 107,140 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Algorithms implemented in Rust, explained.

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

More Repositories

1

audiotags

Unified IO for different types of audio metadata
Rust
43
star
2

bioinformatics-algorithms-rs

Bioinformatics Algorithms implemented in Rust for Learners
Rust
30
star
3

rmarkdown-vscode

This extension provides a few snippets and key bindings for common tasks in .Rmd documents, such as inserting code chunks and including images using knitr::include_graphics(). Additionally, it aims to provide some helper functions for Bookdown and Blogdown.
TypeScript
29
star
4

clock-cli-rs

Command line clock utilities, with CLI and TUI interfaces, implemented in Rust
Rust
24
star
5

sudoku-tui

Play sudoku on the command line
Rust
18
star
6

r-and-tidyverse-book-ans

《R与tidyverse——数据分析入门》练习题的答案
HTML
13
star
7

nom-pdb

PDB parser implemented in Rust using nom
Rust
9
star
8

r-and-tidyverse-book

R与tidyverse——数据分析入门
TeX
7
star
9

cpp4r

[WIP] C++ for Rustaceans
C++
6
star
10

hhmmss

Format time and duration in chrono, std::time and time in HH:MM:SS
Rust
5
star
11

protein

Protein Structural Biology in Rust
Rust
5
star
12

ido

TUI Task Tracker
Rust
4
star
13

kdtree

k-dimensional tree in Rust
Rust
4
star
14

min-max

min! and max! macros for Rust
Rust
4
star
15

ChinaMapData

Easy-to-use standard China Map Data for R
R
3
star
16

romkan

A Romaji/Kana conversion library for Rust
Rust
3
star
17

suffix-array-li2016

An implemenetation of (part of) the suffix array construction algorithm developed by Zhize Li (2016)
Rust
3
star
18

sequence-alignment-js

Sequence Alignment Algorithms implemented in Javascript, with a command line application
JavaScript
3
star
19

nhk-easy

Python
2
star
20

rmarkdown-wrapper-js

Wrapper for RMarkdown, Bookdown and Blogdown
HTML
2
star
21

nom-fasta

FASTA parser implemented in Rust with nom
Rust
2
star
22

cs

Computing the Longest Common Substring
Rust
1
star
23

NetEaseMusic-Lyrics-sh

A shell script to search for and download lyrics from NetEase Music
Shell
1
star
24

clock-core-rs

Reusable components for implementing clock-related functionalities
Rust
1
star
25

knitr-js

JS implementation of knitr and R Markdown
TypeScript
1
star
26

Part-I-Notes

Biochemistry Part I notes
TeX
1
star
27

TianyiShi2001.github.io

HTML
1
star
28

carpe-diem

A handy time tracker for people who don't make plans but do care about their efficiency.
JavaScript
1
star
29

mactags

Read mac file tags on Linux and Windows in addition to Mac
Rust
1
star
30

r-helper-js

Helper functions for calling R in Node.js
TypeScript
1
star