min-heap-typed 1.50.1 → 1.50.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.
Files changed (85) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +120 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
  4. package/dist/data-structures/binary-tree/avl-tree.js +101 -72
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  6. package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  8. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  9. package/dist/data-structures/binary-tree/bst.d.ts +92 -79
  10. package/dist/data-structures/binary-tree/bst.js +68 -76
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
  12. package/dist/data-structures/binary-tree/rb-tree.js +152 -99
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
  14. package/dist/data-structures/binary-tree/segment-tree.js +127 -10
  15. package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  16. package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
  17. package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
  18. package/dist/data-structures/graph/abstract-graph.js +3 -189
  19. package/dist/data-structures/graph/directed-graph.d.ts +73 -0
  20. package/dist/data-structures/graph/directed-graph.js +131 -0
  21. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  22. package/dist/data-structures/graph/map-graph.js +14 -0
  23. package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
  24. package/dist/data-structures/graph/undirected-graph.js +151 -18
  25. package/dist/data-structures/hash/hash-map.d.ts +254 -28
  26. package/dist/data-structures/hash/hash-map.js +347 -78
  27. package/dist/data-structures/heap/heap.d.ts +95 -25
  28. package/dist/data-structures/heap/heap.js +95 -26
  29. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  30. package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
  31. package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  32. package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
  33. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  34. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  35. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  36. package/dist/data-structures/matrix/matrix.js +50 -11
  37. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  38. package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
  39. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  40. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
  41. package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
  42. package/dist/data-structures/priority-queue/priority-queue.js +8 -0
  43. package/dist/data-structures/queue/deque.d.ts +139 -35
  44. package/dist/data-structures/queue/deque.js +200 -62
  45. package/dist/data-structures/queue/queue.d.ts +103 -49
  46. package/dist/data-structures/queue/queue.js +111 -49
  47. package/dist/data-structures/stack/stack.d.ts +51 -21
  48. package/dist/data-structures/stack/stack.js +58 -22
  49. package/dist/data-structures/tree/tree.d.ts +57 -3
  50. package/dist/data-structures/tree/tree.js +77 -11
  51. package/dist/data-structures/trie/trie.d.ts +135 -34
  52. package/dist/data-structures/trie/trie.js +153 -33
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  54. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  55. package/dist/types/utils/utils.d.ts +1 -0
  56. package/package.json +2 -2
  57. package/src/data-structures/base/iterable-base.ts +184 -19
  58. package/src/data-structures/binary-tree/avl-tree.ts +134 -100
  59. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  60. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  61. package/src/data-structures/binary-tree/bst.ts +127 -136
  62. package/src/data-structures/binary-tree/rb-tree.ts +199 -166
  63. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  64. package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
  65. package/src/data-structures/graph/abstract-graph.ts +4 -211
  66. package/src/data-structures/graph/directed-graph.ts +152 -0
  67. package/src/data-structures/graph/map-graph.ts +15 -0
  68. package/src/data-structures/graph/undirected-graph.ts +171 -19
  69. package/src/data-structures/hash/hash-map.ts +389 -96
  70. package/src/data-structures/heap/heap.ts +97 -26
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
  72. package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
  73. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  74. package/src/data-structures/matrix/matrix.ts +52 -12
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  77. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  78. package/src/data-structures/queue/deque.ts +225 -70
  79. package/src/data-structures/queue/queue.ts +118 -49
  80. package/src/data-structures/stack/stack.ts +63 -23
  81. package/src/data-structures/tree/tree.ts +89 -15
  82. package/src/data-structures/trie/trie.ts +173 -38
  83. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  84. package/src/types/data-structures/hash/hash-map.ts +4 -3
  85. package/src/types/utils/utils.ts +2 -0
@@ -19,10 +19,28 @@ import { IterableElementBase } from '../base';
19
19
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
20
20
  */
