min-heap-typed 1.49.5 → 1.49.7

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 (100) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +53 -48
  2. package/dist/data-structures/binary-tree/avl-tree.js +55 -49
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +153 -130
  4. package/dist/data-structures/binary-tree/binary-tree.js +194 -153
  5. package/dist/data-structures/binary-tree/bst.d.ts +83 -71
  6. package/dist/data-structures/binary-tree/bst.js +114 -91
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
  8. package/dist/data-structures/binary-tree/rb-tree.js +62 -59
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  10. package/dist/data-structures/binary-tree/tree-multimap.js +58 -51
  11. package/dist/data-structures/hash/hash-map.d.ts +24 -27
  12. package/dist/data-structures/hash/hash-map.js +35 -35
  13. package/dist/data-structures/hash/index.d.ts +0 -1
  14. package/dist/data-structures/hash/index.js +0 -1
  15. package/dist/data-structures/heap/heap.d.ts +2 -1
  16. package/dist/data-structures/heap/heap.js +13 -13
  17. package/dist/data-structures/heap/max-heap.js +1 -1
  18. package/dist/data-structures/heap/min-heap.js +1 -1
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
  20. package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
  21. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  22. package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
  23. package/dist/data-structures/matrix/matrix.d.ts +2 -7
  24. package/dist/data-structures/matrix/matrix.js +0 -7
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
  26. package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
  27. package/dist/data-structures/priority-queue/priority-queue.js +1 -1
  28. package/dist/data-structures/queue/deque.d.ts +2 -11
  29. package/dist/data-structures/queue/deque.js +9 -13
  30. package/dist/data-structures/queue/queue.d.ts +13 -13
  31. package/dist/data-structures/queue/queue.js +29 -25
  32. package/dist/data-structures/stack/stack.js +2 -3
  33. package/dist/data-structures/trie/trie.d.ts +2 -2
  34. package/dist/data-structures/trie/trie.js +9 -5
  35. package/dist/interfaces/binary-tree.d.ts +3 -3
  36. package/dist/types/common.d.ts +3 -3
  37. package/dist/types/common.js +2 -2
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  40. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  41. package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
  42. package/dist/types/data-structures/hash/index.d.ts +0 -1
  43. package/dist/types/data-structures/hash/index.js +0 -1
  44. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  45. package/dist/types/data-structures/linked-list/index.d.ts +1 -0
  46. package/dist/types/data-structures/linked-list/index.js +1 -0
  47. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  48. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  49. package/dist/types/data-structures/matrix/index.js +1 -0
  50. package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
  51. package/dist/types/data-structures/queue/deque.d.ts +3 -1
  52. package/dist/types/data-structures/trie/trie.d.ts +3 -1
  53. package/package.json +2 -2
  54. package/src/data-structures/binary-tree/avl-tree.ts +58 -53
  55. package/src/data-structures/binary-tree/binary-tree.ts +255 -211
  56. package/src/data-structures/binary-tree/bst.ts +126 -107
  57. package/src/data-structures/binary-tree/rb-tree.ts +66 -64
  58. package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
  59. package/src/data-structures/hash/hash-map.ts +46 -50
  60. package/src/data-structures/hash/index.ts +0 -1
  61. package/src/data-structures/heap/heap.ts +20 -19
  62. package/src/data-structures/heap/max-heap.ts +1 -1
  63. package/src/data-structures/heap/min-heap.ts +1 -1
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  65. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  66. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  67. package/src/data-structures/matrix/matrix.ts +2 -10
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  70. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  71. package/src/data-structures/queue/deque.ts +11 -15
  72. package/src/data-structures/queue/queue.ts +29 -28
  73. package/src/data-structures/stack/stack.ts +3 -6
  74. package/src/data-structures/trie/trie.ts +10 -11
  75. package/src/interfaces/binary-tree.ts +3 -3
  76. package/src/types/common.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  80. package/src/types/data-structures/hash/hash-map.ts +6 -2
  81. package/src/types/data-structures/hash/index.ts +0 -1
  82. package/src/types/data-structures/heap/heap.ts +1 -1
  83. package/src/types/data-structures/linked-list/index.ts +1 -0
  84. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  85. package/src/types/data-structures/matrix/index.ts +1 -0
  86. package/src/types/data-structures/matrix/matrix.ts +7 -1
  87. package/src/types/data-structures/queue/deque.ts +1 -1
  88. package/src/types/data-structures/trie/trie.ts +1 -1
  89. package/dist/data-structures/hash/hash-table.d.ts +0 -108
  90. package/dist/data-structures/hash/hash-table.js +0 -281
  91. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  92. package/dist/types/data-structures/hash/hash-table.js +0 -2
  93. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
  94. package/dist/types/data-structures/matrix/matrix2d.js +0 -2
  95. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
  96. package/dist/types/data-structures/matrix/vector2d.js +0 -2
  97. package/src/data-structures/hash/hash-table.ts +0 -318
  98. package/src/types/data-structures/hash/hash-table.ts +0 -1
  99. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  100. package/src/types/data-structures/matrix/vector2d.ts +0 -1
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
12
12
  height: number;
