min-heap-typed 1.42.8 → 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.
- package/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/data-structures/binary-tree/bst.js +121 -67
- package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/data-structures/graph/abstract-graph.js +147 -36
- package/dist/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/data-structures/graph/directed-graph.js +126 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/data-structures/graph/undirected-graph.js +63 -0
- package/dist/data-structures/heap/heap.d.ts +175 -12
- package/dist/data-structures/heap/heap.js +175 -12
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/data-structures/queue/deque.d.ts +113 -3
- package/dist/data-structures/queue/deque.js +113 -3
- package/dist/data-structures/queue/queue.d.ts +87 -0
- package/dist/data-structures/queue/queue.js +87 -0
- package/dist/data-structures/stack/stack.d.ts +42 -0
- package/dist/data-structures/stack/stack.js +42 -0
- package/dist/data-structures/trie/trie.d.ts +76 -0
- package/dist/data-structures/trie/trie.js +76 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +419 -204
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
|
@@ -47,13 +47,21 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
*
|
|
50
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
51
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
56
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
57
|
+
*
|
|
58
|
+
* The function overrides the add method of a class, adds a key-value pair to a data structure, and
|
|
59
|
+
* balances the structure if necessary.
|
|
60
|
+
* @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
|
|
61
|
+
* `BTNKey`, `N`, `null`, or `undefined`.
|
|
62
|
+
* @param {V} [value] - The `value` parameter is the value associated with the key that is being
|
|
63
|
+
* added to the binary search tree.
|
|
64
|
+
* @returns The method is returning either a node (N) or undefined.
|
|
57
65
|
*/
|
|
58
66
|
override add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined {
|
|
59
67
|
if (keyOrNode === null) return undefined;
|
|
@@ -63,16 +71,24 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
75
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
80
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
81
|
+
*
|
|
82
|
+
* The function overrides the delete method of a binary tree, performs the deletion, and then
|
|
83
|
+
* balances the tree if necessary.
|
|
84
|
+
* @param identifier - The `identifier` parameter is the value or condition used to identify the
|
|
85
|
+
* node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
|
|
86
|
+
* `callback` function.
|
|
87
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
88
|
+
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
89
|
+
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
90
|
+
* parameter of type `N
|
|
91
|
+
* @returns The method is returning an array of `BiTreeDeleteResult<N>`.
|
|
76
92
|
*/
|
|
77
93
|
override delete<C extends BTNCallback<N>>(
|
|
78
94
|
identifier: ReturnType<C>,
|
|
@@ -89,12 +105,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
/**
|
|
92
|
-
* The function swaps the key, value, and height properties between two nodes in a binary
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
108
|
+
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
109
|
+
* tree.
|
|
110
|
+
* @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
111
|
+
* needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
|
|
112
|
+
* @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
113
|
+
* node where the values from the source node will be swapped to.
|
|
114
|
+
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
115
|
+
* if either `srcNode` or `destNode` is undefined.
|
|
98
116
|
*/
|
|
99
117
|
protected override _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined {
|
|
100
118
|
srcNode = this.ensureNotKey(srcNode);
|
|
@@ -122,6 +140,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
122
140
|
}
|
|
123
141
|
|
|
124
142
|
/**
|
|
143
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
144
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
149
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
150
|
+
*
|
|
125
151
|
* The function calculates the balance factor of a node in a binary tree.
|
|
126
152
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
127
153
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
@@ -138,6 +164,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
138
164
|
}
|
|
139
165
|
|
|
140
166
|
/**
|
|
167
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
168
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
173
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
174
|
+
*
|
|
141
175
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
142
176
|
* right children.
|
|
143
177
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
@@ -152,6 +186,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
152
186
|
}
|
|
153
187
|
|
|
154
188
|
/**
|
|
189
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
190
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
195
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
196
|
+
*
|
|
155
197
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
156
198
|
* to restore balance in an AVL tree after inserting a node.
|
|
157
199
|
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
@@ -197,6 +239,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
197
239
|
}
|
|
198
240
|
|
|
199
241
|
/**
|
|
242
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
243
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
248
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
249
|
+
*
|
|
200
250
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
201
251
|
* @param {N} A - A is a node in a binary tree.
|
|
202
252
|
*/
|
|
@@ -227,6 +277,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
227
277
|
}
|
|
228
278
|
|
|
229
279
|
/**
|
|
280
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
281
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
286
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
287
|
+
*
|
|
230
288
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
231
289
|
* @param {N} A - A is a node in a binary tree.
|
|
232
290
|
*/
|
|
@@ -275,6 +333,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
275
333
|
}
|
|
276
334
|
|
|
277
335
|
/**
|
|
336
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
337
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
342
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
343
|
+
*
|
|
278
344
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
279
345
|
* @param {N} A - A is a node in a binary tree.
|
|
280
346
|
*/
|
|
@@ -310,6 +376,14 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
310
376
|
}
|
|
311
377
|
|
|
312
378
|
/**
|
|
379
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
380
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
381
|
+
*/
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
385
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
386
|
+
*
|
|
313
387
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
314
388
|
* @param {N} A - A is a node in a binary tree.
|
|
315
389
|
*/
|