priority-queue-typed 1.19.3
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/.dependency-cruiser.js +449 -0
- package/README.md +700 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/max-priority-queue.d.ts +15 -0
- package/dist/max-priority-queue.js +67 -0
- package/dist/min-priority-queue.d.ts +15 -0
- package/dist/min-priority-queue.js +68 -0
- package/dist/priority-queue.d.ts +180 -0
- package/dist/priority-queue.js +365 -0
- package/jest.config.js +5 -0
- package/package.json +61 -0
- package/tsconfig.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
# What
|
|
2
|
+
|
|
3
|
+
## Brief
|
|
4
|
+
Javascript & TypeScript Data Structure Library.
|
|
5
|
+
|
|
6
|
+
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
|
|
7
|
+
|
|
8
|
+
## Algorithms list only a few out, you can discover more in API docs
|
|
9
|
+
|
|
10
|
+
DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
|
|
11
|
+
|
|
12
|
+
## Code design
|
|
13
|
+
By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
|
|
14
|
+
|
|
15
|
+
# How
|
|
16
|
+
|
|
17
|
+
## install
|
|
18
|
+
### yarn
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add data-structure-typed
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### npm
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install data-structure-typed
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Binary Search Tree (BST) snippet
|
|
31
|
+
|
|
32
|
+
#### TS
|
|
33
|
+
```typescript
|
|
34
|
+
import {BST, BSTNode} from 'data-structure-typed';
|
|
35
|
+
|
|
36
|
+
const bst = new BST();
|
|
37
|
+
bst.add(11);
|
|
38
|
+
bst.add(3);
|
|
39
|
+
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
40
|
+
bst.size === 16; // true
|
|
41
|
+
bst.has(6); // true
|
|
42
|
+
const node6 = bst.get(6);
|
|
43
|
+
bst.getHeight(6) === 2; // true
|
|
44
|
+
bst.getHeight() === 5; // true
|
|
45
|
+
bst.getDepth(6) === 3; // true
|
|
46
|
+
const leftMost = bst.getLeftMost();
|
|
47
|
+
leftMost?.id === 1; // true
|
|
48
|
+
expect(leftMost?.id).toBe(1);
|
|
49
|
+
bst.remove(6);
|
|
50
|
+
bst.get(6); // null
|
|
51
|
+
bst.isAVLBalanced(); // true or false
|
|
52
|
+
const bfsIDs = bst.BFS();
|
|
53
|
+
bfsIDs[0] === 11; // true
|
|
54
|
+
expect(bfsIDs[0]).toBe(11);
|
|
55
|
+
|
|
56
|
+
const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
|
|
57
|
+
objBST.add(11, {id: 11, keyA: 11});
|
|
58
|
+
objBST.add(3, {id: 3, keyA: 3});
|
|
59
|
+
|
|
60
|
+
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
61
|
+
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
62
|
+
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
63
|
+
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
64
|
+
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
65
|
+
|
|
66
|
+
objBST.remove(11);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const avlTree = new AVLTree();
|
|
70
|
+
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
71
|
+
avlTree.isAVLBalanced(); // true
|
|
72
|
+
avlTree.remove(10);
|
|
73
|
+
avlTree.isAVLBalanced(); // true
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
#### JS
|
|
77
|
+
```javascript
|
|
78
|
+
const {BST, BSTNode} = require('data-structure-typed');
|
|
79
|
+
|
|
80
|
+
const bst = new BST();
|
|
81
|
+
bst.add(11);
|
|
82
|
+
bst.add(3);
|
|
83
|
+
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
|
|
84
|
+
bst.size === 16; // true
|
|
85
|
+
bst.has(6); // true
|
|
86
|
+
const node6 = bst.get(6);
|
|
87
|
+
bst.getHeight(6) === 2; // true
|
|
88
|
+
bst.getHeight() === 5; // true
|
|
89
|
+
bst.getDepth(6) === 3; // true
|
|
90
|
+
const leftMost = bst.getLeftMost();
|
|
91
|
+
leftMost?.id === 1; // true
|
|
92
|
+
expect(leftMost?.id).toBe(1);
|
|
93
|
+
bst.remove(6);
|
|
94
|
+
bst.get(6); // null
|
|
95
|
+
bst.isAVLBalanced(); // true or false
|
|
96
|
+
const bfsIDs = bst.BFS();
|
|
97
|
+
bfsIDs[0] === 11; // true
|
|
98
|
+
expect(bfsIDs[0]).toBe(11);
|
|
99
|
+
|
|
100
|
+
const objBST = new BST();
|
|
101
|
+
objBST.add(11, {id: 11, keyA: 11});
|
|
102
|
+
objBST.add(3, {id: 3, keyA: 3});
|
|
103
|
+
|
|
104
|
+
objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
|
|
105
|
+
{id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
|
|
106
|
+
{id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
|
|
107
|
+
{id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
|
|
108
|
+
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
|
|
109
|
+
|
|
110
|
+
objBST.remove(11);
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const avlTree = new AVLTree();
|
|
114
|
+
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
|
|
115
|
+
avlTree.isAVLBalanced(); // true
|
|
116
|
+
avlTree.remove(10);
|
|
117
|
+
avlTree.isAVLBalanced(); // true
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Directed Graph simple snippet
|
|
122
|
+
|
|
123
|
+
#### TS or JS
|
|
124
|
+
```typescript
|
|
125
|
+
import {DirectedGraph} from 'data-structure-typed';
|
|
126
|
+
|
|
127
|
+
const graph = new DirectedGraph();
|
|
128
|
+
|
|
129
|
+
graph.addVertex('A');
|
|
130
|
+
graph.addVertex('B');
|
|
131
|
+
|
|
132
|
+
graph.hasVertex('A'); // true
|
|
133
|
+
graph.hasVertex('B'); // true
|
|
134
|
+
graph.hasVertex('C'); // false
|
|
135
|
+
|
|
136
|
+
graph.addEdge('A', 'B');
|
|
137
|
+
graph.hasEdge('A', 'B'); // true
|
|
138
|
+
graph.hasEdge('B', 'A'); // false
|
|
139
|
+
|
|
140
|
+
graph.removeEdgeSrcToDest('A', 'B');
|
|
141
|
+
graph.hasEdge('A', 'B'); // false
|
|
142
|
+
|
|
143
|
+
graph.addVertex('C');
|
|
144
|
+
|
|
145
|
+
graph.addEdge('A', 'B');
|
|
146
|
+
graph.addEdge('B', 'C');
|
|
147
|
+
|
|
148
|
+
const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Undirected Graph snippet
|
|
152
|
+
|
|
153
|
+
#### TS or JS
|
|
154
|
+
```typescript
|
|
155
|
+
import {UndirectedGraph} from 'data-structure-typed';
|
|
156
|
+
|
|
157
|
+
const graph = new UndirectedGraph();
|
|
158
|
+
graph.addVertex('A');
|
|
159
|
+
graph.addVertex('B');
|
|
160
|
+
graph.addVertex('C');
|
|
161
|
+
graph.addVertex('D');
|
|
162
|
+
graph.removeVertex('C');
|
|
163
|
+
graph.addEdge('A', 'B');
|
|
164
|
+
graph.addEdge('B', 'D');
|
|
165
|
+
|
|
166
|
+
const dijkstraResult = graph.dijkstra('A');
|
|
167
|
+
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+

|
|
171
|
+
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+

|
|
175
|
+
|
|
176
|
+

|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
## API docs & Examples
|
|
180
|
+
|
|
181
|
+
[API Docs](https://data-structure-typed-docs.vercel.app)
|
|
182
|
+
|
|
183
|
+
[Live Examples](https://data-structure-typed-examples.vercel.app)
|
|
184
|
+
|
|
185
|
+
<a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
|
|
186
|
+
|
|
187
|
+
[//]: # ([Examples Repository](https://github.com/zrwusa/data-structure-typed-examples))
|
|
188
|
+
|
|
189
|
+
<a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
|
|
190
|
+
|
|
191
|
+
## Data Structures
|
|
192
|
+
|
|
193
|
+
<table>
|
|
194
|
+
<thead>
|
|
195
|
+
<tr>
|
|
196
|
+
<th>Data Structure</th>
|
|
197
|
+
<th>Unit Test</th>
|
|
198
|
+
<th>Performance Test</th>
|
|
199
|
+
<th>API Documentation</th>
|
|
200
|
+
<th>Implemented</th>
|
|
201
|
+
</tr>
|
|
202
|
+
</thead>
|
|
203
|
+
<tbody>
|
|
204
|
+
<tr>
|
|
205
|
+
<td>Binary Tree</td>
|
|
206
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
|
|
207
|
+
</img></td>
|
|
208
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
|
|
209
|
+
</img></td>
|
|
210
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
|
|
211
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
212
|
+
</tr>
|
|
213
|
+
<tr>
|
|
214
|
+
<td>Binary Search Tree (BST)</td>
|
|
215
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
216
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
217
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></td>
|
|
218
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
219
|
+
</tr>
|
|
220
|
+
<tr>
|
|
221
|
+
<td>AVL Tree</td>
|
|
222
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
223
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
224
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></td>
|
|
225
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
226
|
+
</tr>
|
|
227
|
+
<tr>
|
|
228
|
+
<td>Tree Multiset</td>
|
|
229
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
230
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
231
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiset.html"><span>TreeMultiset</span></a></td>
|
|
232
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
233
|
+
</tr>
|
|
234
|
+
<tr>
|
|
235
|
+
<td>Segment Tree</td>
|
|
236
|
+
<td></td>
|
|
237
|
+
<td></td>
|
|
238
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>SegmentTree</span></a></td>
|
|
239
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
240
|
+
</tr>
|
|
241
|
+
<tr>
|
|
242
|
+
<td>Binary Indexed Tree</td>
|
|
243
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
244
|
+
<td></td>
|
|
245
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>BinaryIndexedTree</span></a></td>
|
|
246
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
247
|
+
</tr>
|
|
248
|
+
<tr>
|
|
249
|
+
<td>Graph</td>
|
|
250
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
251
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
252
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>AbstractGraph</span></a></td>
|
|
253
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
254
|
+
</tr>
|
|
255
|
+
<tr>
|
|
256
|
+
<td>Directed Graph</td>
|
|
257
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
258
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
259
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>DirectedGraph</span></a></td>
|
|
260
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
261
|
+
</tr>
|
|
262
|
+
<tr>
|
|
263
|
+
<td>Undirected Graph</td>
|
|
264
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
265
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
266
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>UndirectedGraph</span></a></td>
|
|
267
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
268
|
+
</tr>
|
|
269
|
+
<tr>
|
|
270
|
+
<td>Linked List</td>
|
|
271
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
272
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
273
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
|
|
274
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
275
|
+
</tr>
|
|
276
|
+
<tr>
|
|
277
|
+
<td>Singly Linked List</td>
|
|
278
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
279
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
280
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
|
|
281
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
282
|
+
</tr>
|
|
283
|
+
<tr>
|
|
284
|
+
<td>Doubly Linked List</td>
|
|
285
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
286
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
287
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>DoublyLinkedList</span></a></td>
|
|
288
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
289
|
+
</tr>
|
|
290
|
+
<tr>
|
|
291
|
+
<td>Queue</td>
|
|
292
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
293
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
294
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></td>
|
|
295
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
296
|
+
</tr>
|
|
297
|
+
<tr>
|
|
298
|
+
<td>Object Deque</td>
|
|
299
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
300
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
301
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>ObjectDeque</span></a></td>
|
|
302
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
303
|
+
</tr>
|
|
304
|
+
<tr>
|
|
305
|
+
<td>Array Deque</td>
|
|
306
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
307
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
308
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>ArrayDeque</span></a></td>
|
|
309
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
310
|
+
</tr>
|
|
311
|
+
<tr>
|
|
312
|
+
<td>Stack</td>
|
|
313
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
314
|
+
<td></td>
|
|
315
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></td>
|
|
316
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
317
|
+
</tr>
|
|
318
|
+
|
|
319
|
+
[//]: # (<tr>)
|
|
320
|
+
|
|
321
|
+
[//]: # (<td>Hash</td>)
|
|
322
|
+
|
|
323
|
+
[//]: # (<td></td>)
|
|
324
|
+
|
|
325
|
+
[//]: # (<td></td>)
|
|
326
|
+
|
|
327
|
+
[//]: # (<td><a href="https://data-structure-typed-docs.vercel.app/classes/HashTable.html"><span>HashTable</span></a></td>)
|
|
328
|
+
|
|
329
|
+
[//]: # (<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>)
|
|
330
|
+
|
|
331
|
+
[//]: # (</tr>)
|
|
332
|
+
<tr>
|
|
333
|
+
<td>Coordinate Set</td>
|
|
334
|
+
<td></td>
|
|
335
|
+
<td></td>
|
|
336
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>CoordinateSet</span></a></td>
|
|
337
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
338
|
+
</tr>
|
|
339
|
+
<tr>
|
|
340
|
+
<td>Coordinate Map</td>
|
|
341
|
+
<td></td>
|
|
342
|
+
<td></td>
|
|
343
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>CoordinateMap</span></a></td>
|
|
344
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
345
|
+
</tr>
|
|
346
|
+
<tr>
|
|
347
|
+
<td>Heap</td>
|
|
348
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
349
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
350
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></td>
|
|
351
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
352
|
+
</tr>
|
|
353
|
+
<tr>
|
|
354
|
+
<td>Priority Queue</td>
|
|
355
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
356
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
357
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>PriorityQueue</span></a></td>
|
|
358
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
359
|
+
</tr>
|
|
360
|
+
<tr>
|
|
361
|
+
<td>Max Priority Queue</td>
|
|
362
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
363
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
364
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>MaxPriorityQueue</span></a></td>
|
|
365
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
366
|
+
</tr>
|
|
367
|
+
<tr>
|
|
368
|
+
<td>Min Priority Queue</td>
|
|
369
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
370
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
371
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>MinPriorityQueue</span></a></td>
|
|
372
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
373
|
+
</tr>
|
|
374
|
+
<tr>
|
|
375
|
+
<td>Trie</td>
|
|
376
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
377
|
+
<td></td>
|
|
378
|
+
<td><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></td>
|
|
379
|
+
<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
|
|
380
|
+
</tr>
|
|
381
|
+
</tbody>
|
|
382
|
+
</table>
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
# Why
|
|
386
|
+
|
|
387
|
+
## Complexities
|
|
388
|
+
|
|
389
|
+
### performance of Big O
|
|
390
|
+
|
|
391
|
+
<table>
|
|
392
|
+
<thead>
|
|
393
|
+
<tr>
|
|
394
|
+
<th>Big O Notation</th>
|
|
395
|
+
<th>Type</th>
|
|
396
|
+
<th>Computations for 10 elements</th>
|
|
397
|
+
<th>Computations for 100 elements</th>
|
|
398
|
+
<th>Computations for 1000 elements</th>
|
|
399
|
+
</tr>
|
|
400
|
+
</thead>
|
|
401
|
+
<tbody>
|
|
402
|
+
<tr>
|
|
403
|
+
<td><strong>O(1)</strong></td>
|
|
404
|
+
<td>Constant</td>
|
|
405
|
+
<td>1</td>
|
|
406
|
+
<td>1</td>
|
|
407
|
+
<td>1</td>
|
|
408
|
+
</tr>
|
|
409
|
+
<tr>
|
|
410
|
+
<td><strong>O(log N)</strong></td>
|
|
411
|
+
<td>Logarithmic</td>
|
|
412
|
+
<td>3</td>
|
|
413
|
+
<td>6</td>
|
|
414
|
+
<td>9</td>
|
|
415
|
+
</tr>
|
|
416
|
+
<tr>
|
|
417
|
+
<td><strong>O(N)</strong></td>
|
|
418
|
+
<td>Linear</td>
|
|
419
|
+
<td>10</td>
|
|
420
|
+
<td>100</td>
|
|
421
|
+
<td>1000</td>
|
|
422
|
+
</tr>
|
|
423
|
+
<tr>
|
|
424
|
+
<td><strong>O(N log N)</strong></td>
|
|
425
|
+
<td>n log(n)</td>
|
|
426
|
+
<td>30</td>
|
|
427
|
+
<td>600</td>
|
|
428
|
+
<td>9000</td>
|
|
429
|
+
</tr>
|
|
430
|
+
<tr>
|
|
431
|
+
<td><strong>O(N^2)</strong></td>
|
|
432
|
+
<td>Quadratic</td>
|
|
433
|
+
<td>100</td>
|
|
434
|
+
<td>10000</td>
|
|
435
|
+
<td>1000000</td>
|
|
436
|
+
</tr>
|
|
437
|
+
<tr>
|
|
438
|
+
<td><strong>O(2^N)</strong></td>
|
|
439
|
+
<td>Exponential</td>
|
|
440
|
+
<td>1024</td>
|
|
441
|
+
<td>1.26e+29</td>
|
|
442
|
+
<td>1.07e+301</td>
|
|
443
|
+
</tr>
|
|
444
|
+
<tr>
|
|
445
|
+
<td><strong>O(N!)</strong></td>
|
|
446
|
+
<td>Factorial</td>
|
|
447
|
+
<td>3628800</td>
|
|
448
|
+
<td>9.3e+157</td>
|
|
449
|
+
<td>4.02e+2567</td>
|
|
450
|
+
</tr>
|
|
451
|
+
</tbody>
|
|
452
|
+
</table>
|
|
453
|
+
|
|
454
|
+
### Data Structure Complexity
|
|
455
|
+
|
|
456
|
+
<table>
|
|
457
|
+
<thead>
|
|
458
|
+
<tr>
|
|
459
|
+
<th>Data Structure</th>
|
|
460
|
+
<th>Access</th>
|
|
461
|
+
<th>Search</th>
|
|
462
|
+
<th>Insertion</th>
|
|
463
|
+
<th>Deletion</th>
|
|
464
|
+
<th>Comments</th>
|
|
465
|
+
</tr>
|
|
466
|
+
</thead>
|
|
467
|
+
<tbody>
|
|
468
|
+
<tr>
|
|
469
|
+
<td><strong>Array</strong></td>
|
|
470
|
+
<td>1</td>
|
|
471
|
+
<td>n</td>
|
|
472
|
+
<td>n</td>
|
|
473
|
+
<td>n</td>
|
|
474
|
+
<td></td>
|
|
475
|
+
</tr>
|
|
476
|
+
<tr>
|
|
477
|
+
<td><strong>Stack</strong></td>
|
|
478
|
+
<td>n</td>
|
|
479
|
+
<td>n</td>
|
|
480
|
+
<td>1</td>
|
|
481
|
+
<td>1</td>
|
|
482
|
+
<td></td>
|
|
483
|
+
</tr>
|
|
484
|
+
<tr>
|
|
485
|
+
<td><strong>Queue</strong></td>
|
|
486
|
+
<td>n</td>
|
|
487
|
+
<td>n</td>
|
|
488
|
+
<td>1</td>
|
|
489
|
+
<td>1</td>
|
|
490
|
+
<td></td>
|
|
491
|
+
</tr>
|
|
492
|
+
<tr>
|
|
493
|
+
<td><strong>Linked List</strong></td>
|
|
494
|
+
<td>n</td>
|
|
495
|
+
<td>n</td>
|
|
496
|
+
<td>1</td>
|
|
497
|
+
<td>n</td>
|
|
498
|
+
<td></td>
|
|
499
|
+
</tr>
|
|
500
|
+
<tr>
|
|
501
|
+
<td><strong>Hash Table</strong></td>
|
|
502
|
+
<td>-</td>
|
|
503
|
+
<td>n</td>
|
|
504
|
+
<td>n</td>
|
|
505
|
+
<td>n</td>
|
|
506
|
+
<td>In case of perfect hash function costs would be O(1)</td>
|
|
507
|
+
</tr>
|
|
508
|
+
<tr>
|
|
509
|
+
<td><strong>Binary Search Tree</strong></td>
|
|
510
|
+
<td>n</td>
|
|
511
|
+
<td>n</td>
|
|
512
|
+
<td>n</td>
|
|
513
|
+
<td>n</td>
|
|
514
|
+
<td>In case of balanced tree costs would be O(log(n))</td>
|
|
515
|
+
</tr>
|
|
516
|
+
<tr>
|
|
517
|
+
<td><strong>B-Tree</strong></td>
|
|
518
|
+
<td>log(n)</td>
|
|
519
|
+
<td>log(n)</td>
|
|
520
|
+
<td>log(n)</td>
|
|
521
|
+
<td>log(n)</td>
|
|
522
|
+
<td></td>
|
|
523
|
+
</tr>
|
|
524
|
+
<tr>
|
|
525
|
+
<td><strong>Red-Black Tree</strong></td>
|
|
526
|
+
<td>log(n)</td>
|
|
527
|
+
<td>log(n)</td>
|
|
528
|
+
<td>log(n)</td>
|
|
529
|
+
<td>log(n)</td>
|
|
530
|
+
<td></td>
|
|
531
|
+
</tr>
|
|
532
|
+
<tr>
|
|
533
|
+
<td><strong>AVL Tree</strong></td>
|
|
534
|
+
<td>log(n)</td>
|
|
535
|
+
<td>log(n)</td>
|
|
536
|
+
<td>log(n)</td>
|
|
537
|
+
<td>log(n)</td>
|
|
538
|
+
<td></td>
|
|
539
|
+
</tr>
|
|
540
|
+
<tr>
|
|
541
|
+
<td><strong>Bloom Filter</strong></td>
|
|
542
|
+
<td>-</td>
|
|
543
|
+
<td>1</td>
|
|
544
|
+
<td>1</td>
|
|
545
|
+
<td>-</td>
|
|
546
|
+
<td>False positives are possible while searching</td>
|
|
547
|
+
</tr>
|
|
548
|
+
</tbody>
|
|
549
|
+
</table>
|
|
550
|
+
|
|
551
|
+
### Sorting Complexity
|
|
552
|
+
|
|
553
|
+
<table>
|
|
554
|
+
<thead>
|
|
555
|
+
<tr>
|
|
556
|
+
<th>Name</th>
|
|
557
|
+
<th>Best</th>
|
|
558
|
+
<th>Average</th>
|
|
559
|
+
<th>Worst</th>
|
|
560
|
+
<th>Memory</th>
|
|
561
|
+
<th>Stable</th>
|
|
562
|
+
<th>Comments</th>
|
|
563
|
+
</tr>
|
|
564
|
+
</thead>
|
|
565
|
+
<tbody>
|
|
566
|
+
<tr>
|
|
567
|
+
<td><strong>Bubble sort</strong></td>
|
|
568
|
+
<td>n</td>
|
|
569
|
+
<td>n<sup>2</sup></td>
|
|
570
|
+
<td>n<sup>2</sup></td>
|
|
571
|
+
<td>1</td>
|
|
572
|
+
<td>Yes</td>
|
|
573
|
+
<td></td>
|
|
574
|
+
</tr>
|
|
575
|
+
<tr>
|
|
576
|
+
<td><strong>Insertion sort</strong></td>
|
|
577
|
+
<td>n</td>
|
|
578
|
+
<td>n<sup>2</sup></td>
|
|
579
|
+
<td>n<sup>2</sup></td>
|
|
580
|
+
<td>1</td>
|
|
581
|
+
<td>Yes</td>
|
|
582
|
+
<td></td>
|
|
583
|
+
</tr>
|
|
584
|
+
<tr>
|
|
585
|
+
<td><strong>Selection sort</strong></td>
|
|
586
|
+
<td>n<sup>2</sup></td>
|
|
587
|
+
<td>n<sup>2</sup></td>
|
|
588
|
+
<td>n<sup>2</sup></td>
|
|
589
|
+
<td>1</td>
|
|
590
|
+
<td>No</td>
|
|
591
|
+
<td></td>
|
|
592
|
+
</tr>
|
|
593
|
+
<tr>
|
|
594
|
+
<td><strong>Heap sort</strong></td>
|
|
595
|
+
<td>n log(n)</td>
|
|
596
|
+
<td>n log(n)</td>
|
|
597
|
+
<td>n log(n)</td>
|
|
598
|
+
<td>1</td>
|
|
599
|
+
<td>No</td>
|
|
600
|
+
<td></td>
|
|
601
|
+
</tr>
|
|
602
|
+
<tr>
|
|
603
|
+
<td><strong>Merge sort</strong></td>
|
|
604
|
+
<td>n log(n)</td>
|
|
605
|
+
<td>n log(n)</td>
|
|
606
|
+
<td>n log(n)</td>
|
|
607
|
+
<td>n</td>
|
|
608
|
+
<td>Yes</td>
|
|
609
|
+
<td></td>
|
|
610
|
+
</tr>
|
|
611
|
+
<tr>
|
|
612
|
+
<td><strong>Quick sort</strong></td>
|
|
613
|
+
<td>n log(n)</td>
|
|
614
|
+
<td>n log(n)</td>
|
|
615
|
+
<td>n<sup>2</sup></td>
|
|
616
|
+
<td>log(n)</td>
|
|
617
|
+
<td>No</td>
|
|
618
|
+
<td>Quicksort is usually done in-place with O(log(n)) stack space</td>
|
|
619
|
+
</tr>
|
|
620
|
+
<tr>
|
|
621
|
+
<td><strong>Shell sort</strong></td>
|
|
622
|
+
<td>n log(n)</td>
|
|
623
|
+
<td>depends on gap sequence</td>
|
|
624
|
+
<td>n (log(n))<sup>2</sup></td>
|
|
625
|
+
<td>1</td>
|
|
626
|
+
<td>No</td>
|
|
627
|
+
<td></td>
|
|
628
|
+
</tr>
|
|
629
|
+
<tr>
|
|
630
|
+
<td><strong>Counting sort</strong></td>
|
|
631
|
+
<td>n + r</td>
|
|
632
|
+
<td>n + r</td>
|
|
633
|
+
<td>n + r</td>
|
|
634
|
+
<td>n + r</td>
|
|
635
|
+
<td>Yes</td>
|
|
636
|
+
<td>r - biggest number in array</td>
|
|
637
|
+
</tr>
|
|
638
|
+
<tr>
|
|
639
|
+
<td><strong>Radix sort</strong></td>
|
|
640
|
+
<td>n * k</td>
|
|
641
|
+
<td>n * k</td>
|
|
642
|
+
<td>n * k</td>
|
|
643
|
+
<td>n + k</td>
|
|
644
|
+
<td>Yes</td>
|
|
645
|
+
<td>k - length of longest key</td>
|
|
646
|
+
</tr>
|
|
647
|
+
</tbody>
|
|
648
|
+
</table>
|
|
649
|
+
|
|
650
|
+

|
|
651
|
+
|
|
652
|
+

|
|
653
|
+
|
|
654
|
+

|
|
655
|
+
|
|
656
|
+
[//]: # ()
|
|
657
|
+
|
|
658
|
+
[//]: # ()
|
|
659
|
+
[//]: # ()
|
|
660
|
+
|
|
661
|
+
[//]: # ()
|
|
662
|
+
[//]: # ()
|
|
663
|
+
|
|
664
|
+
[//]: # ()
|
|
665
|
+
[//]: # ()
|
|
666
|
+
|
|
667
|
+
[//]: # ()
|
|
668
|
+
[//]: # ()
|
|
669
|
+
|
|
670
|
+
[//]: # ()
|
|
671
|
+
[//]: # ()
|
|
672
|
+
|
|
673
|
+
[//]: # ()
|
|
674
|
+
[//]: # ()
|
|
675
|
+
|
|
676
|
+
[//]: # ()
|
|
677
|
+
[//]: # ()
|
|
678
|
+
|
|
679
|
+
[//]: # ()
|
|
680
|
+
[//]: # ()
|
|
681
|
+
|
|
682
|
+
[//]: # ()
|
|
683
|
+
[//]: # ()
|
|
684
|
+
|
|
685
|
+
[//]: # ()
|
|
686
|
+
[//]: # ()
|
|
687
|
+
|
|
688
|
+
[//]: # ()
|
|
689
|
+
[//]: # ()
|
|
690
|
+
|
|
691
|
+
[//]: # ()
|
|
692
|
+
|
|
693
|
+
[//]: # ()
|
|
694
|
+
|
|
695
|
+
[//]: # ()
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|