data-structure-typed 1.12.11 → 1.15.0
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.
- package/README.md +278 -179
- package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +72 -18
- package/dist/data-structures/binary-tree/binary-tree.js +139 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +70 -2
- package/dist/data-structures/binary-tree/segment-tree.js +86 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +45 -5
- package/dist/data-structures/graph/abstract-graph.js +59 -11
- package/dist/data-structures/graph/directed-graph.d.ts +26 -4
- package/dist/data-structures/graph/directed-graph.js +38 -39
- package/dist/data-structures/graph/undirected-graph.d.ts +23 -0
- package/dist/data-structures/graph/undirected-graph.js +41 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-map.js +21 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-set.js +21 -2
- package/dist/data-structures/heap/heap.d.ts +25 -6
- package/dist/data-structures/heap/heap.js +46 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +32 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +75 -8
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +267 -330
- package/dist/data-structures/linked-list/singly-linked-list.js +263 -275
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +14 -5
- package/dist/data-structures/priority-queue/priority-queue.js +20 -4
- package/dist/data-structures/queue/deque.d.ts +30 -16
- package/dist/data-structures/queue/deque.js +62 -12
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/data-structures/types/abstract-graph.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +2 -2
- package/src/data-structures/binary-tree/aa-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +84 -14
- package/src/data-structures/binary-tree/segment-tree.ts +45 -13
- package/src/data-structures/graph/abstract-graph.ts +58 -15
- package/src/data-structures/graph/directed-graph.ts +14 -5
- package/src/data-structures/graph/undirected-graph.ts +23 -6
- package/src/data-structures/hash/coordinate-map.ts +13 -1
- package/src/data-structures/hash/coordinate-set.ts +13 -1
- package/src/data-structures/heap/heap.ts +31 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
- package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
- package/src/data-structures/priority-queue/priority-queue.ts +15 -2
- package/src/data-structures/queue/deque.ts +38 -8
- package/src/data-structures/types/abstract-graph.ts +3 -3
- package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# data-structure-typed
|
|
2
1
|
|
|
3
2
|
Javascript Data Structure, TypeScript Data Structure Library
|
|
4
3
|
|
|
@@ -15,15 +14,22 @@ yarn add data-structure-typed
|
|
|
15
14
|
```bash
|
|
16
15
|
npm install data-structure-typed
|
|
17
16
|
```
|
|
18
|
-
## Online examples
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
## Live Examples
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
[//]: # ([Live Examples](https://data-structure-typed-examples.vercel.app))
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
<a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
|
|
25
23
|
|
|
26
|
-
##
|
|
24
|
+
## Data Structures
|
|
25
|
+
|
|
26
|
+
Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a
|
|
27
|
+
wide range of data structures:
|
|
28
|
+
Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed
|
|
29
|
+
Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack,
|
|
30
|
+
Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
|
|
31
|
+
|
|
32
|
+
## API docs
|
|
27
33
|
|
|
28
34
|
[//]: # ([api docs](https://data-structure-typed-docs.vercel.app/))
|
|
29
35
|
|
|
@@ -37,14 +43,16 @@ npm install data-structure-typed
|
|
|
37
43
|
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/LoopType.html"><span>Loop<wbr/>Type</span></a></li>)
|
|
38
44
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></li>
|
|
39
45
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html"><span>AVLTree<wbr/>Node</span></a></li>
|
|
40
|
-
|
|
46
|
+
|
|
47
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AaTree.html"><span>Aa<wbr/>Tree</span></a></li>)
|
|
41
48
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html"><span>Abstract<wbr/>Edge</span></a></li>
|
|
42
49
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>Abstract<wbr/>Graph</span></a></li>
|
|
43
50
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html"><span>Abstract<wbr/>Vertex</span></a></li>
|
|
44
51
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>Array<wbr/>Deque</span></a></li>
|
|
45
52
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></li>
|
|
46
53
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html"><span>BSTNode</span></a></li>
|
|
47
|
-
|
|
54
|
+
|
|
55
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BTree.html"><span>BTree</span></a></li>)
|
|
48
56
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>Binary<wbr/>Indexed<wbr/>Tree</span></a></li>
|
|
49
57
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary<wbr/>Tree</span></a></li>
|
|
50
58
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html"><span>Binary<wbr/>Tree<wbr/>Node</span></a></li>
|
|
@@ -68,200 +76,292 @@ npm install data-structure-typed
|
|
|
68
76
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>Object<wbr/>Deque</span></a></li>
|
|
69
77
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>Priority<wbr/>Queue</span></a></li>
|
|
70
78
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></li>
|
|
71
|
-
|
|
79
|
+
|
|
80
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/RBTree.html"><span>RBTree</span></a></li>)
|
|
72
81
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>Segment<wbr/>Tree</span></a></li>
|
|
73
82
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html"><span>Segment<wbr/>Tree<wbr/>Node</span></a></li>
|
|
74
83
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>Singly<wbr/>Linked<wbr/>List</span></a></li>
|
|
75
84
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html"><span>Singly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
|
|
76
|
-
|
|
85
|
+
|
|
86
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SplayTree.html"><span>Splay<wbr/>Tree</span></a></li>)
|
|
77
87
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></li>
|
|
78
88
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>Tree<wbr/>Multi<wbr/>Set</span></a></li>
|
|
79
89
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></li>
|
|
80
90
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html"><span>Trie<wbr/>Node</span></a></li>
|
|
81
|
-
|
|
91
|
+
|
|
92
|
+
[//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/TwoThreeTree.html"><span>Two<wbr/>Three<wbr/>Tree</span></a></li>)
|
|
82
93
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html"><span>Undirected<wbr/>Edge</span></a></li>
|
|
83
94
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>Undirected<wbr/>Graph</span></a></li>
|
|
84
95
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html"><span>Undirected<wbr/>Vertex</span></a></li>
|
|
85
96
|
<li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html"><span>Vector2D</span></a></li></ul></nav>
|
|
86
97
|
|
|
87
|
-
|
|
98
|
+
[//]: # ([Examples Repository](https://github.com/zrwusa/data-structure-typed-examples))
|
|
99
|
+
|
|
100
|
+
<a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Complexities
|
|
104
|
+
|
|
105
|
+
### performance of Big O
|
|
88
106
|
|
|
89
|
-
Meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures:
|
|
90
|
-
Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
|
|
91
107
|
<table>
|
|
92
108
|
<thead>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
<tr>
|
|
110
|
+
<th>Big O Notation</th>
|
|
111
|
+
<th>Type</th>
|
|
112
|
+
<th>Computations for 10 elements</th>
|
|
113
|
+
<th>Computations for 100 elements</th>
|
|
114
|
+
<th>Computations for 1000 elements</th>
|
|
115
|
+
</tr>
|
|
99
116
|
</thead>
|
|
100
|
-
|
|
101
117
|
<tbody>
|
|
102
118
|
<tr>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
<td></td>
|
|
152
|
-
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, removeAllEdges, incomingEdgesOf, outgoingEdgesOf, degreeOf, inDegreeOf, outDegreeOf, edgesOf, getEdgeSrc, getEdgeDest, getDestinations, edgeSet, getNeighbors, getEndsOfEdge</td>
|
|
153
|
-
<td>All the features inherited from Graph, topologicalSort</td>
|
|
154
|
-
</tr>
|
|
155
|
-
<tr>
|
|
156
|
-
<td>Undirected Graph</td>
|
|
157
|
-
<td></td>
|
|
158
|
-
<td>All the features inherited from Graph, getEdge, addEdge, removeEdgeBetween, removeEdge, degreeOf, edgesOf, edgeSet, getEdgesOf, getNeighbors, getEndsOfEdge</td>
|
|
159
|
-
<td>All the features inherited from Graph</td>
|
|
160
|
-
</tr>
|
|
161
|
-
<tr>
|
|
162
|
-
<td>Singly Linked List</td>
|
|
163
|
-
<td></td>
|
|
164
|
-
<td>length, head, tail, size, get, getNode, findNodeIndex, findNode, find, findIndex, append, push, prepend, insertAt, removeNode, removeAt, insertBefore, sort, insertAfter, shift, pop, merge, clear, slice, reverse, forEach, map, filter, reduce, toArray, toString</td>
|
|
165
|
-
<td></td>
|
|
166
|
-
|
|
167
|
-
</tr>
|
|
168
|
-
<tr>
|
|
169
|
-
<td>Hash</td>
|
|
170
|
-
<td>CoordinateSet, CoordinateMap</td>
|
|
171
|
-
<td></td>
|
|
172
|
-
<td></td>
|
|
173
|
-
</tr>
|
|
174
|
-
<tr>
|
|
175
|
-
<td>CoordinateSet</td>
|
|
176
|
-
<td></td>
|
|
177
|
-
<td>has, set, get, delete</td>
|
|
178
|
-
<td></td>
|
|
179
|
-
</tr>
|
|
180
|
-
<tr>
|
|
181
|
-
<td>CoordinateMap</td>
|
|
182
|
-
<td></td>
|
|
183
|
-
<td>has, add, delete</td>
|
|
184
|
-
<td></td>
|
|
185
|
-
</tr>
|
|
186
|
-
<tr>
|
|
187
|
-
<td>Heap</td>
|
|
188
|
-
<td></td>
|
|
189
|
-
<td></td>
|
|
190
|
-
</tr>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<tr>
|
|
194
|
-
<td>Doubly Linked List</td>
|
|
195
|
-
<td></td>
|
|
196
|
-
<td>size, offerFirst, offerLast, peekFirst, peekLast, pollFirst, pollLast, get, isEmpty, insert, remove, </td>
|
|
197
|
-
<td></td>
|
|
198
|
-
</tr>
|
|
199
|
-
|
|
200
|
-
[//]: # ( <tr>)
|
|
201
|
-
|
|
202
|
-
[//]: # ( <td>Matrix</td>)
|
|
203
|
-
|
|
204
|
-
[//]: # ( <td></td>)
|
|
205
|
-
|
|
206
|
-
[//]: # ( <td></td>)
|
|
207
|
-
|
|
208
|
-
[//]: # ( <td></td>)
|
|
209
|
-
|
|
210
|
-
[//]: # ( </tr>)
|
|
211
|
-
|
|
212
|
-
<tr>
|
|
213
|
-
<td>Priority Queue</td>
|
|
214
|
-
<td>Max Priority Queue, Min Priority Queue</td>
|
|
215
|
-
<td>offer, peek, poll, leaf, isEmpty, clear, toArray, clone</td>
|
|
216
|
-
<td>isValid, sort, DFS</td>
|
|
217
|
-
</tr>
|
|
218
|
-
<tr>
|
|
219
|
-
<td>Max Priority Queue</td>
|
|
220
|
-
<td></td>
|
|
221
|
-
<td>All the features inherited from Priority Queue</td>
|
|
222
|
-
<td>All the features inherited from Priority Queue</td>
|
|
223
|
-
</tr>
|
|
224
|
-
<tr>
|
|
225
|
-
<td>Min Priority Queue</td>
|
|
226
|
-
<td></td>
|
|
227
|
-
<td>All the features inherited from Priority Queue</td>
|
|
228
|
-
<td>All the features inherited from Priority Queue</td>
|
|
229
|
-
</tr>
|
|
230
|
-
<tr>
|
|
231
|
-
<td>Queue</td>
|
|
232
|
-
<td>Queue, Dequeue</td>
|
|
233
|
-
<td>offer, poll, peek, peekLast, size, isEmpty, toArray, clear, clone, Queue.fromArray</td>
|
|
234
|
-
<td></td>
|
|
235
|
-
</tr>
|
|
236
|
-
<tr>
|
|
237
|
-
<td>ObjectDeque</td>
|
|
238
|
-
<td></td>
|
|
239
|
-
<td>size, offerFirst, offerLast, pollFirst, peekFirst, pollLast, peekLast, get, isEmpty</td>
|
|
240
|
-
<td></td>
|
|
241
|
-
</tr>
|
|
242
|
-
<tr>
|
|
243
|
-
<td>ArrayDeque</td>
|
|
244
|
-
<td></td>
|
|
245
|
-
<td>offerLast, pollLast, pollFirst, offerFirst, peekFirst, peekLast, get, set, insert, remove, isEmpty</td>
|
|
246
|
-
<td></td>
|
|
247
|
-
</tr>
|
|
248
|
-
<tr>
|
|
249
|
-
<td>Stack</td>
|
|
250
|
-
<td></td>
|
|
251
|
-
<td>isEmpty, size, peek, push, pop, toArray, clear, clone, Stack.fromArray</td>
|
|
252
|
-
<td></td>
|
|
253
|
-
</tr>
|
|
254
|
-
<tr>
|
|
255
|
-
<td>Trie</td>
|
|
256
|
-
<td></td>
|
|
257
|
-
<td>put, has, remove, isAbsPrefix, isPrefix, getAll</td>
|
|
258
|
-
<td></td>
|
|
259
|
-
</tr>
|
|
119
|
+
<td><strong>O(1)</strong></td>
|
|
120
|
+
<td>Constant</td>
|
|
121
|
+
<td>1</td>
|
|
122
|
+
<td>1</td>
|
|
123
|
+
<td>1</td>
|
|
124
|
+
</tr>
|
|
125
|
+
<tr>
|
|
126
|
+
<td><strong>O(log N)</strong></td>
|
|
127
|
+
<td>Logarithmic</td>
|
|
128
|
+
<td>3</td>
|
|
129
|
+
<td>6</td>
|
|
130
|
+
<td>9</td>
|
|
131
|
+
</tr>
|
|
132
|
+
<tr>
|
|
133
|
+
<td><strong>O(N)</strong></td>
|
|
134
|
+
<td>Linear</td>
|
|
135
|
+
<td>10</td>
|
|
136
|
+
<td>100</td>
|
|
137
|
+
<td>1000</td>
|
|
138
|
+
</tr>
|
|
139
|
+
<tr>
|
|
140
|
+
<td><strong>O(N log N)</strong></td>
|
|
141
|
+
<td>n log(n)</td>
|
|
142
|
+
<td>30</td>
|
|
143
|
+
<td>600</td>
|
|
144
|
+
<td>9000</td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td><strong>O(N^2)</strong></td>
|
|
148
|
+
<td>Quadratic</td>
|
|
149
|
+
<td>100</td>
|
|
150
|
+
<td>10000</td>
|
|
151
|
+
<td>1000000</td>
|
|
152
|
+
</tr>
|
|
153
|
+
<tr>
|
|
154
|
+
<td><strong>O(2^N)</strong></td>
|
|
155
|
+
<td>Exponential</td>
|
|
156
|
+
<td>1024</td>
|
|
157
|
+
<td>1.26e+29</td>
|
|
158
|
+
<td>1.07e+301</td>
|
|
159
|
+
</tr>
|
|
160
|
+
<tr>
|
|
161
|
+
<td><strong>O(N!)</strong></td>
|
|
162
|
+
<td>Factorial</td>
|
|
163
|
+
<td>3628800</td>
|
|
164
|
+
<td>9.3e+157</td>
|
|
165
|
+
<td>4.02e+2567</td>
|
|
166
|
+
</tr>
|
|
260
167
|
</tbody>
|
|
168
|
+
</table>
|
|
169
|
+
|
|
170
|
+
### Data Structure Complexity
|
|
261
171
|
|
|
172
|
+
<table>
|
|
173
|
+
<thead>
|
|
174
|
+
<tr>
|
|
175
|
+
<th>Data Structure</th>
|
|
176
|
+
<th>Access</th>
|
|
177
|
+
<th>Search</th>
|
|
178
|
+
<th>Insertion</th>
|
|
179
|
+
<th>Deletion</th>
|
|
180
|
+
<th>Comments</th>
|
|
181
|
+
</tr>
|
|
182
|
+
</thead>
|
|
183
|
+
<tbody>
|
|
184
|
+
<tr>
|
|
185
|
+
<td><strong>Array</strong></td>
|
|
186
|
+
<td>1</td>
|
|
187
|
+
<td>n</td>
|
|
188
|
+
<td>n</td>
|
|
189
|
+
<td>n</td>
|
|
190
|
+
<td></td>
|
|
191
|
+
</tr>
|
|
192
|
+
<tr>
|
|
193
|
+
<td><strong>Stack</strong></td>
|
|
194
|
+
<td>n</td>
|
|
195
|
+
<td>n</td>
|
|
196
|
+
<td>1</td>
|
|
197
|
+
<td>1</td>
|
|
198
|
+
<td></td>
|
|
199
|
+
</tr>
|
|
200
|
+
<tr>
|
|
201
|
+
<td><strong>Queue</strong></td>
|
|
202
|
+
<td>n</td>
|
|
203
|
+
<td>n</td>
|
|
204
|
+
<td>1</td>
|
|
205
|
+
<td>1</td>
|
|
206
|
+
<td></td>
|
|
207
|
+
</tr>
|
|
208
|
+
<tr>
|
|
209
|
+
<td><strong>Linked List</strong></td>
|
|
210
|
+
<td>n</td>
|
|
211
|
+
<td>n</td>
|
|
212
|
+
<td>1</td>
|
|
213
|
+
<td>n</td>
|
|
214
|
+
<td></td>
|
|
215
|
+
</tr>
|
|
216
|
+
<tr>
|
|
217
|
+
<td><strong>Hash Table</strong></td>
|
|
218
|
+
<td>-</td>
|
|
219
|
+
<td>n</td>
|
|
220
|
+
<td>n</td>
|
|
221
|
+
<td>n</td>
|
|
222
|
+
<td>In case of perfect hash function costs would be O(1)</td>
|
|
223
|
+
</tr>
|
|
224
|
+
<tr>
|
|
225
|
+
<td><strong>Binary Search Tree</strong></td>
|
|
226
|
+
<td>n</td>
|
|
227
|
+
<td>n</td>
|
|
228
|
+
<td>n</td>
|
|
229
|
+
<td>n</td>
|
|
230
|
+
<td>In case of balanced tree costs would be O(log(n))</td>
|
|
231
|
+
</tr>
|
|
232
|
+
<tr>
|
|
233
|
+
<td><strong>B-Tree</strong></td>
|
|
234
|
+
<td>log(n)</td>
|
|
235
|
+
<td>log(n)</td>
|
|
236
|
+
<td>log(n)</td>
|
|
237
|
+
<td>log(n)</td>
|
|
238
|
+
<td></td>
|
|
239
|
+
</tr>
|
|
240
|
+
<tr>
|
|
241
|
+
<td><strong>Red-Black Tree</strong></td>
|
|
242
|
+
<td>log(n)</td>
|
|
243
|
+
<td>log(n)</td>
|
|
244
|
+
<td>log(n)</td>
|
|
245
|
+
<td>log(n)</td>
|
|
246
|
+
<td></td>
|
|
247
|
+
</tr>
|
|
248
|
+
<tr>
|
|
249
|
+
<td><strong>AVL Tree</strong></td>
|
|
250
|
+
<td>log(n)</td>
|
|
251
|
+
<td>log(n)</td>
|
|
252
|
+
<td>log(n)</td>
|
|
253
|
+
<td>log(n)</td>
|
|
254
|
+
<td></td>
|
|
255
|
+
</tr>
|
|
256
|
+
<tr>
|
|
257
|
+
<td><strong>Bloom Filter</strong></td>
|
|
258
|
+
<td>-</td>
|
|
259
|
+
<td>1</td>
|
|
260
|
+
<td>1</td>
|
|
261
|
+
<td>-</td>
|
|
262
|
+
<td>False positives are possible while searching</td>
|
|
263
|
+
</tr>
|
|
264
|
+
</tbody>
|
|
262
265
|
</table>
|
|
263
266
|
|
|
267
|
+
### Sorting Complexity
|
|
264
268
|
|
|
269
|
+
<table>
|
|
270
|
+
<thead>
|
|
271
|
+
<tr>
|
|
272
|
+
<th>Name</th>
|
|
273
|
+
<th>Best</th>
|
|
274
|
+
<th>Average</th>
|
|
275
|
+
<th>Worst</th>
|
|
276
|
+
<th>Memory</th>
|
|
277
|
+
<th>Stable</th>
|
|
278
|
+
<th>Comments</th>
|
|
279
|
+
</tr>
|
|
280
|
+
</thead>
|
|
281
|
+
<tbody>
|
|
282
|
+
<tr>
|
|
283
|
+
<td><strong>Bubble sort</strong></td>
|
|
284
|
+
<td>n</td>
|
|
285
|
+
<td>n<sup>2</sup></td>
|
|
286
|
+
<td>n<sup>2</sup></td>
|
|
287
|
+
<td>1</td>
|
|
288
|
+
<td>Yes</td>
|
|
289
|
+
<td></td>
|
|
290
|
+
</tr>
|
|
291
|
+
<tr>
|
|
292
|
+
<td><strong>Insertion sort</strong></td>
|
|
293
|
+
<td>n</td>
|
|
294
|
+
<td>n<sup>2</sup></td>
|
|
295
|
+
<td>n<sup>2</sup></td>
|
|
296
|
+
<td>1</td>
|
|
297
|
+
<td>Yes</td>
|
|
298
|
+
<td></td>
|
|
299
|
+
</tr>
|
|
300
|
+
<tr>
|
|
301
|
+
<td><strong>Selection sort</strong></td>
|
|
302
|
+
<td>n<sup>2</sup></td>
|
|
303
|
+
<td>n<sup>2</sup></td>
|
|
304
|
+
<td>n<sup>2</sup></td>
|
|
305
|
+
<td>1</td>
|
|
306
|
+
<td>No</td>
|
|
307
|
+
<td></td>
|
|
308
|
+
</tr>
|
|
309
|
+
<tr>
|
|
310
|
+
<td><strong>Heap sort</strong></td>
|
|
311
|
+
<td>n log(n)</td>
|
|
312
|
+
<td>n log(n)</td>
|
|
313
|
+
<td>n log(n)</td>
|
|
314
|
+
<td>1</td>
|
|
315
|
+
<td>No</td>
|
|
316
|
+
<td></td>
|
|
317
|
+
</tr>
|
|
318
|
+
<tr>
|
|
319
|
+
<td><strong>Merge sort</strong></td>
|
|
320
|
+
<td>n log(n)</td>
|
|
321
|
+
<td>n log(n)</td>
|
|
322
|
+
<td>n log(n)</td>
|
|
323
|
+
<td>n</td>
|
|
324
|
+
<td>Yes</td>
|
|
325
|
+
<td></td>
|
|
326
|
+
</tr>
|
|
327
|
+
<tr>
|
|
328
|
+
<td><strong>Quick sort</strong></td>
|
|
329
|
+
<td>n log(n)</td>
|
|
330
|
+
<td>n log(n)</td>
|
|
331
|
+
<td>n<sup>2</sup></td>
|
|
332
|
+
<td>log(n)</td>
|
|
333
|
+
<td>No</td>
|
|
334
|
+
<td>Quicksort is usually done in-place with O(log(n)) stack space</td>
|
|
335
|
+
</tr>
|
|
336
|
+
<tr>
|
|
337
|
+
<td><strong>Shell sort</strong></td>
|
|
338
|
+
<td>n log(n)</td>
|
|
339
|
+
<td>depends on gap sequence</td>
|
|
340
|
+
<td>n (log(n))<sup>2</sup></td>
|
|
341
|
+
<td>1</td>
|
|
342
|
+
<td>No</td>
|
|
343
|
+
<td></td>
|
|
344
|
+
</tr>
|
|
345
|
+
<tr>
|
|
346
|
+
<td><strong>Counting sort</strong></td>
|
|
347
|
+
<td>n + r</td>
|
|
348
|
+
<td>n + r</td>
|
|
349
|
+
<td>n + r</td>
|
|
350
|
+
<td>n + r</td>
|
|
351
|
+
<td>Yes</td>
|
|
352
|
+
<td>r - biggest number in array</td>
|
|
353
|
+
</tr>
|
|
354
|
+
<tr>
|
|
355
|
+
<td><strong>Radix sort</strong></td>
|
|
356
|
+
<td>n * k</td>
|
|
357
|
+
<td>n * k</td>
|
|
358
|
+
<td>n * k</td>
|
|
359
|
+
<td>n + k</td>
|
|
360
|
+
<td>Yes</td>
|
|
361
|
+
<td>k - length of longest key</td>
|
|
362
|
+
</tr>
|
|
363
|
+
</tbody>
|
|
364
|
+
</table>
|
|
265
365
|
|
|
266
366
|
|
|
267
367
|

|
|
@@ -272,7 +372,6 @@ Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Bi
|
|
|
272
372
|
|
|
273
373
|

|
|
274
374
|
|
|
275
|
-
|
|
276
375
|

|
|
277
376
|
|
|
278
377
|

|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import { BST, BSTNode } from './bst';
|
|
6
9
|
import type { AVLTreeDeleted, BinaryTreeNodeId } from '../types';
|
|
7
10
|
export declare class AVLTreeNode<T> extends BSTNode<T> {
|
|
11
|
+
/**
|
|
12
|
+
* The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
|
|
13
|
+
* id, value, and count.
|
|
14
|
+
* @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
|
|
15
|
+
* the current instance.
|
|
16
|
+
*/
|
|
8
17
|
clone(): AVLTreeNode<T>;
|
|
9
18
|
}
|
|
10
19
|
export declare class AVLTree<T> extends BST<T> {
|
|
11
20
|
createNode(id: BinaryTreeNodeId, val: T, count?: number): AVLTreeNode<T>;
|
|
12
21
|
/**
|
|
13
|
-
* The function overrides the
|
|
22
|
+
* The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
14
23
|
* balances the tree.
|
|
15
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to
|
|
24
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
|
|
16
25
|
* update in the AVL tree.
|
|
17
26
|
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
|
|
18
27
|
* `id`. It can be of type `T` (the generic type) or `null`.
|
|
@@ -21,7 +30,7 @@ export declare class AVLTree<T> extends BST<T> {
|
|
|
21
30
|
* to `1`, indicating that the value should be inserted once.
|
|
22
31
|
* @returns The method is returning either an AVLTreeNode<T> object or null.
|
|
23
32
|
*/
|
|
24
|
-
|
|
33
|
+
add(id: BinaryTreeNodeId, val: T | null, count?: number): AVLTreeNode<T> | null;
|
|
25
34
|
/**
|
|
26
35
|
* The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
|
|
27
36
|
* then balances the tree if necessary.
|
|
@@ -28,8 +28,11 @@ var __values = (this && this.__values) || function(o) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* data-structure-typed
|
|
32
|
+
*
|
|
33
|
+
* @author Tyler Zeng
|
|
34
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
35
|
+
* @license MIT License
|
|
33
36
|
*/
|
|
34
37
|
var bst_1 = require("./bst");
|
|
35
38
|
var AVLTreeNode = /** @class */ (function (_super) {
|
|
@@ -37,6 +40,12 @@ var AVLTreeNode = /** @class */ (function (_super) {
|
|
|
37
40
|
function AVLTreeNode() {
|
|
38
41
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
39
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The function overrides the clone method of the AVLTreeNode class to create a new AVLTreeNode object with the same
|
|
45
|
+
* id, value, and count.
|
|
46
|
+
* @returns The method is returning a new instance of the AVLTreeNode class with the same id, val, and count values as
|
|
47
|
+
* the current instance.
|
|
48
|
+
*/
|
|
40
49
|
AVLTreeNode.prototype.clone = function () {
|
|
41
50
|
return new AVLTreeNode(this.id, this.val, this.count);
|
|
42
51
|
};
|
|
@@ -52,9 +61,9 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
52
61
|
return new AVLTreeNode(id, val, count);
|
|
53
62
|
};
|
|
54
63
|
/**
|
|
55
|
-
* The function overrides the
|
|
64
|
+
* The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
56
65
|
* balances the tree.
|
|
57
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to
|
|
66
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
|
|
58
67
|
* update in the AVL tree.
|
|
59
68
|
* @param {T | null} val - The `val` parameter represents the value that you want to assign to the node with the given
|
|
60
69
|
* `id`. It can be of type `T` (the generic type) or `null`.
|
|
@@ -63,8 +72,8 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
63
72
|
* to `1`, indicating that the value should be inserted once.
|
|
64
73
|
* @returns The method is returning either an AVLTreeNode<T> object or null.
|
|
65
74
|
*/
|
|
66
|
-
AVLTree.prototype.
|
|
67
|
-
var inserted = _super.prototype.
|
|
75
|
+
AVLTree.prototype.add = function (id, val, count) {
|
|
76
|
+
var inserted = _super.prototype.add.call(this, id, val, count);
|
|
68
77
|
if (inserted)
|
|
69
78
|
this.balancePath(inserted);
|
|
70
79
|
return inserted;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
export declare class BinaryIndexedTree {
|
|
6
9
|
private readonly _sumTree;
|
|
10
|
+
/**
|
|
11
|
+
* The constructor initializes an array with a specified length and fills it with zeros.
|
|
12
|
+
* @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
|
|
13
|
+
* sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
|
|
14
|
+
* The size of the sum tree array is `n + 1` because
|
|
15
|
+
*/
|
|
7
16
|
constructor(n: number);
|
|
8
17
|
static lowBit(x: number): number;
|
|
9
18
|
/**
|
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BinaryIndexedTree = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* data-structure-typed
|
|
6
|
+
*
|
|
7
|
+
* @author Tyler Zeng
|
|
8
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
9
|
+
* @license MIT License
|
|
7
10
|
*/
|
|
8
11
|
var BinaryIndexedTree = /** @class */ (function () {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor initializes an array with a specified length and fills it with zeros.
|
|
14
|
+
* @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
|
|
15
|
+
* sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
|
|
16
|
+
* The size of the sum tree array is `n + 1` because
|
|
17
|
+
*/
|
|
9
18
|
function BinaryIndexedTree(n) {
|
|
10
19
|
this._sumTree = new Array(n + 1).fill(0);
|
|
11
20
|
}
|