min-heap-typed 1.42.7 → 1.42.9

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 +388 -201
  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 +419 -204
  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
@@ -68,17 +68,23 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
68
68
  }
69
69
 
70
70
  /**
71
- * The `add` function adds a new node to a binary search tree, updating the count if the key already
72
- * exists, and balancing the tree if necessary.
73
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can be either a
74
- * `BTNKey` (which represents the key of the node to be added), a `N` (which represents a
75
- * node to be added), or `undefined` (which represents a undefined node).
76
- * @param [value] - The `value` parameter represents the value associated with the key that is being
77
- * added to the binary tree.
78
- * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
79
- * pair that will be added to the binary tree. It has a default value of 1, which means that if no
80
- * count is specified, the default count will be 1.
81
- * @returns The function `add` returns a value of type `N | undefined | undefined`.
71
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
72
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
73
+ */
74
+
75
+ /**
76
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
77
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
78
+ *
79
+ * The `add` function adds a new node to the tree multimap, updating the count if the key already
80
+ * exists, and balances the tree if necessary.
81
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be one of the
82
+ * following types:
83
+ * @param {V} [value] - The `value` parameter represents the value associated with the key that is
84
+ * being added to the tree. It is an optional parameter, so it can be omitted if not needed.
85
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
86
+ * times the key-value pair should be added to the multimap. If not provided, the default value is 1.
87
+ * @returns a node (`N`) or `undefined`.
82
88
  */
83
89
  override add(keyOrNode: BTNKey | N | null | undefined, value?: V, count = 1): N | undefined {
84
90
  if (keyOrNode === null) return undefined;
@@ -150,12 +156,24 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
150
156
  }
151
157
 
152
158
  /**
153
- * The function adds a new node to a binary tree if there is an available slot in the parent node.
154
- * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be added to
155
- * the tree. It can be either a node object (`N`) or `undefined`.
156
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
157
- * be added as a child.
158
- * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
159
+ * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
160
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
161
+ */
162
+
163
+ /**
164
+ * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
165
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
166
+ *
167
+ * The function adds a new node to a binary tree, either as the left child or the right child of a
168
+ * given parent node.
169
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
170
+ * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
171
+ * `undefined` if there is no node to add.
172
+ * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
173
+ * which the new node will be added as a child. It can be either a node object (`N`) or a key value
174
+ * (`BTNKey`).
175
+ * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
176
+ * added, or `undefined` if no node was added.
159
177
  */
160
178
  protected override _addTo(newNode: N | undefined, parent: BTNKey | N | undefined): N | undefined {
161
179
  parent = this.ensureNotKey(parent);
@@ -184,14 +202,22 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
184
202
  }
185
203
 
186
204
  /**
187
- * The `addMany` function adds multiple keys or nodes to a TreeMultimap and returns an array of the
188
- * inserted nodes.
189
- * @param {(BTNKey | undefined)[] | (N | undefined)[]} keysOrNodes - An array of keys or nodes to be
190
- * added to the multiset. Each element can be either a BTNKey or a TreeMultimapNode.
191
- * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond
192
- * to the keys or nodes being added to the multiset. It is used to associate additional data with
193
- * each key or node.
194
- * @returns The function `addMany` returns an array of `N`, `undefined`, or `undefined` values.
205
+ * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
206
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
207
+ */
208
+
209
+ /**
210
+ * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
211
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
212
+ *
213
+ * The function `addMany` takes an array of keys or nodes and adds them to the TreeMultimap,
214
+ * returning an array of the inserted nodes.
215
+ * @param {(BTNKey | N | undefined)[]} keysOrNodes - An array of keys or nodes. Each element can be
216
+ * of type BTNKey, N, or undefined.
217
+ * @param {V[]} [data] - The `data` parameter is an optional array of values that correspond to the
218
+ * keys or nodes being added. It is used to associate data with each key or node being added to the
219
+ * TreeMultimap. If provided, the length of the `data` array should be the same as the length of the
220
+ * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
195
221
  */