21
21
  export declare class Heap<E = any> extends IterableElementBase<E> {
22
+ /**
23
+ * The constructor initializes a heap data structure with optional elements and options.
24
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
25
+ * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
26
+ * be initialized as empty.
27
+ * @param [options] - The `options` parameter is an optional object that can contain additional
28
+ * configuration options for the heap. In this case, it is used to specify a custom comparator
29
+ * function for comparing elements in the heap. The comparator function is used to determine the
30
+ * order of elements in the heap.
31
+ */
22
32
  constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
23
33
  protected _comparator: (a: E, b: E) => number;
34
+ /**
35
+ * The function returns the value of the _comparator property.
36
+ * @returns The `_comparator` property is being returned.
37
+ */
24
38
  get comparator(): (a: E, b: E) => number;
25
39
  protected _elements: E[];
40
+ /**
41
+ * The function returns an array of elements.
42
+ * @returns The elements array is being returned.
43
+ */
26
44
  get elements(): E[];
27
45
  /**
28
46
  * Get the size (number of elements) of the heap.
@@ -43,11 +61,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
43
61
  comparator: Comparator<E>;
44
62
  }): Heap<E>;
45
63
  /**
46
- * Time Complexity: O(log n), where n is the number of elements in the heap.
64
+ * Time Complexity: O(log n)
47
65
  * Space Complexity: O(1)
66
+ * where n is the number of elements in the heap.
48
67
  */
49
68
  /**
50
- * Time Complexity: O(log n), where n is the number of elements in the heap.
69
+ * Time Complexity: O(log n)
51
70
  * Space Complexity: O(1)
52
71
  *
53
72
  * Insert an element into the heap and maintain the heap properties.
@@ -55,11 +74,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
55
74
  */
56
75
  add(element: E): boolean;
57
76
  /**
58
- * Time Complexity: O(log n), where n is the number of elements in the heap.
77
+ * Time Complexity: O(log n)
59
78
  * Space Complexity: O(1)
79
+ * where n is the number of elements in the heap.
60
80
  */
61
81
  /**
62
- * Time Complexity: O(log n), where n is the number of elements in the heap.
82
+ * Time Complexity: O(log n)
63
83
  * Space Complexity: O(1)
64
84
  *
65
85
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -67,6 +87,13 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
67
87
  */
68
88
  poll(): E | undefined;
69
89
  /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ */
93
+ /**
94
+ * Time Complexity: O(1)
95
+ * Space Complexity: O(1)
96
+ *
70
97
  * Peek at the top element of the heap without removing it.
71
98
  * @returns The top element or undefined if the heap is empty.
72
99
  */
@@ -81,11 +108,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
81
108
  */
82
109
  clear(): void;
83
110
  /**
84
- * Time Complexity: O(n), where n is the number of elements in the elements array.
111
+ * Time Complexity: O(n)
85
112
  * Space Complexity: O(n)
86
113
  */
87
114
  /**
88
- * Time Complexity: O(n), where n is the number of elements in the elements array.
115
+ * Time Complexity: O(n)
89
116
  * Space Complexity: O(n)
90
117
  *
91
118
  * Clear and add elements of the heap
@@ -93,11 +120,11 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
93
120
  */
94
121
  refill(elements: E[]): boolean[];
95
122
  /**
96
- * Time Complexity: O(n), where n is the number of elements in the heap.
123
+ * Time Complexity: O(n)
97
124
  * Space Complexity: O(1)
98
125
  */
99
126
  /**
100
- * Time Complexity: O(n), where n is the number of elements in the heap.
127
+ * Time Complexity: O(n)
101
128
  * Space Complexity: O(1)
102
129
  *
103
130
  * Use a comparison function to check whether a binary heap contains a specific element.
@@ -106,11 +133,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
106
133
  */
107
134
  has(element: E): boolean;
108
135
  /**
109
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
136
+ * Time Complexity: O(n)
110
137
  * Space Complexity: O(1)
138
+ * The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
111
139
  */
112
140
  /**
113
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
141
+ * Time Complexity: O(n)
114
142
  * Space Complexity: O(1)
115
143
  *
116
144
  * The `delete` function removes an element from an array-like data structure, maintaining the order
@@ -122,12 +150,13 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
122
150
  */
123
151
  delete(element: E): boolean;
124
152
  /**
125
- * Time Complexity: O(n), where n is the number of elements in the heap.
126
- * Space Complexity: O(h), where h is the height of the heap.
153
+ * Time Complexity: O(n)
154
+ * Space Complexity: O(log n)
155
+ * where log n is the height of the heap.
127
156
  */
128
157
  /**
129
- * Time Complexity: O(n), where n is the number of elements in the heap.
130
- * Space Complexity: O(h), where h is the height of the heap.
158
+ * Time Complexity: O(n)
159
+ * Space Complexity: O(log n)
131
160
  *
132
161
  * Depth-first search (DFS) method, different traversal orders can be selected。
133
162
  * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
@@ -171,12 +200,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
171
200
  */
172
201
  sort(): E[];
173
202
  /**
174
- * Time Complexity: O(log n)
175
- * Space Complexity: O(1)
203
+ * Time Complexity: O(n log n)
204
+ * Space Complexity: O(n)
176
205
  */
177
206
  /**
178
- * Time Complexity: O(n)
179
- * Space Complexity: O(1)
207
+ * Time Complexity: O(n log n)
208
+ * Space Complexity: O(n)
180
209
  *
181
210
  * Fix the entire heap to maintain heap properties.
182
211
  */
@@ -227,9 +256,12 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
227
256
  * original Heap.
228
257
  */
229
258
  map<T>(callback: ElementCallback<E, T>, comparator: Comparator<T>, thisArg?: any): Heap<T>;
259
+ /**
260
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
261
+ */
230
262
  protected _getIterator(): IterableIterator<E>;
231
263
  /**
232
- * Time Complexity: O(n)
264
+ * Time Complexity: O(log n)
233
265
  * Space Complexity: O(1)
234
266
  */
235
267
  /**
@@ -240,6 +272,10 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
240
272
  * @param index - The index of the newly added element.
241
273
  */
242
274
  protected _bubbleUp(index: number): boolean;
275
+ /**
276
+ * Time Complexity: O(log n)
277
+ * Space Complexity: O(1)
278
+ */
243
279
  /**
244
280
  * Time Complexity: O(log n)
245
281
  * Space Complexity: O(1)
@@ -258,17 +294,51 @@ export declare class FibonacciHeapNode<E> {
258
294
  child?: FibonacciHeapNode<E>;
259
295
  parent?: FibonacciHeapNode<E>;
260
296
  marked: boolean;
297
+ /**
298
+ * The constructor function initializes an object with an element and a degree, and sets the marked
299
+ * property to false.
300
+ * @param {E} element - The "element" parameter represents the value or data that will be stored in
301
+ * the node of a data structure. It can be any type of data, such as a number, string, object, or
302
+ * even another data structure.
303
+ * @param [degree=0] - The degree parameter represents the degree of the element in a data structure
304
+ * called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
305
+ * degree is set to 0 when a new node is created.
306
+ */
261
307
  constructor(element: E, degree?: number);
262
308
  }