@@ -23,15 +23,15 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
23
23
  */
24
24
  export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
25
25
  /**
26
- * The constructor function initializes an AVLTree object with optional elements and options.
27
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
28
- * objects. It represents a collection of elements that will be added to the AVL tree during
26
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
27
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
29
29
  * initialization.
30
30
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
31
31
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
32
32
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
33
33
  */
34
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
34
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: AVLTreeOptions<K>);
35
35
  /**
36
36
  * The function creates a new AVL tree node with the specified key and value.
37
37
  * @param {K} key - The key parameter is the key value that will be associated with
@@ -51,25 +51,26 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
51
51
  */
52
52
  createTree(options?: AVLTreeOptions<K>): TREE;
53
53
  /**
54
- * The function checks if an exemplar is an instance of AVLTreeNode.
55
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
56
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
54
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
55
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
56
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
57
57
  */
58
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
58
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
59
59
  /**
60
60
  * The function "isNotNodeInstance" checks if a potential key is a K.
61
61
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
62
62
  * data type.
63
63
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
64
64
  */
65
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
65
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
66
66
  /**
67
- * 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.
68
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
67
+ * Time Complexity: O(log n)
68
+ * Space Complexity: O(1)
69
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
69
70
  */
70
71
  /**
71
- * 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.
72
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
72
+ * Time Complexity: O(log n)
73
+ * Space Complexity: O(1)
73
74
  *
74
75
  * The function overrides the add method of a binary tree node and balances the tree after inserting
75
76
  * a new node.
@@ -79,14 +80,14 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
79
80
  * being added to the binary tree.
80
81
  * @returns The method is returning either the inserted node or undefined.
81
82
  */
82
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
83
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
83
84
  /**
84
- * 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.
85
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
85
+ * Time Complexity: O(log n)
86
+ * Space Complexity: O(1)
86
87
  */
87
88
  /**
88
- * 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.
89
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
89
+ * Time Complexity: O(log n)
90
+ * Space Complexity: O(1)
90
91
  *
91
92
  * The function overrides the delete method of a binary tree, performs the deletion, and then
92
93
  * balances the tree if necessary.
@@ -112,12 +113,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
112
113
  */
113
114
  protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
114
115
  /**
115
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
116
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
116
+ * Time Complexity: O(1)
117
+ * Space Complexity: O(1)
118
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
117
119
  */
118
120
  /**
119
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
120
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
121
+ * Time Complexity: O(1)
122
+ * Space Complexity: O(1)
121
123
  *
122
124
  * The function calculates the balance factor of a node in a binary tree.
123
125
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -126,12 +128,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
126
128
  */
127
129
  protected _balanceFactor(node: N): number;
128
130
  /**
129
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
130
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
131
+ * Time Complexity: O(1)
132
+ * Space Complexity: O(1)
133
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
131
134
  */
132
135
  /**
133
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
134
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
136
+ * Time Complexity: O(1)
137
+ * Space Complexity: O(1)
135
138
  *
136
139
  * The function updates the height of a node in a binary tree based on the heights of its left and
137
140
  * right children.
@@ -139,62 +142,64 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
139
142
  */
140
143
  protected _updateHeight(node: N): void;
141
144
  /**
142
- * 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.
143
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
145
+ * Time Complexity: O(log n)
146
+ * Space Complexity: O(1)
147
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
144
148
  */
145
149
  /**
146
- * 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.
147
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
150
+ * Time Complexity: O(log n)
151
+ * Space Complexity: O(1)
148
152
  *
149
153
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
150
154
  * to restore balance in an AVL tree after inserting a node.
151
155
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
152
156
  * AVL tree that needs to be balanced.
153
157
  */