196
222
  override addMany(keysOrNodes: (BTNKey | N | undefined)[], data?: V[]): (N | undefined)[] {
197
223
  const inserted: (N | undefined)[] = [];
@@ -215,10 +241,18 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
215
241
  }
216
242
 
217
243
  /**
218
- * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
219
- * binary search tree using either a recursive or iterative approach.
244
+ * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
245
+ * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
246
+ */
247
+
248
+ /**
249
+ * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
250
+ * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
251
+ *
252
+ * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
253
+ * tree using either a recursive or iterative approach.
220
254
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
221
- * type of iteration to use when building a balanced binary search tree. It can have two possible
255
+ * type of iteration to use when building the balanced binary search tree. It can have two possible
222
256
  * values:
223
257
  * @returns a boolean value.
224
258
  */
@@ -261,20 +295,28 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
261
295
  }
262
296
 
263
297
  /**
264
- * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
265
- * node along with the parent node that needs to be balanced.
266
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
267
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
268
- * searching for. It can be a specific key value or any other property of the node.
269
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
270
- * value. This value is compared with the `identifier` parameter to determine if the node should be
271
- * included in the result. The `callback` parameter has a default value of
272
- * `this._defaultOneParamCallback`
298
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
299
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
300
+ */
301
+
302
+ /**
303
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
304
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
305
+ *
306
+ * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
307
+ * account the count of the node and balancing the tree if necessary.
308
+ * @param identifier - The identifier is the value or key that is used to identify the node that
309
+ * needs to be deleted from the binary tree. It can be of any type that is returned by the callback
310
+ * function.
311
+ * @param {C} callback - The `callback` parameter is a function that is used to determine if a node
312
+ * should be deleted. It is optional and defaults to a default callback function. The `callback`
313
+ * function takes one parameter, which is the identifier of the node, and returns a value that is
314
+ * used to identify the node to
273
315
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
274
316
  * being deleted. If set to true, the count of the node will not be considered and the node will be
275
317
  * deleted regardless of its count. If set to false (default), the count of the node will be
276
318
  * decremented by 1 and
277
- * @returns The method `delete` returns an array of `BiTreeDeleteResult<N>` objects.
319
+ * @returns an array of `BiTreeDeleteResult<N>`.
278
320
  */
279
321
  override delete<C extends BTNCallback<N>>(
280
322
  identifier: ReturnType<C>,
@@ -344,11 +386,13 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
344
386
  }
345
387
 
346
388
  /**
347
- * The function swaps the values of two nodes in a binary tree.
348
- * @param {N} srcNode - The source node that needs to be swapped with the destination node.
349
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
350
- * from `srcNode` will be swapped into.
351
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
389
+ * The `_swap` function swaps the key, value, count, and height properties between two nodes.
390
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from
391
+ * which the values will be swapped. It can be of type `BTNKey`, `N`, or `undefined`.
392
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
393
+ * node where the values from the source node will be swapped to.
394
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
395
+ * if either `srcNode` or `destNode` is undefined.
352
396
  */
353
397
  protected _swap(srcNode: BTNKey | N | undefined, destNode:BTNKey | N | undefined): N | undefined{
354
398
  srcNode = this.ensureNotKey(srcNode);
@@ -374,4 +418,4 @@ export class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = TreeMultim
374
418
  }
375
419
  return undefined;
376
420
  }
377
- }
421
+ }
@@ -105,6 +105,14 @@ export abstract class AbstractGraph<
105
105
  abstract getEndsOfEdge(edge: EO): [VO, VO] | null;
106
106
 
