min-heap-typed 1.42.8 → 1.43.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 (49) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
  2. package/dist/data-structures/binary-tree/avl-tree.js +88 -23
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
  4. package/dist/data-structures/binary-tree/binary-tree.js +415 -236
  5. package/dist/data-structures/binary-tree/bst.d.ts +121 -66
  6. package/dist/data-structures/binary-tree/bst.js +121 -67
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
  8. package/dist/data-structures/binary-tree/rb-tree.js +95 -18
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
  10. package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
  11. package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
  12. package/dist/data-structures/graph/abstract-graph.js +147 -36
  13. package/dist/data-structures/graph/directed-graph.d.ts +126 -0
  14. package/dist/data-structures/graph/directed-graph.js +126 -0
  15. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  16. package/dist/data-structures/graph/undirected-graph.js +63 -0
  17. package/dist/data-structures/heap/heap.d.ts +175 -12
  18. package/dist/data-structures/heap/heap.js +175 -12
  19. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
  20. package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
  21. package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
  22. package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
  23. package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
  24. package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
  25. package/dist/data-structures/queue/deque.d.ts +113 -3
  26. package/dist/data-structures/queue/deque.js +113 -3
  27. package/dist/data-structures/queue/queue.d.ts +87 -0
  28. package/dist/data-structures/queue/queue.js +87 -0
  29. package/dist/data-structures/stack/stack.d.ts +42 -0
  30. package/dist/data-structures/stack/stack.js +42 -0
  31. package/dist/data-structures/trie/trie.d.ts +76 -0
  32. package/dist/data-structures/trie/trie.js +76 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/avl-tree.ts +97 -23
  35. package/src/data-structures/binary-tree/binary-tree.ts +465 -256
  36. package/src/data-structures/binary-tree/bst.ts +130 -68
  37. package/src/data-structures/binary-tree/rb-tree.ts +106 -19
  38. package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
  39. package/src/data-structures/graph/abstract-graph.ts +133 -7
  40. package/src/data-structures/graph/directed-graph.ts +145 -1
  41. package/src/data-structures/graph/undirected-graph.ts +72 -0
  42. package/src/data-structures/heap/heap.ts +201 -12
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
  44. package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
  45. package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
  46. package/src/data-structures/queue/deque.ts +127 -3
  47. package/src/data-structures/queue/queue.ts +99 -0
  48. package/src/data-structures/stack/stack.ts +48 -0
  49. package/src/data-structures/trie/trie.ts +87 -4
@@ -111,6 +111,14 @@ export class DirectedGraph<
111
111
  }
112
112
 
