Crates.io | algs4_rs |
lib.rs | algs4_rs |
version | 0.6.0 |
created_at | 2025-08-29 19:18:46.219529+00 |
updated_at | 2025-09-19 01:45:16.458531+00 |
description | Rust implementations for the algorithms and clients in the text book "Algorithms, 4th Edition" by Robert Sedgewick and Kevin Wayne. |
homepage | https://github.com/rui-r-duan/algs4_rs |
repository | https://github.com/rui-r-duan/algs4_rs |
max_upload_size | |
id | 1816415 |
size | 236,188 |
This public repository contains the Rust source code for the algorithms and clients in the text book Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
My goal is to cover all the algorithms code that the official algs4
repo provides,
implementing them in Rust, trying to keep the APIs compatible to the official
Java version. In some cases, the APIs are designed to be idiomatic Rust, for
example, I/O APIs, len()
instead of size()
, and Option<&T>
instead of
NoSuchElementException
.
I hope that this crate helps people learn both Algorithms and Rust.
The I/O APIs are not stable. Breaking changes may be made in the versions 0.y.z
.
The current versions are good for learning, though.
tests
modules.examples
directory.examples
directory, and LinearRegression
in a library module.StdIn
, file input FileIn
, and abstract versatile input
In
, backed by the Java-util-like Scanner
. They are all implemented
without any external dependency.SVec
to demonstrate
Rust's equivalences of ResizingArrayStack
, ResizingArrayQueue
, etc.
Advanced Rust is demonstrated in SVec
.cargo build
cargo build --examples # build all the example binaries
cargo test
cargo test -- --show-output # show stdout
cargo test bst # only run the tests which contain name "bst"
cargo run --example doubling_ratio # only run the binary doubling_ratio
Most internal modules are re-exported. For example,
use algs4_rs::BST; // `algs4_rs::bst::BST` is used
Copyright © 2025 by Rui Duan.
This code is released under GPL version 3 or later.