107
107
  /**
108
+ * Time Complexity: O(1) - Constant time for Map lookup.
109
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
110
+ */
111
+
112
+ /**
113
+ * Time Complexity: O(1) - Constant time for Map lookup.
114
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
115
+ *
108
116
  * The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
109
117
  * @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
110
118
  * the `_vertices` map.
@@ -116,6 +124,14 @@ export abstract class AbstractGraph<
116
124
  }
117
125
 
118
126
  /**
127
+ * Time Complexity: O(1) - Constant time for Map lookup.
128
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
129
+ */
130
+
131
+ /**
132
+ * Time Complexity: O(1) - Constant time for Map lookup.
133
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
134
+ *
119
135
  * The function checks if a vertex exists in a graph.
120
136
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
121
137
  * (`VertexKey`).
@@ -129,6 +145,11 @@ export abstract class AbstractGraph<
129
145
 
130
146
  addVertex(key: VertexKey, value?: V): boolean;
131
147
 
148
+ /**
149
+ * Time Complexity: O(1) - Constant time for Map operations.
150
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
151
+ */
152
+
132
153
  addVertex(keyOrVertex: VertexKey | VO, value?: V): boolean {
133
154
  if (keyOrVertex instanceof AbstractVertex) {
134
155
  return this._addVertexOnly(keyOrVertex);
@@ -139,6 +160,14 @@ export abstract class AbstractGraph<
139
160
  }
140
161
 
141
162
  /**
163
+ * Time Complexity: O(1) - Constant time for Map operations.
164
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
165
+ */
166
+
167
+ /**
168
+ * Time Complexity: O(1) - Constant time for Map operations.
169
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
170
+ *
142
171
  * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
143
172
  * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
144
173
  * (`VertexKey`).
@@ -150,6 +179,14 @@ export abstract class AbstractGraph<
150
179
  }
151
180
 
152
181
  /**
182
+ * Time Complexity: O(K), where K is the number of vertices to be removed.
183
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
184
+ */
185
+
186
+ /**
187
+ * Time Complexity: O(K), where K is the number of vertices to be removed.
188
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
189
+ *
153
190
  * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
154
191
  * @param {VO[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`VO[]`) or an array
155
192
  * of vertex IDs (`VertexKey[]`).
@@ -165,6 +202,14 @@ export abstract class AbstractGraph<
165
202
  }
166
203
 
167
204
  /**
205
+ * Time Complexity: O(1) - Depends on the implementation in the concrete class.
206
+ * Space Complexity: O(1) - Depends on the implementation in the concrete class.
207
+ */
208
+
209
+ /**
210
+ * Time Complexity: O(1) - Depends on the implementation in the concrete class.
211
+ * Space Complexity: O(1) - Depends on the implementation in the concrete class.
212
+ *
168
213
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
169
214
  * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
170
215
  * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
@@ -181,6 +226,11 @@ export abstract class AbstractGraph<
181
226
 
182
227
  addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
183
228
 
229
+ /**
230
+ * Time Complexity: O(1) - Depends on the implementation in the concrete class.
231
+ * Space Complexity: O(1) - Depends on the implementation in the concrete class.
232
+ */
233
+
184
234
  addEdge(srcOrEdge: VO | VertexKey | EO, dest?: VO | VertexKey, weight?: number, value?: E): boolean {
185
235
  if (srcOrEdge instanceof AbstractEdge) {
186
236
  return this._addEdgeOnly(srcOrEdge);
@@ -198,6 +248,14 @@ export abstract class AbstractGraph<
198
248
  }
199
249
 
200
250
  /**
251
+ * Time Complexity: O(1) - Constant time for Map and Edge operations.
252
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
253
+ */
254
+
255
+ /**
256
+ * Time Complexity: O(1) - Constant time for Map and Edge operations.
257
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
258
+ *
201
259
  * The function sets the weight of an edge between two vertices in a graph.
202
260
  * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
203
261
  * the source vertex of the edge.
@@ -219,6 +277,14 @@ export abstract class AbstractGraph<
219
277
  }
220
278
 
221
279
  /**
280
+ * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
281
+ * Space Complexity: O(P) - Linear space, where P is the number of paths found.
282
+ */
283
+
284
+ /**
285
+ * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
286
+ * Space Complexity: O(P) - Linear space, where P is the number of paths found.
287
+ *
222
288
  * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
223
289
  * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
224
290
  * It is the starting vertex for finding paths.
@@ -258,6 +324,14 @@ export abstract class AbstractGraph<
258
324
  }
259
325
 
260
326
  /**
327
+ * Time Complexity: O(L), where L is the length of the path.
328
+ * Space Complexity: O(1) - Constant space.
329
+ */
330
+
331
+ /**
332
+ * Time Complexity: O(L), where L is the length of the path.
333
+ * Space Complexity: O(1) - Constant space.
334
+ *
261
335
  * The function calculates the sum of weights along a given path.
262
336
  * @param {VO[]} path - An array of vertices (VO) representing a path in a graph.
263
337
  * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
@@ -271,6 +345,14 @@ export abstract class AbstractGraph<
271
345
  }
272
346
 
273
347
  /**
348
+ * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
349
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
350
+ */
351
+
352
+ /**
353
+ * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
354
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
355
+ *
274
356
  * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
275
357
  * weights or using a breadth-first search algorithm.
276
358
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
@@ -330,6 +412,14 @@ export abstract class AbstractGraph<
330
412
  }
331
413
 
332
414
  /**
415
+ * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
416
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
417
+ */
418
+
419
+ /**
420
+ * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
421
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
422
+ *
333
423
  * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
334
424
  * using a breadth-first search algorithm.
335
425
  * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
@@ -398,11 +488,18 @@ export abstract class AbstractGraph<
398
488
  }
399
489
 
400
490
  /**
401
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
491
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
402
492
  * /
403
493
 
404
494
  /**
405
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
495
+ * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
496
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
497
+ */
498
+
499
+ /**
500
+ * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
501
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
502
+ *
406
503
  * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
407
504
  * a graph without using a heap data structure.
408
505
  * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
@@ -533,7 +630,7 @@ export abstract class AbstractGraph<
533
630
  }
534
631
 
535
632
  /**
536
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
633
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
537
634
  *
538
635
  * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
539
636
  * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
@@ -542,6 +639,14 @@ export abstract class AbstractGraph<
542
639
  * /
543
640
 
544
641
  /**
642
+ * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
643
+ * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
644
+ */
645
+
646
+ /**
647
+ * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
648
+ * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
649
+ *
545
650
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
546
651
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
547
652
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
@@ -670,12 +775,15 @@ export abstract class AbstractGraph<
670
775
  }
671
776
 
672
777
  /**
673
- * BellmanFord time:O(VE) space:O(VO)
778
+ * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
779
+ * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
674
780
  * one to rest pairs
675
781
  * /
676
782
 
677
783
  /**
678
- * BellmanFord time:O(VE) space:O(VO)
784
+ * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
785
+ * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
786
+ *
679
787
  * one to rest pairs
680
788
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
681
789
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
@@ -795,13 +903,18 @@ export abstract class AbstractGraph<
795
903
  */
796
904
 
797
905
  /**
798
- * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
906
+ * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
907
+ * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
908
+ * Not support graph with negative weight cycle
799
909
  * all pairs
800
910
  * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
801
911
  * /
802
912
 
803
913
  /**
804
- * Floyd algorithm time: O(VO^3) space: O(VO^2), not support graph with negative weight cycle
914
+ * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
915
+ * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
916
+ *
917
+ * Not support graph with negative weight cycle
805
918
  * all pairs
806
919
  * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
807
920
  * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
@@ -847,6 +960,8 @@ export abstract class AbstractGraph<
847
960
  }
848
961
 
849
962
  /**
963
+ * Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
964
+ * Space Complexity: O(V) - Linear space (Tarjan's algorithm).
850
965
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
851
966
  * Tarjan can find cycles in directed or undirected graph
852
967
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
@@ -855,6 +970,9 @@ export abstract class AbstractGraph<
855
970
  * /
856
971
 
857
972
  /**
973
+ * Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
974
+ * Space Complexity: O(V) - Linear space (Tarjan's algorithm).
975
+ *
858
976
  * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
859
977
  * Tarjan can find cycles in directed or undirected graph
860
978
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
@@ -983,6 +1101,14 @@ export abstract class AbstractGraph<
983
1101
  }
984
1102
 
985
1103
  /**
1104
+ * Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
1105
+ * Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
1106
+ */
1107
+
1108
+ /**
1109
+ * Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
1110
+ * Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
1111
+ *
986
1112
  * The function returns a map that associates each vertex object with its corresponding depth-first
987
1113
  * number.
988
1114
  * @returns A Map object with keys of type VO and values of type number.