bst-typed 1.19.9 → 1.20.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.
Files changed (2) hide show
  1. package/README.md +300 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -14,15 +14,314 @@ npm i bst-typed
14
14
  ```bash
15
15
  yarn add bst-typed
16
16
  ```
17
-
17
+ ### methods
18
+ ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/methods-8bit/bst.png?raw=true)
18
19
  ### snippet
19
20
  #### TS
20
21
  ```typescript
22
+ import {BST, BSTNode} from 'data-structure-typed';
23
+ // /* or if you prefer */ import {BST, BSTNode} from 'bst-typed';
24
+
25
+ const bst = new BST();
26
+ bst instanceof BST; // true
27
+ bst.add(11);
28
+ bst.add(3);
29
+ const idsAndValues = [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
30
+ bst.addMany(idsAndValues);
31
+ bst.root instanceof BSTNode; // true
32
+
33
+ if (bst.root) bst.root.id; // 11
34
+
35
+ bst.size; // 16
36
+
37
+ bst.has(6); // true
38
+
39
+ const node6 = bst.get(6);
40
+ node6 && bst.getHeight(6); // 2
41
+ node6 && bst.getDepth(6); // 3
42
+
43
+ const nodeId10 = bst.get(10);
44
+ nodeId10?.id; // 10
45
+
46
+ const nodeVal9 = bst.get(9, 'val');
47
+ nodeVal9?.id; // 9
48
+
49
+
50
+ const leftMost = bst.getLeftMost();
51
+ leftMost?.id; // 1
52
+
53
+ const node15 = bst.get(15);
54
+ const minNodeBySpecificNode = node15 && bst.getLeftMost(node15);
55
+ minNodeBySpecificNode?.id; // 12
56
+
57
+ const subTreeSum = node15 && bst.subTreeSum(15);
58
+ subTreeSum; // 70
59
+
60
+ const lesserSum = bst.lesserSum(10);
61
+ lesserSum; // 45
62
+
63
+ node15 instanceof BSTNode; // true
64
+
65
+ const node11 = bst.get(11);
66
+ node11 instanceof BSTNode; // true
67
+
68
+ const dfsInorderNodes = bst.DFS('in', 'node');
69
+ dfsInorderNodes[0].id; // 1
70
+ dfsInorderNodes[dfsInorderNodes.length - 1].id; // 16
71
+
72
+ bst.perfectlyBalance();
73
+ bst.isPerfectlyBalanced(); // true
74
+
75
+ const bfsNodesAfterBalanced = bst.BFS('node');
76
+ bfsNodesAfterBalanced[0].id; // 8);
77
+ bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id; // 16
78
+
79
+ const removed11 = bst.remove(11, true);
80
+ removed11 instanceof Array; // true
81
+
82
+
83
+ if (removed11[0].deleted) removed11[0].deleted.id; // 11
84
+
85
+ bst.isAVLBalanced(); // true
86
+
87
+ bst.getHeight(15); // 1
88
+
89
+ const removed1 = bst.remove(1, true);
90
+ removed1 instanceof Array; // true
91
+
92
+ if (removed1[0].deleted) removed1[0].deleted.id; // 1
93
+
94
+ bst.isAVLBalanced(); // true
95
+
96
+ bst.getHeight(); // 4
97
+
98
+ const removed4 = bst.remove(4, true);
99
+ removed4 instanceof Array; // true
100
+
101
+ if (removed4[0].deleted) removed4[0].deleted.id; // 4
102
+ bst.isAVLBalanced(); // true
103
+ bst.getHeight(); // 4
104
+
105
+ const removed10 = bst.remove(10, true);
106
+
107
+ if (removed10[0].deleted) removed10[0].deleted.id; // 10
108
+ bst.isAVLBalanced(); // false
109
+ bst.getHeight(); // 4
110
+
111
+ const removed15 = bst.remove(15, true);
112
+
113
+ if (removed15[0].deleted) removed15[0].deleted.id; // 15
114
+
115
+ bst.isAVLBalanced(); // true
116
+ bst.getHeight(); // 3
117
+
118
+ const removed5 = bst.remove(5, true);
119
+
120
+ if (removed5[0].deleted) removed5[0].deleted.id; // 5
121
+
122
+ bst.isAVLBalanced(); // true
123
+ bst.getHeight(); // 3
124
+
125
+ const removed13 = bst.remove(13, true);
126
+ if (removed13[0].deleted) removed13[0].deleted.id; // 13
127
+ bst.isAVLBalanced(); // true
128
+ bst.getHeight(); // 3
129
+
130
+ const removed3 = bst.remove(3, true);
131
+ if (removed3[0].deleted) removed3[0].deleted.id; // 3
132
+ bst.isAVLBalanced(); // false
133
+ bst.getHeight(); // 3
134
+
135
+ const removed8 = bst.remove(8, true);
136
+ if (removed8[0].deleted) removed8[0].deleted.id; // 8
137
+ bst.isAVLBalanced(); // true
138
+ bst.getHeight(); // 3
139
+
140
+ const removed6 = bst.remove(6, true);
141
+ if (removed6[0].deleted) removed6[0].deleted.id; // 6
142
+ bst.remove(6, true).length; // 0
143
+ bst.isAVLBalanced(); // false
144
+ bst.getHeight(); // 3
145
+
146
+ const removed7 = bst.remove(7, true);
147
+ if (removed7[0].deleted) removed7[0].deleted.id; // 7
148
+ bst.isAVLBalanced(); // false
149
+ bst.getHeight(); // 3
150
+
151
+ const removed9 = bst.remove(9, true);
152
+ if (removed9[0].deleted) removed9[0].deleted.id; // 9
153
+ bst.isAVLBalanced(); // false
154
+ bst.getHeight(); // 3
155
+
156
+ const removed14 = bst.remove(14, true);
157
+ if (removed14[0].deleted) removed14[0].deleted.id; // 14
158
+ bst.isAVLBalanced(); // false
159
+ bst.getHeight(); // 2
160
+
161
+ bst.isAVLBalanced(); // false
162
+
163
+ const bfsIDs = bst.BFS();
164
+ bfsIDs[0]; // 2
165
+ bfsIDs[1]; // 12
166
+ bfsIDs[2]; // 16
21
167
 
168
+ const bfsNodes = bst.BFS('node');
169
+ bfsNodes[0].id; // 2
170
+ bfsNodes[1].id; // 12
171
+ bfsNodes[2].id; // 16
22
172
  ```