263
309
  export declare class FibonacciHeap<E> {
310
+ /**
311
+ * The constructor function initializes a FibonacciHeap object with an optional comparator function.
312
+ * @param [comparator] - The `comparator` parameter is an optional argument that represents a
313
+ * function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
314
+ * will be used to determine the order of elements in the heap. If no comparator function is
315
+ * provided, a default comparator function will be used.
316
+ */
264
317
  constructor(comparator?: Comparator<E>);
265
318
  protected _root?: FibonacciHeapNode<E>;
319
+ /**
320
+ * The function returns the root node of a Fibonacci heap.
321
+ * @returns The method is returning either a FibonacciHeapNode object or undefined.
322
+ */
266
323
  get root(): FibonacciHeapNode<E> | undefined;
267
324
  protected _size: number;
325
+ /**
326
+ * The function returns the size of an object.
327
+ * @returns The size of the object, which is a number.
328
+ */
268
329
  get size(): number;
269
330
  protected _min?: FibonacciHeapNode<E>;
331
+ /**
332
+ * The function returns the minimum node in a Fibonacci heap.
333
+ * @returns The method is returning the minimum node of the Fibonacci heap, which is of type
334
+ * `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
335
+ */
270
336
  get min(): FibonacciHeapNode<E> | undefined;
271
337
  protected _comparator: Comparator<E>;
338
+ /**
339
+ * The function returns the comparator used for comparing elements.
340
+ * @returns The `_comparator` property of the object.
341
+ */
272
342
  get comparator(): Comparator<E>;
273
343
  /**
274
344
  * Get the size (number of elements) of the heap.
@@ -337,11 +407,11 @@ export declare class FibonacciHeap<E> {
337
407
  */
338
408
  mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void;
339
409
  /**
340
- * Time Complexity: O(log n), where n is the number of elements in the heap.
410
+ * Time Complexity: O(log n)
341
411
  * Space Complexity: O(1)
342
412
  */
343
413
  /**
344
- * Time Complexity: O(log n), where n is the number of elements in the heap.
414
+ * Time Complexity: O(log n)
345
415
  * Space Complexity: O(1)
346
416
  *
347
417
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -349,11 +419,11 @@ export declare class FibonacciHeap<E> {
349
419
  */
350
420
  poll(): E | undefined;
351
421
  /**
352
- * Time Complexity: O(log n), where n is the number of elements in the heap.
422
+ * Time Complexity: O(log n)
353
423
  * Space Complexity: O(1)
354
424
  */
355
425
  /**
356
- * Time Complexity: O(log n), where n is the number of elements in the heap.
426
+ * Time Complexity: O(log n)
357
427
  * Space Complexity: O(1)
358
428
  *
359
429
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -425,11 +495,11 @@ export declare class FibonacciHeap<E> {
425
495
  */
426
496
  protected _link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
427
497
  /**
428
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
498
+ * Time Complexity: O(n log n)
429
499
  * Space Complexity: O(n)
430
500
  */
431
501
  /**
432
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
502
+ * Time Complexity: O(n log n)
433
503
  * Space Complexity: O(n)
434
504
  *
435
505
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -21,6 +21,16 @@ const base_1 = require("../base");
21
21
  * 8. Graph Algorithms: Such as Dijkstra's shortest path algorithm and Prim's minimum spanning tree algorithm, which use heaps to improve performance.
22
22
  */
23
23
  class Heap extends base_1.IterableElementBase {
24
+ /**
25
+ * The constructor initializes a heap data structure with optional elements and options.
26
+ * @param elements - The `elements` parameter is an iterable object that contains the initial
27
+ * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
28
+ * be initialized as empty.
29
+ * @param [options] - The `options` parameter is an optional object that can contain additional
30
+ * configuration options for the heap. In this case, it is used to specify a custom comparator
31
+ * function for comparing elements in the heap. The comparator function is used to determine the
32
+ * order of elements in the heap.
33
+ */
24
34
  constructor(elements = [], options) {
25
35
  super();
26
36
  this._comparator = (a, b) => {
@@ -41,12 +51,19 @@ class Heap extends base_1.IterableElementBase {
41
51
  for (const el of elements) {
42
52
  this.add(el);
43
53
  }
44
- // this.fix();
45
54
  }
46
55
  }
56
+ /**
57
+ * The function returns the value of the _comparator property.
58
+ * @returns The `_comparator` property is being returned.
59
+ */
47
60
  get comparator() {
48
61
  return this._comparator;
49
62
  }
63
+ /**
64
+ * The function returns an array of elements.
65
+ * @returns The elements array is being returned.
66
+ */
50
67
  get elements() {
51
68
  return this._elements;
52
69
  }
@@ -74,11 +91,12 @@ class Heap extends base_1.IterableElementBase {
74
91
  return new Heap(elements, options);
75
92
  }
76
93
  /**
77
- * Time Complexity: O(log n), where n is the number of elements in the heap.
94
+ * Time Complexity: O(log n)
78
95
  * Space Complexity: O(1)
96
+ * where n is the number of elements in the heap.
79
97
  */
80
98
  /**
81
- * Time Complexity: O(log n), where n is the number of elements in the heap.
99
+ * Time Complexity: O(log n)
82
100
  * Space Complexity: O(1)
83
101
  *
84
102
  * Insert an element into the heap and maintain the heap properties.
@@ -89,11 +107,12 @@ class Heap extends base_1.IterableElementBase {
89
107
  return this._bubbleUp(this.elements.length - 1);
90
108
  }
91
109
  /**
92
- * Time Complexity: O(log n), where n is the number of elements in the heap.
110
+ * Time Complexity: O(log n)
93
111
  * Space Complexity: O(1)
112
+ * where n is the number of elements in the heap.
94
113
  */
95
114
  /**
96
- * Time Complexity: O(log n), where n is the number of elements in the heap.
115
+ * Time Complexity: O(log n)
97
116
  * Space Complexity: O(1)
98
117
  *
99
118
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -111,6 +130,13 @@ class Heap extends base_1.IterableElementBase {
111
130
  return value;
112
131
  }
113
132
  /**
133
+ * Time Complexity: O(1)
134
+ * Space Complexity: O(1)
135
+ */
136
+ /**
137
+ * Time Complexity: O(1)
138
+ * Space Complexity: O(1)
139
+ *
114
140
  * Peek at the top element of the heap without removing it.
115
141
  * @returns The top element or undefined if the heap is empty.
116
142
  */
@@ -131,11 +157,11 @@ class Heap extends base_1.IterableElementBase {
131
157
  this._elements = [];
132
158
  }
133
159
  /**
134
- * Time Complexity: O(n), where n is the number of elements in the elements array.
160
+ * Time Complexity: O(n)
135
161
  * Space Complexity: O(n)
136
162
  */
137
163
  /**
138
- * Time Complexity: O(n), where n is the number of elements in the elements array.
164
+ * Time Complexity: O(n)
139
165
  * Space Complexity: O(n)
140
166
  *
141
167
  * Clear and add elements of the heap
@@ -146,11 +172,11 @@ class Heap extends base_1.IterableElementBase {
146
172
  return this.fix();
147
173
  }
148
174
  /**
149
- * Time Complexity: O(n), where n is the number of elements in the heap.
175
+ * Time Complexity: O(n)
150
176
  * Space Complexity: O(1)
151
177
  */
152
178
  /**
153
- * Time Complexity: O(n), where n is the number of elements in the heap.
179
+ * Time Complexity: O(n)
154
180
  * Space Complexity: O(1)
155
181
  *
156
182
  * Use a comparison function to check whether a binary heap contains a specific element.
@@ -161,11 +187,12 @@ class Heap extends base_1.IterableElementBase {
161
187
  return this.elements.includes(element);
162
188
  }
163
189
  /**
164
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
190
+ * Time Complexity: O(n)
165
191
  * Space Complexity: O(1)
192
+ * The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
166
193
  */
167
194
  /**
168
- * Time Complexity: O(n). The worst-case O(n), where n is the number of elements in the heap. This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
195
+ * Time Complexity: O(n)
169
196
  * Space Complexity: O(1)
170
197
  *
171
198
  * The `delete` function removes an element from an array-like data structure, maintaining the order
@@ -193,12 +220,13 @@ class Heap extends base_1.IterableElementBase {
193
220
  return true;
194
221
  }
195
222
  /**
196
- * Time Complexity: O(n), where n is the number of elements in the heap.
197
- * Space Complexity: O(h), where h is the height of the heap.
223
+ * Time Complexity: O(n)
224
+ * Space Complexity: O(log n)
225
+ * where log n is the height of the heap.
198
226
  */
199
227
  /**
200
- * Time Complexity: O(n), where n is the number of elements in the heap.
201
- * Space Complexity: O(h), where h is the height of the heap.
228
+ * Time Complexity: O(n)
229
+ * Space Complexity: O(log n)
202
230
  *
203
231
  * Depth-first search (DFS) method, different traversal orders can be selected。
204
232
  * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
@@ -282,12 +310,12 @@ class Heap extends base_1.IterableElementBase {
282
310
  return visitedNode;
283
311
  }
284
312
  /**
285
- * Time Complexity: O(log n)
286
- * Space Complexity: O(1)
313
+ * Time Complexity: O(n log n)
314
+ * Space Complexity: O(n)
287
315
  */
288
316
  /**
289
- * Time Complexity: O(n)
290
- * Space Complexity: O(1)
317
+ * Time Complexity: O(n log n)
318
+ * Space Complexity: O(n)
291
319
  *
292
320
  * Fix the entire heap to maintain heap properties.
293
321
  */
@@ -361,13 +389,16 @@ class Heap extends base_1.IterableElementBase {
361
389
  }
362
390
  return mappedHeap;
363
391
  }
392
+ /**
393
+ * The function `_getIterator` returns an iterable iterator for the elements in the class.
394
+ */
364
395
  *_getIterator() {
365
396
  for (const element of this.elements) {
366
397
  yield element;
367
398
  }
368
399
  }
369
400
  /**
370
- * Time Complexity: O(n)
401
+ * Time Complexity: O(log n)
371
402
  * Space Complexity: O(1)
372
403
  */
373
404
  /**
@@ -390,6 +421,10 @@ class Heap extends base_1.IterableElementBase {
390
421
  this.elements[index] = element;
391
422
  return true;
392
423
  }
424
+ /**
425
+ * Time Complexity: O(log n)
426
+ * Space Complexity: O(1)
427
+ */
393
428
  /**
394
429
  * Time Complexity: O(log n)
395
430
  * Space Complexity: O(1)
@@ -419,6 +454,16 @@ class Heap extends base_1.IterableElementBase {
419
454
  }
420
455
  exports.Heap = Heap;
421
456
  class FibonacciHeapNode {
457
+ /**
458
+ * The constructor function initializes an object with an element and a degree, and sets the marked
459
+ * property to false.
460
+ * @param {E} element - The "element" parameter represents the value or data that will be stored in
461
+ * the node of a data structure. It can be any type of data, such as a number, string, object, or
462
+ * even another data structure.
463
+ * @param [degree=0] - The degree parameter represents the degree of the element in a data structure
464
+ * called a Fibonacci heap. The degree of a node is the number of children it has. By default, the
465
+ * degree is set to 0 when a new node is created.
466
+ */
422
467
  constructor(element, degree = 0) {
423
468
  this.element = element;
424
469
  this.degree = degree;
@@ -427,6 +472,13 @@ class FibonacciHeapNode {
427
472
  }
428
473
  exports.FibonacciHeapNode = FibonacciHeapNode;
429
474
  class FibonacciHeap {
475
+ /**
476
+ * The constructor function initializes a FibonacciHeap object with an optional comparator function.
477
+ * @param [comparator] - The `comparator` parameter is an optional argument that represents a
478
+ * function used to compare elements in the FibonacciHeap. If a comparator function is provided, it
479
+ * will be used to determine the order of elements in the heap. If no comparator function is
480
+ * provided, a default comparator function will be used.
481
+ */
430
482
  constructor(comparator) {
431
483
  this._size = 0;
432
484
  this.clear();
@@ -435,15 +487,32 @@ class FibonacciHeap {
435
487
  throw new Error('FibonacciHeap constructor: given comparator should be a function.');
436
488
  }
437
489
  }
490
+ /**
491
+ * The function returns the root node of a Fibonacci heap.
492
+ * @returns The method is returning either a FibonacciHeapNode object or undefined.
493
+ */
438
494
  get root() {
439
495
  return this._root;
440
496
  }
497
+ /**
498
+ * The function returns the size of an object.
499
+ * @returns The size of the object, which is a number.
500
+ */
441
501
  get size() {
442
502
  return this._size;
443
503
  }
504
+ /**
505
+ * The function returns the minimum node in a Fibonacci heap.
506
+ * @returns The method is returning the minimum node of the Fibonacci heap, which is of type
507
+ * `FibonacciHeapNode<E>`. If there is no minimum node, it will return `undefined`.
508
+ */
444
509
  get min() {
445
510
  return this._min;
446
511
  }
512
+ /**
513
+ * The function returns the comparator used for comparing elements.
514
+ * @returns The `_comparator` property of the object.
515
+ */
447
516
  get comparator() {
448
517
  return this._comparator;
449
518
  }
@@ -559,11 +628,11 @@ class FibonacciHeap {
559
628
  }
560
629
  }
561
630
  /**
562
- * Time Complexity: O(log n), where n is the number of elements in the heap.
631
+ * Time Complexity: O(log n)
563
632
  * Space Complexity: O(1)
564
633
  */
565
634
  /**
566
- * Time Complexity: O(log n), where n is the number of elements in the heap.
635
+ * Time Complexity: O(log n)
567
636
  * Space Complexity: O(1)
568
637
  *
569
638
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -573,11 +642,11 @@ class FibonacciHeap {
573
642
  return this.pop();
574
643
  }
575
644
  /**
576
- * Time Complexity: O(log n), where n is the number of elements in the heap.
645
+ * Time Complexity: O(log n)
577
646
  * Space Complexity: O(1)
578
647
  */
579
648
  /**
580
- * Time Complexity: O(log n), where n is the number of elements in the heap.
649
+ * Time Complexity: O(log n)
581
650
  * Space Complexity: O(1)
582
651
  *
583
652
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -726,11 +795,11 @@ class FibonacciHeap {
726
795
  y.parent = x;
727
796
  }
728
797
  /**
729
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
798
+ * Time Complexity: O(n log n)
730
799
  * Space Complexity: O(n)
731
800
  */
732
801
  /**
733
- * Time Complexity: O(n log n), where n is the number of elements in the heap.
802
+ * Time Complexity: O(n log n)
734
803
  * Space Complexity: O(n)
735
804
  *
736
805
  * Remove and return the top element (smallest or largest element) from the heap.