154
- protected _balancePath(node: N): void;
158
+ protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void;
155
159
  /**
156
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
157
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
160
+ * Time Complexity: O(1)
161
+ * Space Complexity: O(1)
162
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
158
163
  */
159
164
  /**
160
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
161
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
165
+ * Time Complexity: O(1)
166
+ * Space Complexity: O(1)
162
167
  *
163
168
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
164
169
  * @param {N} A - A is a node in a binary tree.
165
170
  */
166
171
  protected _balanceLL(A: N): void;
167
172
  /**
168
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
169
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
173
+ * Time Complexity: O(1)
174
+ * Space Complexity: O(1)
170
175
  */
171
176
  /**
172
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
173
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
177
+ * Time Complexity: O(1)
178
+ * Space Complexity: O(1)
174
179
  *
175
180
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
176
181
  * @param {N} A - A is a node in a binary tree.
177
182
  */
178
183
  protected _balanceLR(A: N): void;
179
184
  /**
180
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
181
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
185
+ * Time Complexity: O(1)
186
+ * Space Complexity: O(1)
182
187
  */
183
188
  /**
184
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
185
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
189
+ * Time Complexity: O(1)
190
+ * Space Complexity: O(1)
186
191
  *
187
192
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
188
193
  * @param {N} A - A is a node in a binary tree.
189
194
  */
190
195
  protected _balanceRR(A: N): void;
191
196
  /**
192
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
193
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(1)
194
199
  */
195
200
  /**
196
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
197
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
201
+ * Time Complexity: O(1)
202
+ * Space Complexity: O(1)
198
203
  *
199
204
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
200
205
  * @param {N} A - A is a node in a binary tree.
@@ -27,18 +27,18 @@ exports.AVLTreeNode = AVLTreeNode;
27
27
  */
