docs: Expand README with comprehensive Rust algorithm learning roadmap
This commit is contained in:
parent
bf28764ef5
commit
09c121833d
144
README.MD
144
README.MD
@ -2,13 +2,143 @@
|
||||
|
||||
Because I am not familiar with Rust, so it will be a good practice
|
||||
|
||||
## Basic Container
|
||||
1. Stack
|
||||
2. Queue
|
||||
3. Linked List
|
||||
> Goal: Learn Rust by implementing classic algorithms\
|
||||
> Principle: start simple, index-based first, avoid lifetimes early
|
||||
|
||||
## Search
|
||||
1. Binary Search
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## Sort
|
||||
## 🔍 Search
|
||||
|
||||
### 1. Binary Search
|
||||
|
||||
- Implement iterative version
|
||||
- Return `Option<usize>`
|
||||
- Practice slice borrowing: `&[T]`
|
||||
|
||||
**Rust focus** - `usize` - `Option` - bounds checking
|
||||
|
||||
**Extensions** - `lower_bound` - `upper_bound` - `partition_point`
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🔃 Sort
|
||||
|
||||
### 2. Insertion Sort
|
||||
|
||||
- In-place sorting
|
||||
- Good for understanding mutable slices
|
||||
|
||||
**Rust focus** - `&mut [T]` - index manipulation - borrow checker basics
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
### 3. Merge Sort
|
||||
|
||||
- Recursive implementation
|
||||
- Use temporary `Vec`
|
||||
|
||||
**Rust focus** - ownership vs borrowing - recursion - `Vec` allocation
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
### 4. Generic Sort
|
||||
|
||||
``` rust
|
||||
fn sort<T: Ord>(arr: &mut [T])
|
||||
```
|
||||
|
||||
**Rust focus** - generics - trait bounds (`Ord`)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🧭 Graph
|
||||
|
||||
### 5. Graph Representation
|
||||
|
||||
Recommended structure:
|
||||
|
||||
``` rust
|
||||
type Graph = Vec<Vec<(usize, i64)>>;
|
||||
```
|
||||
|
||||
**Rust focus** - tuple - type alias - index-based graph
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
### 6. BFS / DFS
|
||||
|
||||
- Implement using adjacency list
|
||||
- Use queue / stack
|
||||
|
||||
**Rust focus** - `VecDeque` - mutable borrow scope control
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
### 7. Dijkstra
|
||||
|
||||
- Use `BinaryHeap`
|
||||
- Implement min-heap with `Reverse`
|
||||
|
||||
**Rust focus** - `BinaryHeap` - `Reverse<T>` - ownership in heap
|
||||
elements
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🌱 Extra (Optional but Recommended)
|
||||
|
||||
### 8. Union-Find (Disjoint Set)
|
||||
|
||||
- Path compression
|
||||
- Union by rank
|
||||
|
||||
**Rust focus** - `struct` + `impl` - mutable state management
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
### 9. Tree Traversal
|
||||
|
||||
- Preorder / Inorder / Postorder
|
||||
|
||||
**Rust focus** - `Option<Box<T>>` - `match` exhaustiveness
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🗂 Suggested Repository Structure
|
||||
|
||||
``` text
|
||||
algorithms-in-rust/
|
||||
├── src/
|
||||
│ ├── search/
|
||||
│ │ └── binary_search.rs
|
||||
│ ├── sort/
|
||||
│ │ ├── insertion.rs
|
||||
│ │ └── merge.rs
|
||||
│ ├── graph/
|
||||
│ │ ├── bfs.rs
|
||||
│ │ └── dijkstra.rs
|
||||
│ ├── lib.rs
|
||||
└── tests/
|
||||
```
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🧠 Implementation Notes
|
||||
|
||||
- Prefer index-based structures early
|
||||
- Avoid `Rc<RefCell<T>>` unless truly needed
|
||||
- If borrow checker complains:
|
||||
- reduce scope
|
||||
- split logic into smaller functions
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
## 🎯 Recommended Order
|
||||
|
||||
1. Binary Search\
|
||||
2. Insertion Sort\
|
||||
3. Merge Sort\
|
||||
4. BFS\
|
||||
5. Dijkstra
|
||||
|
||||
After completing this list, you should be comfortable reading and
|
||||
writing most Rust algorithm code.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user