raghu 1.0.0rc1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- raghu-1.0.0rc1/LICENSE +22 -0
- raghu-1.0.0rc1/PKG-INFO +198 -0
- raghu-1.0.0rc1/README.md +173 -0
- raghu-1.0.0rc1/pyproject.toml +50 -0
- raghu-1.0.0rc1/raghu/__init__.py +74 -0
- raghu-1.0.0rc1/raghu/containers.py +374 -0
- raghu-1.0.0rc1/raghu/graphs.py +689 -0
- raghu-1.0.0rc1/raghu/linear.py +430 -0
- raghu-1.0.0rc1/raghu/py.typed +0 -0
- raghu-1.0.0rc1/raghu/searching_sorting.py +228 -0
- raghu-1.0.0rc1/raghu/trees.py +692 -0
- raghu-1.0.0rc1/raghu.egg-info/PKG-INFO +198 -0
- raghu-1.0.0rc1/raghu.egg-info/SOURCES.txt +21 -0
- raghu-1.0.0rc1/raghu.egg-info/dependency_links.txt +1 -0
- raghu-1.0.0rc1/raghu.egg-info/requires.txt +3 -0
- raghu-1.0.0rc1/raghu.egg-info/top_level.txt +1 -0
- raghu-1.0.0rc1/setup.cfg +4 -0
- raghu-1.0.0rc1/tests/test_containers.py +300 -0
- raghu-1.0.0rc1/tests/test_exports.py +32 -0
- raghu-1.0.0rc1/tests/test_graphs.py +401 -0
- raghu-1.0.0rc1/tests/test_linear.py +199 -0
- raghu-1.0.0rc1/tests/test_searching_sorting.py +118 -0
- raghu-1.0.0rc1/tests/test_trees.py +312 -0
raghu-1.0.0rc1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) <YEAR> <YOUR NAME>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED
|
|
16
|
+
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
raghu-1.0.0rc1/PKG-INFO
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: raghu
|
|
3
|
+
Version: 1.0.0rc1
|
|
4
|
+
Summary: Clean OOP data structures and standalone algorithms in pure Python, with zero dependencies.
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: data-structures,algorithms,dsa,sorting,searching,education
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# raghu
|
|
27
|
+
|
|
28
|
+
Clean, type-safe OOP data structures and standalone algorithms in pure Python. Zero runtime dependencies.
|
|
29
|
+
|
|
30
|
+
`raghu` provides reliable, well-tested implementations of fundamental computer science data structures and algorithms. Built for Python 3.8+ with standard library only.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install raghu
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Quick-Start Examples
|
|
43
|
+
|
|
44
|
+
### Linear Data Structures
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import raghu
|
|
48
|
+
|
|
49
|
+
stack = raghu.Stack([1, 2, 3])
|
|
50
|
+
stack.push(4)
|
|
51
|
+
top_item = stack.pop()
|
|
52
|
+
|
|
53
|
+
queue = raghu.Queue()
|
|
54
|
+
queue.enqueue("task_a")
|
|
55
|
+
queue.enqueue("task_b")
|
|
56
|
+
first_task = queue.dequeue()
|
|
57
|
+
|
|
58
|
+
deque = raghu.Deque([10, 20])
|
|
59
|
+
deque.append_left(5)
|
|
60
|
+
deque.append_right(30)
|
|
61
|
+
left_item = deque.pop_left()
|
|
62
|
+
|
|
63
|
+
sll = raghu.SinglyLinkedList([1, 2, 3])
|
|
64
|
+
sll.reverse()
|
|
65
|
+
|
|
66
|
+
dll = raghu.DoublyLinkedList([10, 30])
|
|
67
|
+
dll.insert(1, 20)
|
|
68
|
+
forward_values = dll.traverse_forward()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Searching and Sorting
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import raghu
|
|
75
|
+
|
|
76
|
+
numbers = [9, 3, 7, 1, 5, 2, 8]
|
|
77
|
+
|
|
78
|
+
index = raghu.binary_search(sorted(numbers), 7)
|
|
79
|
+
|
|
80
|
+
sorted_asc = raghu.merge_sort(numbers)
|
|
81
|
+
sorted_desc = raghu.quick_sort(numbers, key=lambda x: -x)
|
|
82
|
+
sorted_heap = raghu.heap_sort(numbers)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Trees and Heaps
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import raghu
|
|
89
|
+
|
|
90
|
+
bst = raghu.BST([5, 3, 8, 1, 4, 7, 9])
|
|
91
|
+
bst.insert(6)
|
|
92
|
+
bst.delete(3)
|
|
93
|
+
smallest = bst.find_min()
|
|
94
|
+
largest = bst.find_max()
|
|
95
|
+
inorder_elements = bst.inorder()
|
|
96
|
+
|
|
97
|
+
min_heap = raghu.MinHeap.heapify([5, 1, 8, 3, 2])
|
|
98
|
+
min_val = min_heap.pop()
|
|
99
|
+
|
|
100
|
+
trie = raghu.Trie(["apple", "application", "aptitude"])
|
|
101
|
+
is_present = trie.search("apple")
|
|
102
|
+
has_prefix = trie.starts_with("app")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Graphs and Disjoint Sets
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
import raghu
|
|
109
|
+
|
|
110
|
+
g = raghu.Graph(directed=True)
|
|
111
|
+
g.add_edge("A", "B", weight=2.0)
|
|
112
|
+
g.add_edge("B", "C", weight=3.0)
|
|
113
|
+
g.add_edge("A", "C", weight=6.0)
|
|
114
|
+
|
|
115
|
+
bfs_order = g.bfs("A")
|
|
116
|
+
distances, predecessors = g.dijkstra("A")
|
|
117
|
+
path = g.shortest_path("A", "C")
|
|
118
|
+
|
|
119
|
+
dag = raghu.Graph(directed=True)
|
|
120
|
+
dag.add_edge("task1", "task2")
|
|
121
|
+
dag.add_edge("task2", "task3")
|
|
122
|
+
topo_order = dag.topological_sort()
|
|
123
|
+
|
|
124
|
+
uf = raghu.UnionFind([1, 2, 3, 4, 5])
|
|
125
|
+
uf.union(1, 2)
|
|
126
|
+
uf.union(2, 3)
|
|
127
|
+
are_connected = uf.connected(1, 3)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Custom Containers
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import raghu
|
|
134
|
+
|
|
135
|
+
hmap = raghu.HashMap()
|
|
136
|
+
hmap["user_id"] = 101
|
|
137
|
+
hmap["role"] = "admin"
|
|
138
|
+
user = hmap.get("user_id")
|
|
139
|
+
|
|
140
|
+
lru = raghu.LRUCache(capacity=2)
|
|
141
|
+
lru.put("a", 1)
|
|
142
|
+
lru.put("b", 2)
|
|
143
|
+
val_a = lru.get("a")
|
|
144
|
+
lru.put("c", 3)
|
|
145
|
+
assert "b" not in lru
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Complexity Reference
|
|
151
|
+
|
|
152
|
+
| Module | Entity | Kind | Time Complexity (Average) | Time Complexity (Worst) | Space Complexity |
|
|
153
|
+
| :--- | :--- | :--- | :--- | :--- | :--- |
|
|
154
|
+
| `linear` | `Stack` | Class | Push/Pop/Peek: $O(1)$ | Push/Pop/Peek: $O(1)$ | $O(n)$ |
|
|
155
|
+
| `linear` | `Queue` | Class | Enqueue/Dequeue/Front: $O(1)$ | Enqueue/Dequeue/Front: $O(1)$ | $O(n)$ |
|
|
156
|
+
| `linear` | `Deque` | Class | Append/Pop Left/Right: $O(1)$ | Append/Pop Left/Right: $O(1)$ | $O(n)$ |
|
|
157
|
+
| `linear` | `SinglyLinkedList` | Class | Insert Head/Tail: $O(1)$, Delete/Search: $O(n)$ | Insert Head/Tail: $O(1)$, Delete/Search: $O(n)$ | $O(n)$ |
|
|
158
|
+
| `linear` | `DoublyLinkedList` | Class | Insert Head/Tail: $O(1)$, Index Insert/Delete: $O(n)$ | Insert Head/Tail: $O(1)$, Index Insert/Delete: $O(n)$ | $O(n)$ |
|
|
159
|
+
| `searching_sorting` | `linear_search` | Function | $O(n)$ | $O(n)$ | $O(1)$ |
|
|
160
|
+
| `searching_sorting` | `binary_search` | Function | $O(\log n)$ | $O(\log n)$ | $O(1)$ iterative, $O(\log n)$ recursive |
|
|
161
|
+
| `searching_sorting` | `bubble_sort` | Function | $O(n^2)$ | $O(n^2)$ ($O(n)$ best) | $O(n)$ |
|
|
162
|
+
| `searching_sorting` | `selection_sort` | Function | $O(n^2)$ | $O(n^2)$ | $O(n)$ |
|
|
163
|
+
| `searching_sorting` | `insertion_sort` | Function | $O(n^2)$ | $O(n^2)$ ($O(n)$ best) | $O(n)$ |
|
|
164
|
+
| `searching_sorting` | `merge_sort` | Function | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ |
|
|
165
|
+
| `searching_sorting` | `quick_sort` | Function | $O(n \log n)$ | $O(n^2)$ | $O(n)$ copy + $O(\log n)$ stack |
|
|
166
|
+
| `searching_sorting` | `heap_sort` | Function | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ |
|
|
167
|
+
| `trees` | `BinaryTreeNode` | Class | $O(1)$ | $O(1)$ | $O(1)$ |
|
|
168
|
+
| `trees` | `BinaryTree` | Class | Traversals/Height/Size: $O(n)$ | Traversals/Height/Size: $O(n)$ | $O(n)$ |
|
|
169
|
+
| `trees` | `BST` | Class | Insert/Search/Delete: $O(\log n)$ | Insert/Search/Delete: $O(n)$ | $O(n)$ |
|
|
170
|
+
| `trees` | `MinHeap` | Class | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | $O(n)$ |
|
|
171
|
+
| `trees` | `MaxHeap` | Class | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | $O(n)$ |
|
|
172
|
+
| `trees` | `Trie` | Class | Insert/Search/Prefix: $O(m)$ | Insert/Search/Prefix: $O(m)$ | $O(N)$ characters |
|
|
173
|
+
| `graphs` | `Graph` | Class | Add/Has Vertex/Edge: $O(1)$ | Add/Has Vertex/Edge: $O(1)$ | $O(V + E)$ |
|
|
174
|
+
| `graphs` | `UnionFind` | Class | Find/Union/Connected: $O(\alpha(n))$ | Find/Union/Connected: $O(\alpha(n))$ | $O(n)$ |
|
|
175
|
+
| `graphs` | `bfs` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
176
|
+
| `graphs` | `dfs` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
177
|
+
| `graphs` | `has_cycle` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
178
|
+
| `graphs` | `topological_sort` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
179
|
+
| `graphs` | `dijkstra` | Function | $O((V + E) \log V)$ | $O((V + E) \log V)$ | $O(V)$ |
|
|
180
|
+
| `graphs` | `shortest_path` | Function | $O((V + E) \log V)$ | $O((V + E) \log V)$ | $O(V)$ |
|
|
181
|
+
| `containers` | `HashMap` | Class | Put/Get/Remove: $O(1)$ | Put/Get/Remove: $O(n)$ | $O(n)$ |
|
|
182
|
+
| `containers` | `LRUCache` | Class | Get/Put: $O(1)$ | Get/Put: $O(1)$ | $O(\text{capacity})$ |
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Contributing
|
|
187
|
+
|
|
188
|
+
Contributions are welcome. Please ensure that all contributions conform to project guidelines:
|
|
189
|
+
- Python 3.8+ compatible, standard library only at runtime.
|
|
190
|
+
- Full type annotations conforming to `mypy --strict`.
|
|
191
|
+
- Formatted and linted via `ruff`.
|
|
192
|
+
- All tests passing under `pytest`.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
raghu-1.0.0rc1/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# raghu
|
|
2
|
+
|
|
3
|
+
Clean, type-safe OOP data structures and standalone algorithms in pure Python. Zero runtime dependencies.
|
|
4
|
+
|
|
5
|
+
`raghu` provides reliable, well-tested implementations of fundamental computer science data structures and algorithms. Built for Python 3.8+ with standard library only.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install raghu
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Quick-Start Examples
|
|
18
|
+
|
|
19
|
+
### Linear Data Structures
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import raghu
|
|
23
|
+
|
|
24
|
+
stack = raghu.Stack([1, 2, 3])
|
|
25
|
+
stack.push(4)
|
|
26
|
+
top_item = stack.pop()
|
|
27
|
+
|
|
28
|
+
queue = raghu.Queue()
|
|
29
|
+
queue.enqueue("task_a")
|
|
30
|
+
queue.enqueue("task_b")
|
|
31
|
+
first_task = queue.dequeue()
|
|
32
|
+
|
|
33
|
+
deque = raghu.Deque([10, 20])
|
|
34
|
+
deque.append_left(5)
|
|
35
|
+
deque.append_right(30)
|
|
36
|
+
left_item = deque.pop_left()
|
|
37
|
+
|
|
38
|
+
sll = raghu.SinglyLinkedList([1, 2, 3])
|
|
39
|
+
sll.reverse()
|
|
40
|
+
|
|
41
|
+
dll = raghu.DoublyLinkedList([10, 30])
|
|
42
|
+
dll.insert(1, 20)
|
|
43
|
+
forward_values = dll.traverse_forward()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Searching and Sorting
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import raghu
|
|
50
|
+
|
|
51
|
+
numbers = [9, 3, 7, 1, 5, 2, 8]
|
|
52
|
+
|
|
53
|
+
index = raghu.binary_search(sorted(numbers), 7)
|
|
54
|
+
|
|
55
|
+
sorted_asc = raghu.merge_sort(numbers)
|
|
56
|
+
sorted_desc = raghu.quick_sort(numbers, key=lambda x: -x)
|
|
57
|
+
sorted_heap = raghu.heap_sort(numbers)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Trees and Heaps
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import raghu
|
|
64
|
+
|
|
65
|
+
bst = raghu.BST([5, 3, 8, 1, 4, 7, 9])
|
|
66
|
+
bst.insert(6)
|
|
67
|
+
bst.delete(3)
|
|
68
|
+
smallest = bst.find_min()
|
|
69
|
+
largest = bst.find_max()
|
|
70
|
+
inorder_elements = bst.inorder()
|
|
71
|
+
|
|
72
|
+
min_heap = raghu.MinHeap.heapify([5, 1, 8, 3, 2])
|
|
73
|
+
min_val = min_heap.pop()
|
|
74
|
+
|
|
75
|
+
trie = raghu.Trie(["apple", "application", "aptitude"])
|
|
76
|
+
is_present = trie.search("apple")
|
|
77
|
+
has_prefix = trie.starts_with("app")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Graphs and Disjoint Sets
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import raghu
|
|
84
|
+
|
|
85
|
+
g = raghu.Graph(directed=True)
|
|
86
|
+
g.add_edge("A", "B", weight=2.0)
|
|
87
|
+
g.add_edge("B", "C", weight=3.0)
|
|
88
|
+
g.add_edge("A", "C", weight=6.0)
|
|
89
|
+
|
|
90
|
+
bfs_order = g.bfs("A")
|
|
91
|
+
distances, predecessors = g.dijkstra("A")
|
|
92
|
+
path = g.shortest_path("A", "C")
|
|
93
|
+
|
|
94
|
+
dag = raghu.Graph(directed=True)
|
|
95
|
+
dag.add_edge("task1", "task2")
|
|
96
|
+
dag.add_edge("task2", "task3")
|
|
97
|
+
topo_order = dag.topological_sort()
|
|
98
|
+
|
|
99
|
+
uf = raghu.UnionFind([1, 2, 3, 4, 5])
|
|
100
|
+
uf.union(1, 2)
|
|
101
|
+
uf.union(2, 3)
|
|
102
|
+
are_connected = uf.connected(1, 3)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Custom Containers
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
import raghu
|
|
109
|
+
|
|
110
|
+
hmap = raghu.HashMap()
|
|
111
|
+
hmap["user_id"] = 101
|
|
112
|
+
hmap["role"] = "admin"
|
|
113
|
+
user = hmap.get("user_id")
|
|
114
|
+
|
|
115
|
+
lru = raghu.LRUCache(capacity=2)
|
|
116
|
+
lru.put("a", 1)
|
|
117
|
+
lru.put("b", 2)
|
|
118
|
+
val_a = lru.get("a")
|
|
119
|
+
lru.put("c", 3)
|
|
120
|
+
assert "b" not in lru
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Complexity Reference
|
|
126
|
+
|
|
127
|
+
| Module | Entity | Kind | Time Complexity (Average) | Time Complexity (Worst) | Space Complexity |
|
|
128
|
+
| :--- | :--- | :--- | :--- | :--- | :--- |
|
|
129
|
+
| `linear` | `Stack` | Class | Push/Pop/Peek: $O(1)$ | Push/Pop/Peek: $O(1)$ | $O(n)$ |
|
|
130
|
+
| `linear` | `Queue` | Class | Enqueue/Dequeue/Front: $O(1)$ | Enqueue/Dequeue/Front: $O(1)$ | $O(n)$ |
|
|
131
|
+
| `linear` | `Deque` | Class | Append/Pop Left/Right: $O(1)$ | Append/Pop Left/Right: $O(1)$ | $O(n)$ |
|
|
132
|
+
| `linear` | `SinglyLinkedList` | Class | Insert Head/Tail: $O(1)$, Delete/Search: $O(n)$ | Insert Head/Tail: $O(1)$, Delete/Search: $O(n)$ | $O(n)$ |
|
|
133
|
+
| `linear` | `DoublyLinkedList` | Class | Insert Head/Tail: $O(1)$, Index Insert/Delete: $O(n)$ | Insert Head/Tail: $O(1)$, Index Insert/Delete: $O(n)$ | $O(n)$ |
|
|
134
|
+
| `searching_sorting` | `linear_search` | Function | $O(n)$ | $O(n)$ | $O(1)$ |
|
|
135
|
+
| `searching_sorting` | `binary_search` | Function | $O(\log n)$ | $O(\log n)$ | $O(1)$ iterative, $O(\log n)$ recursive |
|
|
136
|
+
| `searching_sorting` | `bubble_sort` | Function | $O(n^2)$ | $O(n^2)$ ($O(n)$ best) | $O(n)$ |
|
|
137
|
+
| `searching_sorting` | `selection_sort` | Function | $O(n^2)$ | $O(n^2)$ | $O(n)$ |
|
|
138
|
+
| `searching_sorting` | `insertion_sort` | Function | $O(n^2)$ | $O(n^2)$ ($O(n)$ best) | $O(n)$ |
|
|
139
|
+
| `searching_sorting` | `merge_sort` | Function | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ |
|
|
140
|
+
| `searching_sorting` | `quick_sort` | Function | $O(n \log n)$ | $O(n^2)$ | $O(n)$ copy + $O(\log n)$ stack |
|
|
141
|
+
| `searching_sorting` | `heap_sort` | Function | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ |
|
|
142
|
+
| `trees` | `BinaryTreeNode` | Class | $O(1)$ | $O(1)$ | $O(1)$ |
|
|
143
|
+
| `trees` | `BinaryTree` | Class | Traversals/Height/Size: $O(n)$ | Traversals/Height/Size: $O(n)$ | $O(n)$ |
|
|
144
|
+
| `trees` | `BST` | Class | Insert/Search/Delete: $O(\log n)$ | Insert/Search/Delete: $O(n)$ | $O(n)$ |
|
|
145
|
+
| `trees` | `MinHeap` | Class | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | $O(n)$ |
|
|
146
|
+
| `trees` | `MaxHeap` | Class | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | Push/Pop: $O(\log n)$, Heapify: $O(n)$, Peek: $O(1)$ | $O(n)$ |
|
|
147
|
+
| `trees` | `Trie` | Class | Insert/Search/Prefix: $O(m)$ | Insert/Search/Prefix: $O(m)$ | $O(N)$ characters |
|
|
148
|
+
| `graphs` | `Graph` | Class | Add/Has Vertex/Edge: $O(1)$ | Add/Has Vertex/Edge: $O(1)$ | $O(V + E)$ |
|
|
149
|
+
| `graphs` | `UnionFind` | Class | Find/Union/Connected: $O(\alpha(n))$ | Find/Union/Connected: $O(\alpha(n))$ | $O(n)$ |
|
|
150
|
+
| `graphs` | `bfs` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
151
|
+
| `graphs` | `dfs` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
152
|
+
| `graphs` | `has_cycle` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
153
|
+
| `graphs` | `topological_sort` | Function | $O(V + E)$ | $O(V + E)$ | $O(V)$ |
|
|
154
|
+
| `graphs` | `dijkstra` | Function | $O((V + E) \log V)$ | $O((V + E) \log V)$ | $O(V)$ |
|
|
155
|
+
| `graphs` | `shortest_path` | Function | $O((V + E) \log V)$ | $O((V + E) \log V)$ | $O(V)$ |
|
|
156
|
+
| `containers` | `HashMap` | Class | Put/Get/Remove: $O(1)$ | Put/Get/Remove: $O(n)$ | $O(n)$ |
|
|
157
|
+
| `containers` | `LRUCache` | Class | Get/Put: $O(1)$ | Get/Put: $O(1)$ | $O(\text{capacity})$ |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
Contributions are welcome. Please ensure that all contributions conform to project guidelines:
|
|
164
|
+
- Python 3.8+ compatible, standard library only at runtime.
|
|
165
|
+
- Full type annotations conforming to `mypy --strict`.
|
|
166
|
+
- Formatted and linted via `ruff`.
|
|
167
|
+
- All tests passing under `pytest`.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "raghu"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Clean OOP data structures and standalone algorithms in pure Python, with zero dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["data-structures", "algorithms", "dsa", "sorting", "searching", "education"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Intended Audience :: Education",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.8",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dependencies = []
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest>=7"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["raghu"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
raghu = ["py.typed"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.dynamic]
|
|
39
|
+
version = { attr = "raghu.__version__" }
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
line-length = 88
|
|
46
|
+
target-version = "py38"
|
|
47
|
+
|
|
48
|
+
[tool.ruff.lint]
|
|
49
|
+
select = ["E", "F", "W", "I", "RUF"]
|
|
50
|
+
ignore = ["E501"]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from raghu.containers import (
|
|
2
|
+
HashMap,
|
|
3
|
+
LRUCache,
|
|
4
|
+
)
|
|
5
|
+
from raghu.graphs import (
|
|
6
|
+
Graph,
|
|
7
|
+
UnionFind,
|
|
8
|
+
bfs,
|
|
9
|
+
dfs,
|
|
10
|
+
dijkstra,
|
|
11
|
+
has_cycle,
|
|
12
|
+
shortest_path,
|
|
13
|
+
topological_sort,
|
|
14
|
+
)
|
|
15
|
+
from raghu.linear import (
|
|
16
|
+
Deque,
|
|
17
|
+
DoublyLinkedList,
|
|
18
|
+
Queue,
|
|
19
|
+
SinglyLinkedList,
|
|
20
|
+
Stack,
|
|
21
|
+
)
|
|
22
|
+
from raghu.searching_sorting import (
|
|
23
|
+
binary_search,
|
|
24
|
+
bubble_sort,
|
|
25
|
+
heap_sort,
|
|
26
|
+
insertion_sort,
|
|
27
|
+
linear_search,
|
|
28
|
+
merge_sort,
|
|
29
|
+
quick_sort,
|
|
30
|
+
selection_sort,
|
|
31
|
+
)
|
|
32
|
+
from raghu.trees import (
|
|
33
|
+
BST,
|
|
34
|
+
BinaryTree,
|
|
35
|
+
BinaryTreeNode,
|
|
36
|
+
MaxHeap,
|
|
37
|
+
MinHeap,
|
|
38
|
+
Trie,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
__version__ = "1.0.0rc1"
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"BST",
|
|
45
|
+
"BinaryTree",
|
|
46
|
+
"BinaryTreeNode",
|
|
47
|
+
"Deque",
|
|
48
|
+
"DoublyLinkedList",
|
|
49
|
+
"Graph",
|
|
50
|
+
"HashMap",
|
|
51
|
+
"LRUCache",
|
|
52
|
+
"MaxHeap",
|
|
53
|
+
"MinHeap",
|
|
54
|
+
"Queue",
|
|
55
|
+
"SinglyLinkedList",
|
|
56
|
+
"Stack",
|
|
57
|
+
"Trie",
|
|
58
|
+
"UnionFind",
|
|
59
|
+
"__version__",
|
|
60
|
+
"bfs",
|
|
61
|
+
"binary_search",
|
|
62
|
+
"bubble_sort",
|
|
63
|
+
"dfs",
|
|
64
|
+
"dijkstra",
|
|
65
|
+
"has_cycle",
|
|
66
|
+
"heap_sort",
|
|
67
|
+
"insertion_sort",
|
|
68
|
+
"linear_search",
|
|
69
|
+
"merge_sort",
|
|
70
|
+
"quick_sort",
|
|
71
|
+
"selection_sort",
|
|
72
|
+
"shortest_path",
|
|
73
|
+
"topological_sort",
|
|
74
|
+
]
|