28
28
  class AVLTree extends bst_1.BST {
29
29
  /**
30
- * The constructor function initializes an AVLTree object with optional elements and options.
31
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
32
- * objects. It represents a collection of elements that will be added to the AVL tree during
30
+ * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
31
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
32
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
33
33
  * initialization.
34
34
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
35
35
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
36
36
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
37
37
  */
38
- constructor(elements, options) {
38
+ constructor(keysOrNodesOrEntries = [], options) {
39
39
  super([], options);
40
- if (elements)
41
- super.addMany(elements);
40
+ if (keysOrNodesOrEntries)
41
+ super.addMany(keysOrNodesOrEntries);
42
42
  }
43
43
  /**
44
44
  * The function creates a new AVL tree node with the specified key and value.
@@ -63,12 +63,12 @@ class AVLTree extends bst_1.BST {
63
63
  return new AVLTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
64
64
  }
65
65
  /**
66
- * The function checks if an exemplar is an instance of AVLTreeNode.
67
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
68
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
66
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
67
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
68
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
69
69
  */
70
- isNode(exemplar) {
71
- return exemplar instanceof AVLTreeNode;
70
+ isNode(keyOrNodeOrEntry) {
71
+ return keyOrNodeOrEntry instanceof AVLTreeNode;
72
72
  }
73
73
  /**
74
74
  * The function "isNotNodeInstance" checks if a potential key is a K.
@@ -80,12 +80,13 @@ class AVLTree extends bst_1.BST {
80
80
  return !(potentialKey instanceof AVLTreeNode);
81
81
  }
82
82
  /**
83
- * 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.
84
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
83
+ * Time Complexity: O(log n)
84
+ * Space Complexity: O(1)
85
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
85
86
  */
86
87
  /**
87
- * 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.
88
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
88
+ * Time Complexity: O(log n)
89
+ * Space Complexity: O(1)
89
90
  *
90
91
  * The function overrides the add method of a binary tree node and balances the tree after inserting
91
92
  * a new node.
@@ -97,19 +98,19 @@ class AVLTree extends bst_1.BST {
97
98
  */
98
99
  add(keyOrNodeOrEntry, value) {
99
100
  if (keyOrNodeOrEntry === null)
100
- return undefined;
101
+ return false;
101
102
  const inserted = super.add(keyOrNodeOrEntry, value);
102
103
  if (inserted)
103
- this._balancePath(inserted);
104
+ this._balancePath(keyOrNodeOrEntry);
104
105
  return inserted;
105
106
  }
106
107
  /**
107
- * 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.
108
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
108
+ * Time Complexity: O(log n)
109
+ * Space Complexity: O(1)
109
110
  */
110
111
  /**
111
- * 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.
112
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
112
+ * Time Complexity: O(log n)
113
+ * Space Complexity: O(1)
113
114
  *
114
115
  * The function overrides the delete method of a binary tree, performs the deletion, and then
115
116
  * balances the tree if necessary.
@@ -163,12 +164,13 @@ class AVLTree extends bst_1.BST {
163
164
  return undefined;
164
165
  }
165
166
  /**
166
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
167
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
167
+ * Time Complexity: O(1)
168
+ * Space Complexity: O(1)
169
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
168
170
  */
169
171
  /**
170
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
171
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
172
+ * Time Complexity: O(1)
173
+ * Space Complexity: O(1)
172
174
  *
173
175
  * The function calculates the balance factor of a node in a binary tree.
174
176
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -186,12 +188,13 @@ class AVLTree extends bst_1.BST {
186
188
  return node.right.height - node.left.height;
187
189
  }
188
190
  /**
189
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
190
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
191
+ * Time Complexity: O(1)
192
+ * Space Complexity: O(1)
193
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
191
194
  */
192
195
  /**
193
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
194
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
196
+ * Time Complexity: O(1)
197
+ * Space Complexity: O(1)
195
198
  *
196
199
  * The function updates the height of a node in a binary tree based on the heights of its left and
197
200
  * right children.
@@ -210,12 +213,13 @@ class AVLTree extends bst_1.BST {
210
213
  node.height = 1 + Math.max(node.right.height, node.left.height);
211
214
  }
212
215
  /**
213
- * 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.
214
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
216
+ * Time Complexity: O(log n)
217
+ * Space Complexity: O(1)
218
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
215
219
  */
216
220
  /**
217
- * 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.
218
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
221
+ * Time Complexity: O(log n)
222
+ * Space Complexity: O(1)
219
223
  *
220
224
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
221
225
  * to restore balance in an AVL tree after inserting a node.
@@ -223,6 +227,7 @@ class AVLTree extends bst_1.BST {
223
227
  * AVL tree that needs to be balanced.
224
228
  */
225
229
  _balancePath(node) {
230
+ node = this.ensureNode(node);
226
231
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
227
232
  for (let i = 0; i < path.length; i++) {
228
233
  // second O(log n)
@@ -262,12 +267,13 @@ class AVLTree extends bst_1.BST {
262
267
  }
263
268
  }
264
269
  /**
265
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
266
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
270
+ * Time Complexity: O(1)
271
+ * Space Complexity: O(1)
272
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
267
273
  */
268
274
  /**
269
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
270
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
275
+ * Time Complexity: O(1)
276
+ * Space Complexity: O(1)
271
277
  *
272
278
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
273
279
  * @param {N} A - A is a node in a binary tree.
@@ -303,12 +309,12 @@ class AVLTree extends bst_1.BST {
303
309
  this._updateHeight(B);
304
310
  }
305
311
  /**
306
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
307
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
312
+ * Time Complexity: O(1)
313
+ * Space Complexity: O(1)
308
314
  */
309
315
  /**
310
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
311
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
316
+ * Time Complexity: O(1)
317
+ * Space Complexity: O(1)
312
318
  *
313
319
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
314
320
  * @param {N} A - A is a node in a binary tree.
@@ -359,12 +365,12 @@ class AVLTree extends bst_1.BST {
359
365
  C && this._updateHeight(C);
360
366
  }
361
367
  /**
362
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
363
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
368
+ * Time Complexity: O(1)
369
+ * Space Complexity: O(1)
364
370
  */
365
371
  /**
366
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
367
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
372
+ * Time Complexity: O(1)
373
+ * Space Complexity: O(1)
368
374
  *
369
375
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
370
376
  * @param {N} A - A is a node in a binary tree.
@@ -401,12 +407,12 @@ class AVLTree extends bst_1.BST {
401
407
  B && this._updateHeight(B);
402
408
  }
403
409
  /**
404
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
405
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
410
+ * Time Complexity: O(1)
411
+ * Space Complexity: O(1)
406
412
  */
407
413
  /**
408
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
409
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
414
+ * Time Complexity: O(1)
415
+ * Space Complexity: O(1)
410
416
  *
411
417
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
412
418
  * @param {N} A - A is a node in a binary tree.