113
113
  /**
114
+ * Time Complexity: O(|V|) where |V| is the number of vertices
115
+ * Space Complexity: O(1)
116
+ */
117
+
118
+ /**
119
+ * Time Complexity: O(|V|) where |V| is the number of vertices
120
+ * Space Complexity: O(1)
121
+ *
114
122
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
115
123
  * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
116
124
  * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
@@ -137,6 +145,14 @@ export class DirectedGraph<
137
145
  }
138
146
 
139
147
  /**
148
+ * Time Complexity: O(|E|) where |E| is the number of edges
149
+ * Space Complexity: O(1)
150
+ */
151
+
152
+ /**
153
+ * Time Complexity: O(|E|) where |E| is the number of edges
154
+ * Space Complexity: O(1)
155
+ *
140
156
  * The function removes an edge between two vertices in a graph and returns the removed edge.
141
157
  * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
142
158
  * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
@@ -163,6 +179,14 @@ export class DirectedGraph<
163
179
  }
164
180
 
165
181
  /**
182
+ * Time Complexity: O(|E|) where |E| is the number of edges
183
+ * Space Complexity: O(1)
184
+ */
185
+
186
+ /**
187
+ * Time Complexity: O(|E|) where |E| is the number of edges
188
+ * Space Complexity: O(1)
189
+ *
166
190
  * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
167
191
  * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
168
192
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
@@ -188,6 +212,14 @@ export class DirectedGraph<
188
212
  }
189
213
 
190
214
  /**
215
+ * Time Complexity: O(|E|) where |E| is the number of edges
216
+ * Space Complexity: O(1)
217
+ */
218
+
219
+ /**
220
+ * Time Complexity: O(|E|) where |E| is the number of edges
221
+ * Space Complexity: O(1)
222
+ *
191
223
  * The function removes edges between two vertices and returns the removed edges.
192
224
  * @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
193
225
  * unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
@@ -210,6 +242,14 @@ export class DirectedGraph<
210
242
  }
211
243
 
212
244
  /**
245
+ * Time Complexity: O(1)
246
+ * Space Complexity: O(1)
247
+ */
248
+
249
+ /**
250
+ * Time Complexity: O(1)
251
+ * Space Complexity: O(1)
252
+ *
213
253
  * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
214
254
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
215
255
  * (`VertexKey`).
@@ -224,6 +264,14 @@ export class DirectedGraph<
224
264
  }
225
265
 
226
266
  /**
267
+ * Time Complexity: O(1)
268
+ * Space Complexity: O(1)
269
+ */
270
+
271
+ /**
272
+ * Time Complexity: O(1)
273
+ * Space Complexity: O(1)
274
+ *
227
275
  * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
228
276
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
229
277
  * (`VertexKey`).
@@ -238,6 +286,14 @@ export class DirectedGraph<
238
286
  }
239
287
 
240
288
  /**
289
+ * Time Complexity: O(1)
290
+ * Space Complexity: O(1)
291
+ */
292
+
293
+ /**
294
+ * Time Complexity: O(1)
295
+ * Space Complexity: O(1)
296
+ *
241
297
  * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
242
298
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
243
299
  * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
@@ -247,6 +303,14 @@ export class DirectedGraph<
247
303
  }
248
304
 
249
305
  /**
306
+ * Time Complexity: O(1)
307
+ * Space Complexity: O(1)
308
+ */
309
+
310
+ /**
311
+ * Time Complexity: O(1)
312
+ * Space Complexity: O(1)
313
+ *
250
314
  * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
251
315
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
252
316
  * @returns The number of incoming edges of the specified vertex or vertex ID.
@@ -256,6 +320,14 @@ export class DirectedGraph<
256
320
  }
257
321
 
258
322
  /**
323
+ * Time Complexity: O(1)
324
+ * Space Complexity: O(1)
325
+ */
326
+
327
+ /**
328
+ * Time Complexity: O(1)
329
+ * Space Complexity: O(1)
330
+ *
259
331
  * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
260
332
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
261
333
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
@@ -265,6 +337,14 @@ export class DirectedGraph<
265
337
  }
266
338
 
267
339
  /**
340
+ * Time Complexity: O(1)
341
+ * Space Complexity: O(1)
342
+ */
343
+
344
+ /**
345
+ * Time Complexity: O(1)
346
+ * Space Complexity: O(1)
347
+ *
268
348
  * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
269
349
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
270
350
  * @returns The function `edgesOf` returns an array of edges.
@@ -274,6 +354,14 @@ export class DirectedGraph<
274
354
  }
275
355
 
276
356
  /**
357
+ * Time Complexity: O(1)
358
+ * Space Complexity: O(1)
359
+ */
360
+
361
+ /**
362
+ * Time Complexity: O(1)
363
+ * Space Complexity: O(1)
364
+ *
277
365
  * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
278
366
  * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
279
367
  * @returns either a vertex object (VO) or null.
@@ -283,6 +371,14 @@ export class DirectedGraph<
283
371
  }
284
372
 
285
373
  /**
374
+ * Time Complexity: O(1)
375
+ * Space Complexity: O(1)
376
+ */
377
+
378
+ /**
379
+ * Time Complexity: O(1)
380
+ * Space Complexity: O(1)
381
+ *
286
382
  * The function "getEdgeDest" returns the destination vertex of an edge.
287
383
  * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
288
384
  * @returns either a vertex object of type VO or null.
@@ -292,6 +388,14 @@ export class DirectedGraph<
292
388
  }
293
389
 
294
390
  /**
391
+ * Time Complexity: O(|E|) where |E| is the number of edges
392
+ * Space Complexity: O(1)
393
+ */
394
+
395
+ /**
396
+ * Time Complexity: O(|E|) where |E| is the number of edges
397
+ * Space Complexity: O(1)
398
+ *
295
399
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
296
400
  * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
297
401
  * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
@@ -313,6 +417,14 @@ export class DirectedGraph<
313
417
  }
314
418
 
315
419
  /**
420
+ * Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
421
+ * Space Complexity: O(|V|)
422
+ */
423
+
424
+ /**
425
+ * Time Complexity: O(|V| + |E|) where |V| is the number of vertices and |E| is the number of edges
426
+ * Space Complexity: O(|V|)
427
+ *
316
428
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
317
429
  * in the sorted order, or null if the graph contains a cycle.
318
430
  * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
@@ -359,6 +471,14 @@ export class DirectedGraph<
359
471
  }
360
472
 
361
473
  /**
474
+ * Time Complexity: O(|E|) where |E| is the number of edges
475
+ * Space Complexity: O(|E|)
476
+ */
477
+
478
+ /**
479
+ * Time Complexity: O(|E|) where |E| is the number of edges
480
+ * Space Complexity: O(|E|)
481
+ *
362
482
  * The `edgeSet` function returns an array of all the edges in the graph.
363
483
  * @returns The `edgeSet()` method returns an array of edges (`EO[]`).
364
484
  */
@@ -371,6 +491,14 @@ export class DirectedGraph<
371
491
  }
372
492
 
