This is a personal journey into implementing classic Data Structures and Algorithms (DSA) using idiomatic Rust.
While resources for DSA in languages like C++ (STL) and Python are abundant, finding high quality, ground up implementations in Rust can be challenging. Rust's strict memory safety, ownership model, and borrow checker make implementing even "simple" algorithms like Linked Lists or Quick Sort a unique challenge compared to other languages.
This repository serves as both a learning resource and a reference for writing memory-safe, efficient, and idiomatic Rust code.
A deep dive into
- Bubble Sort - The naive implementation.
- Optimized Bubble Sort - Adds a flag to detect early completion.
- Bidirectional Bubble Sort - Bidirectional variation.
- Shifting Bounds Sort - Dynamically shrinks the sorting window based on the last swap.
- Selection Sort - Minimizes writes by finding the minimum element first.
-
Insertion Sort - Efficient for small or partially sorted datasets; handles
usizeunderflow carefully. - Merge Sort - Memory-efficient implementation using a single scratch buffer.
-
Quick Sort - Hybrid implementation using
split_at_mutfor safe concurrency. -
Heap Sort -
$O(1)$ space complexity using implicit tree structures.