|
1 | | -# Programming problems in rust |
| 1 | +# Programming problems & Data Structures In Rust |
| 2 | + |
| 3 | +A collection of **Rust implementations** for common programming problems, interview questions, and fundamental data structures. This project serves as a resource for those looking to understand algorithmic problem-solving in Rust with detailed explanations and efficient implementations. |
| 4 | + |
| 5 | +## ⚡ About the Project |
| 6 | +This repository provides well-structured and optimized solutions to classical algorithmic problems using Rust. Each problem includes: |
| 7 | +- **Clear Problem Descriptions**: Understanding the problem statement. |
| 8 | +- **Rust Implementations**: Efficiently written, idiomatic Rust code. |
| 9 | +- **Algorithmic Insights**: Explanation of the approach, trade-offs, and optimizations. |
| 10 | +- **Test Cases**: Ensuring correctness and performance. |
| 11 | + |
| 12 | +## ✨ Featured Problems & Implementations |
| 13 | +The project covers a variety of topics, including: |
| 14 | + |
| 15 | +### 🔢 **Array & Number Problems** |
| 16 | +- Segregate negatives & positives |
| 17 | +- Buy and sell stock once |
| 18 | +- Contains duplicate |
| 19 | +- Contains nearby duplicate |
| 20 | +- Maximum subarray sum |
| 21 | +- Two sum |
| 22 | +- Maximum product subarray |
| 23 | +- Product of array except self |
| 24 | +- K nearest points from a given point |
| 25 | + |
| 26 | +### 🔠 **String Problems** |
| 27 | +- Segregate RGB characters |
| 28 | +- Longest common prefix |
| 29 | +- Longest common suffix |
| 30 | + |
| 31 | +### 📈 **Dynamic Programming & Recursion** |
| 32 | +- Longest increasing subsequence |
| 33 | +- Number of ways to reach matrix end |
| 34 | +- Palindrome partitioning |
| 35 | +- N-Queens problem |
| 36 | +- Subsets (backtracking, iterative, bit manipulation) |
| 37 | +- Combination sum (multiple variants) |
| 38 | + |
| 39 | +### 🔍 **Search & Sorting** |
| 40 | +- Minimum in sorted rotated array |
| 41 | +- Insert a new interval to a list of sorted intervals |
| 42 | +- Search in a row and column-wise sorted matrix |
| 43 | +- Search a target in a sorted rotated array |
| 44 | + |
| 45 | +### 🌳 **Data Structures Implementations** |
| 46 | +- **Binary Search Tree (BST)** with parent pointers |
| 47 | +- **Trie (Prefix Tree)** for efficient string searching |
| 48 | +- **Min Heap & Max Heap** for priority queue operations |
| 49 | + |
| 50 | +## 🦀 Why Rust? |
| 51 | +Rust provides **memory safety**, **performance**, and **concurrency** without the overhead of garbage collection. This makes it an excellent choice for implementing algorithmic solutions that require efficiency and reliability. |
| 52 | + |
| 53 | +## 📜 Example: Binary Search Tree (BST) with Parent Pointers |
| 54 | +A **BST (Binary Search Tree)** allows efficient searching, insertion, and deletion of elements. Our implementation uses **parent pointers** to facilitate operations such as node deletion efficiently. |
| 55 | + |
| 56 | +### 🌲 Node Definition |
| 57 | +```rust |
| 58 | +struct Node<T: Ord + Default + Clone + std::fmt::Debug> { |
| 59 | + key: T, |
| 60 | + left: Option<Rc<RefCell<Tree<T>>>>, |
| 61 | + right: Option<Rc<RefCell<Tree<T>>>>, |
| 62 | + parent: Option<Weak<RefCell<Node<T>>>>, |
| 63 | +} |
| 64 | +``` |
| 65 | +### 🔧 Key Features |
| 66 | +- **Uses `Rc<RefCell<Node<T>>`** for shared ownership and interior mutability. |
| 67 | +- **Weak parent references** to prevent memory leaks. |
| 68 | + |
| 69 | +## 🏔️ Example: Max Heap Implementation |
| 70 | +A **Max Heap** ensures that the parent node is always larger than its children. It is useful for implementing priority queues. |
| 71 | + |
| 72 | +```rust |
| 73 | +#[derive(Debug)] |
| 74 | +pub struct MaxHeap<T: Ord> { |
| 75 | + elements: Vec<T>, |
| 76 | +} |
| 77 | +``` |
| 78 | +### 🔹 Heap Operations |
| 79 | +- **Insertion**: Adds an element and maintains heap property. |
| 80 | +- **Deletion**: Removes the largest element and rebalances the heap. |
| 81 | + |
| 82 | +## 💡 Who Is This For? |
| 83 | +This project is perfect for: |
| 84 | +- Rust developers looking to practice algorithms. |
| 85 | +- Engineers preparing for coding interviews. |
| 86 | +- Students learning data structures and algorithms. |
| 87 | + |
| 88 | +## 🤝 Contributing |
| 89 | +Contributions are welcome! Feel free to open issues, suggest improvements, or submit pull requests. |
| 90 | + |
0 commit comments