23
173
  #### JS
24
174
  ```javascript
175
+ const {BST, BSTNode} = require('data-structure-typed');
176
+ // /* or if you prefer */ const {BST, BSTNode} = require('bst-typed');
177
+
178
+ const bst = new BST();
179
+ bst instanceof BST; // true
180
+ bst.add(11);
181
+ bst.add(3);
182
+ const idsAndValues = [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
183
+ bst.addMany(idsAndValues);
184
+ bst.root instanceof BSTNode; // true
185
+
186
+ if (bst.root) bst.root.id; // 11
187
+
188
+ bst.size; // 16
189
+
190
+ bst.has(6); // true
191
+
192
+ const node6 = bst.get(6);
193
+ node6 && bst.getHeight(6); // 2
194
+ node6 && bst.getDepth(6); // 3
195
+
196
+ const nodeId10 = bst.get(10);
197
+ nodeId10?.id; // 10
198
+
199
+ const nodeVal9 = bst.get(9, 'val');
200
+ nodeVal9?.id; // 9
201
+
202
+
203
+ const leftMost = bst.getLeftMost();
204
+ leftMost?.id; // 1
205
+
206
+ const node15 = bst.get(15);
207
+ const minNodeBySpecificNode = node15 && bst.getLeftMost(node15);
208
+ minNodeBySpecificNode?.id; // 12
209
+
210
+ const subTreeSum = node15 && bst.subTreeSum(15);
211
+ subTreeSum; // 70
212
+
213
+ const lesserSum = bst.lesserSum(10);
214
+ lesserSum; // 45
215
+
216
+ node15 instanceof BSTNode; // true
217
+
218
+ const node11 = bst.get(11);
219
+ node11 instanceof BSTNode; // true
220
+
221
+ const dfsInorderNodes = bst.DFS('in', 'node');
222
+ dfsInorderNodes[0].id; // 1
223
+ dfsInorderNodes[dfsInorderNodes.length - 1].id; // 16
224
+
225
+ bst.perfectlyBalance();
226
+ bst.isPerfectlyBalanced(); // true
227
+
228
+ const bfsNodesAfterBalanced = bst.BFS('node');
229
+ bfsNodesAfterBalanced[0].id; // 8);
230
+ bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].id; // 16
231
+
232
+ const removed11 = bst.remove(11, true);
233
+ removed11 instanceof Array; // true
234
+
235
+
236
+ if (removed11[0].deleted) removed11[0].deleted.id; // 11
237
+
238
+ bst.isAVLBalanced(); // true
239
+
240
+ bst.getHeight(15); // 1
241
+
242
+ const removed1 = bst.remove(1, true);
243
+ removed1 instanceof Array; // true
244
+
245
+ if (removed1[0].deleted) removed1[0].deleted.id; // 1
246
+
247
+ bst.isAVLBalanced(); // true
248
+
249
+ bst.getHeight(); // 4
250
+
251
+ const removed4 = bst.remove(4, true);
252
+ removed4 instanceof Array; // true
253
+
254
+ if (removed4[0].deleted) removed4[0].deleted.id; // 4
255
+ bst.isAVLBalanced(); // true
256
+ bst.getHeight(); // 4
257
+
258
+ const removed10 = bst.remove(10, true);
259
+
260
+ if (removed10[0].deleted) removed10[0].deleted.id; // 10
261
+ bst.isAVLBalanced(); // false
262
+ bst.getHeight(); // 4
263
+
264
+ const removed15 = bst.remove(15, true);
265
+
266
+ if (removed15[0].deleted) removed15[0].deleted.id; // 15
267
+
268
+ bst.isAVLBalanced(); // true
269
+ bst.getHeight(); // 3
270
+
271
+ const removed5 = bst.remove(5, true);
272
+
273
+ if (removed5[0].deleted) removed5[0].deleted.id; // 5
274
+
275
+ bst.isAVLBalanced(); // true
276
+ bst.getHeight(); // 3
277
+
278
+ const removed13 = bst.remove(13, true);
279
+ if (removed13[0].deleted) removed13[0].deleted.id; // 13
280
+ bst.isAVLBalanced(); // true
281
+ bst.getHeight(); // 3
282
+
283
+ const removed3 = bst.remove(3, true);
284
+ if (removed3[0].deleted) removed3[0].deleted.id; // 3
285
+ bst.isAVLBalanced(); // false
286
+ bst.getHeight(); // 3
287
+
288
+ const removed8 = bst.remove(8, true);
289
+ if (removed8[0].deleted) removed8[0].deleted.id; // 8
290
+ bst.isAVLBalanced(); // true
291
+ bst.getHeight(); // 3
292
+
293
+ const removed6 = bst.remove(6, true);
294
+ if (removed6[0].deleted) removed6[0].deleted.id; // 6
295
+ bst.remove(6, true).length; // 0
296
+ bst.isAVLBalanced(); // false
297
+ bst.getHeight(); // 3
298
+
299
+ const removed7 = bst.remove(7, true);
300
+ if (removed7[0].deleted) removed7[0].deleted.id; // 7
301
+ bst.isAVLBalanced(); // false
302
+ bst.getHeight(); // 3
303
+
304
+ const removed9 = bst.remove(9, true);
305
+ if (removed9[0].deleted) removed9[0].deleted.id; // 9
306
+ bst.isAVLBalanced(); // false
307
+ bst.getHeight(); // 3
308
+
309
+ const removed14 = bst.remove(14, true);
310
+ if (removed14[0].deleted) removed14[0].deleted.id; // 14
311
+ bst.isAVLBalanced(); // false
312
+ bst.getHeight(); // 2
313
+
314
+ bst.isAVLBalanced(); // false
315
+
316
+ const bfsIDs = bst.BFS();
317
+ bfsIDs[0]; // 2
318
+ bfsIDs[1]; // 12
319
+ bfsIDs[2]; // 16
25
320
 
321
+ const bfsNodes = bst.BFS('node');
322
+ bfsNodes[0].id; // 2
323
+ bfsNodes[1].id; // 12
324
+ bfsNodes[2].id; // 16
26
325
  ```
27
326
 
28
327
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bst-typed",
3
- "version": "1.19.9",
3
+ "version": "1.20.0",
4
4
  "description": "BST (Binary Search Tree). Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -65,7 +65,7 @@
65
65
  "typescript": "^4.9.5"
66
66
  },
67
67
  "dependencies": {
68
- "data-structure-typed": "^1.19.9",
68
+ "data-structure-typed": "^1.20.0",
69
69
  "zod": "^3.22.2"
70
70
  }
71
71
  }