373
493
  /**
494
+ * Time Complexity: O(|E|) where |E| is the number of edges
495
+ * Space Complexity: O(1)
496
+ */
497
+
498
+ /**
499
+ * Time Complexity: O(|E|) where |E| is the number of edges
500
+ * Space Complexity: O(1)
501
+ *
374
502
  * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
375
503
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
376
504
  * (`VertexKey`).
@@ -393,6 +521,14 @@ export class DirectedGraph<
393
521
  }
394
522
 
395
523
  /**
524
+ * Time Complexity: O(1)
525
+ * Space Complexity: O(1)
526
+ */
527
+
528
+ /**
529
+ * Time Complexity: O(1)
530
+ * Space Complexity: O(1)
531
+ *
396
532
  * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
397
533
  * otherwise it returns null.
398
534
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
@@ -413,6 +549,14 @@ export class DirectedGraph<
413
549
  }
414
550
 
415
551
  /**
552
+ * Time Complexity: O(1)
553
+ * Space Complexity: O(1)
554
+ */
555
+
556
+ /**
557
+ * Time Complexity: O(1)
558
+ * Space Complexity: O(1)
559
+ *
416
560
  * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
417
561
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
418
562
  * needs to be added to the graph.
@@ -447,4 +591,4 @@ export class DirectedGraph<
447
591
  return false;
448
592
  }
449
593
  }
450
- }
594
+ }
@@ -93,6 +93,14 @@ export class UndirectedGraph<
93
93
  }
94
94
 
95
95
  /**
96
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
97
+ * Space Complexity: O(1)
98
+ */
99
+
100
+ /**
101
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
102
+ * Space Complexity: O(1)
103
+ *
96
104
  * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
97
105
  * @param {VO | VertexKey | null} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
98
106
  * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
@@ -116,6 +124,14 @@ export class UndirectedGraph<
116
124
  }
117
125
 
118
126
  /**
127
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
128
+ * Space Complexity: O(1)
129
+ */
130
+
131
+ /**
132
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
133
+ * Space Complexity: O(1)
134
+ *
119
135
  * The function removes an edge between two vertices in a graph and returns the removed edge.
120
136
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
121
137
  * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
@@ -143,6 +159,14 @@ export class UndirectedGraph<
143
159
  }
144
160
 
145
161
  /**
162
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
163
+ * Space Complexity: O(1)
164
+ */
165
+
166
+ /**
167
+ * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
168
+ * Space Complexity: O(1)
169
+ *
146
170
  * The deleteEdge function removes an edge between two vertices in a graph.
147
171
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
148
172
  * @returns The method is returning either the removed edge (of type EO) or null if the edge was not found.
@@ -152,6 +176,14 @@ export class UndirectedGraph<
152
176
  }
153
177
 
154
178
  /**
179
+ * Time Complexity: O(1)
180
+ * Space Complexity: O(1)
181
+ */
182
+
183
+ /**
184
+ * Time Complexity: O(1)
185
+ * Space Complexity: O(1)
186
+ *
155
187
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
156
188
  * vertex.
157
189
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
@@ -168,6 +200,14 @@ export class UndirectedGraph<
168
200
  }
169
201
 
170
202
  /**
203
+ * Time Complexity: O(1)
204
+ * Space Complexity: O(1)
205
+ */
206
+
207
+ /**
208
+ * Time Complexity: O(1)
209
+ * Space Complexity: O(1)
210
+ *
171
211
  * The function returns the edges of a given vertex or vertex ID.
172
212
  * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
173
213
  * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
@@ -183,6 +223,14 @@ export class UndirectedGraph<
183
223
  }
184
224
 
185
225
  /**
226
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
227
+ * Space Complexity: O(|E|)
228
+ */
229
+
230
+ /**
231
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
232
+ * Space Complexity: O(|E|)
233
+ *
186
234
  * The function "edgeSet" returns an array of unique edges from a set of edges.
187
235
  * @returns The method `edgeSet()` returns an array of type `EO[]`.
188
236
  */
@@ -197,6 +245,14 @@ export class UndirectedGraph<
197
245
  }
198
246
 
199
247
  /**
248
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
249
+ * Space Complexity: O(|E|)
250
+ */
251
+
252
+ /**
253
+ * Time Complexity: O(|V| + |E|), where |V| is the number of vertices and |E| is the number of edges.
254
+ * Space Complexity: O(|E|)
255
+ *
200
256
  * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
201
257
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
202
258
  * (`VertexKey`).
@@ -218,6 +274,14 @@ export class UndirectedGraph<
218
274
  }
219
275
 
220
276
  /**
277
+ * Time Complexity: O(1)
278
+ * Space Complexity: O(1)
279
+ */
280
+
281
+ /**
282
+ * Time Complexity: O(1)
283
+ * Space Complexity: O(1)
284
+ *
221
285
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
222
286
  * it returns null.
223
287
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
@@ -238,6 +302,14 @@ export class UndirectedGraph<
238
302
  }
239
303
 
240
304
  /**
305
+ * Time Complexity: O(1)
306
+ * Space Complexity: O(1)
307
+ */
308
+
309
+ /**
310
+ * Time Complexity: O(1)
311
+ * Space Complexity: O(1)
312
+ *
241
313
  * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
242
314
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
243
315
  * @returns a boolean value.