data-structure-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 (107) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +12 -12
  4. package/benchmark/report.json +106 -106
  5. package/dist/cjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
  6. package/dist/cjs/src/data-structures/binary-tree/avl-tree.js +88 -23
  7. package/dist/cjs/src/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
  9. package/dist/cjs/src/data-structures/binary-tree/binary-tree.js +388 -201
  10. package/dist/cjs/src/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/src/data-structures/binary-tree/bst.d.ts +121 -66
  12. package/dist/cjs/src/data-structures/binary-tree/bst.js +121 -67
  13. package/dist/cjs/src/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
  15. package/dist/cjs/src/data-structures/binary-tree/rb-tree.js +95 -18
  16. package/dist/cjs/src/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
  18. package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
  19. package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
  21. package/dist/cjs/src/data-structures/graph/abstract-graph.js +147 -36
  22. package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/src/data-structures/graph/directed-graph.d.ts +126 -0
  24. package/dist/cjs/src/data-structures/graph/directed-graph.js +126 -0
  25. package/dist/cjs/src/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
  27. package/dist/cjs/src/data-structures/graph/undirected-graph.js +63 -0
  28. package/dist/cjs/src/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/src/data-structures/heap/heap.d.ts +175 -12
  30. package/dist/cjs/src/data-structures/heap/heap.js +175 -12
  31. package/dist/cjs/src/data-structures/heap/heap.js.map +1 -1
  32. package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
  33. package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
  34. package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  35. package/dist/cjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
  36. package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
  37. package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
  39. package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
  40. package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js.map +1 -1
  41. package/dist/cjs/src/data-structures/queue/deque.d.ts +113 -3
  42. package/dist/cjs/src/data-structures/queue/deque.js +113 -3
  43. package/dist/cjs/src/data-structures/queue/deque.js.map +1 -1
  44. package/dist/cjs/src/data-structures/queue/queue.d.ts +87 -0
  45. package/dist/cjs/src/data-structures/queue/queue.js +87 -0
  46. package/dist/cjs/src/data-structures/queue/queue.js.map +1 -1
  47. package/dist/cjs/src/data-structures/stack/stack.d.ts +42 -0
  48. package/dist/cjs/src/data-structures/stack/stack.js +42 -0
  49. package/dist/cjs/src/data-structures/stack/stack.js.map +1 -1
  50. package/dist/cjs/src/data-structures/trie/trie.d.ts +76 -0
  51. package/dist/cjs/src/data-structures/trie/trie.js +76 -1
  52. package/dist/cjs/src/data-structures/trie/trie.js.map +1 -1
  53. package/dist/mjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
  54. package/dist/mjs/src/data-structures/binary-tree/avl-tree.js +88 -23
  55. package/dist/mjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
  56. package/dist/mjs/src/data-structures/binary-tree/binary-tree.js +388 -201
  57. package/dist/mjs/src/data-structures/binary-tree/bst.d.ts +121 -66
  58. package/dist/mjs/src/data-structures/binary-tree/bst.js +121 -67
  59. package/dist/mjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
  60. package/dist/mjs/src/data-structures/binary-tree/rb-tree.js +95 -18
  61. package/dist/mjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
  62. package/dist/mjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
  63. package/dist/mjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
  64. package/dist/mjs/src/data-structures/graph/abstract-graph.js +147 -36
  65. package/dist/mjs/src/data-structures/graph/directed-graph.d.ts +126 -0
  66. package/dist/mjs/src/data-structures/graph/directed-graph.js +126 -0
  67. package/dist/mjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
  68. package/dist/mjs/src/data-structures/graph/undirected-graph.js +63 -0
  69. package/dist/mjs/src/data-structures/heap/heap.d.ts +175 -12
  70. package/dist/mjs/src/data-structures/heap/heap.js +175 -12
  71. package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
  72. package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
  73. package/dist/mjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
  74. package/dist/mjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
  75. package/dist/mjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
  76. package/dist/mjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
  77. package/dist/mjs/src/data-structures/queue/deque.d.ts +113 -3
  78. package/dist/mjs/src/data-structures/queue/deque.js +113 -3
  79. package/dist/mjs/src/data-structures/queue/queue.d.ts +87 -0
  80. package/dist/mjs/src/data-structures/queue/queue.js +87 -0
  81. package/dist/mjs/src/data-structures/stack/stack.d.ts +42 -0
  82. package/dist/mjs/src/data-structures/stack/stack.js +42 -0
  83. package/dist/mjs/src/data-structures/trie/trie.d.ts +76 -0
  84. package/dist/mjs/src/data-structures/trie/trie.js +76 -1
  85. package/dist/umd/data-structure-typed.min.js +1 -1
  86. package/dist/umd/data-structure-typed.min.js.map +1 -1
  87. package/package.json +1 -1
  88. package/src/data-structures/binary-tree/avl-tree.ts +97 -23
  89. package/src/data-structures/binary-tree/binary-tree.ts +419 -204
  90. package/src/data-structures/binary-tree/bst.ts +130 -68
  91. package/src/data-structures/binary-tree/rb-tree.ts +106 -19
  92. package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
  93. package/src/data-structures/graph/abstract-graph.ts +133 -7
  94. package/src/data-structures/graph/directed-graph.ts +145 -1
  95. package/src/data-structures/graph/undirected-graph.ts +72 -0
  96. package/src/data-structures/heap/heap.ts +201 -12
  97. package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
  98. package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
  99. package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
  100. package/src/data-structures/queue/deque.ts +127 -3
  101. package/src/data-structures/queue/queue.ts +99 -0
  102. package/src/data-structures/stack/stack.ts +48 -0
  103. package/src/data-structures/trie/trie.ts +87 -4
  104. package/test/integration/index.html +24 -2
  105. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +19 -2
  106. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
  107. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -1
@@ -32,38 +32,61 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
32
32
  */
33
33
  createNode(key: BTNKey, value?: V): N;
34
34
  /**
35
- * The function overrides the add method of a binary tree node and balances the tree after inserting
36
- * a new node.
37
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can accept either a
38
- * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
39
- * @param [value] - The `value` parameter is the value that you want to assign to the new node that you
40
- * are adding to the binary search tree.
41
- * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
35
+ * 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.
36
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
37
+ */
38
+ /**
39
+ * 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.
40
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
41
+ *
42
+ * The function overrides the add method of a class, adds a key-value pair to a data structure, and
43
+ * balances the structure if necessary.
44
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
45
+ * `BTNKey`, `N`, `null`, or `undefined`.
46
+ * @param {V} [value] - The `value` parameter is the value associated with the key that is being
47
+ * added to the binary search tree.
48
+ * @returns The method is returning either a node (N) or undefined.
42
49
  */
43
50
  add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined;
44
51
  /**
45
- * The function overrides the delete method of a binary tree and balances the tree after deleting a
46
- * node if necessary.
47
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
48
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
49
- * searching for. It can be a specific key value or any other property of the node.
50
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
51
- * value. This value is compared with the `identifier` parameter to determine if the node should be
52
- * included in the result. The `callback` parameter has a default value of
53
- * `this._defaultOneParamCallback`
54
- * @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
52
+ * 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.
53
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
54
+ */
55
+ /**
56
+ * 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.
57
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
58
+ *
59
+ * The function overrides the delete method of a binary tree, performs the deletion, and then
60
+ * balances the tree if necessary.
61
+ * @param identifier - The `identifier` parameter is the value or condition used to identify the
62
+ * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
63
+ * `callback` function.
64
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
65
+ * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
66
+ * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
67
+ * parameter of type `N
68
+ * @returns The method is returning an array of `BiTreeDeleteResult<N>`.
55
69
  */
56
70
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
57
71
  /**
58
- * The function swaps the key, value, and height properties between two nodes in a binary tree.
59
- * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
60
- * with the `destNode`.
61
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
62
- * from the source node (`srcNode`) will be swapped to.
63
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
72
+ * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
73
+ * tree.
74
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
75
+ * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
76
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
77
+ * node where the values from the source node will be swapped to.
78
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
79
+ * if either `srcNode` or `destNode` is undefined.
64
80
  */
65
81
  protected _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined;
66
82
  /**
83
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
84
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
85
+ */
86
+ /**
87
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
88
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
89
+ *
67
90
  * The function calculates the balance factor of a node in a binary tree.
68
91
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
69
92
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
@@ -71,12 +94,26 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
71
94
  */
72
95
  protected _balanceFactor(node: N): number;
73
96
  /**
97
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
98
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
99
+ */
100
+ /**
101
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
102
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
103
+ *
74
104
  * The function updates the height of a node in a binary tree based on the heights of its left and
75
105
  * right children.
76
106
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
77
107
  */
78
108
  protected _updateHeight(node: N): void;
79
109
  /**
110
+ * 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.
111
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
112
+ */
113
+ /**
114
+ * 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.
115
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
116
+ *
80
117
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
81
118
  * to restore balance in an AVL tree after inserting a node.
82
119
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
@@ -84,21 +121,49 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
84
121
  */
85
122
  protected _balancePath(node: N): void;
86
123
  /**
124
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
125
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
126
+ */
127
+ /**
128
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
129
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
130
+ *
87
131
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
88
132
  * @param {N} A - A is a node in a binary tree.
89
133
  */
90
134
  protected _balanceLL(A: N): void;
91
135
  /**
136
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
137
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
138
+ */
139
+ /**
140
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
141
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
142
+ *
92
143
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
93
144
  * @param {N} A - A is a node in a binary tree.
94
145
  */
95
146
  protected _balanceLR(A: N): void;
96
147
  /**
148
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
149
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
150
+ */
151
+ /**
152
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
153
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
154
+ *
97
155
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
98
156
  * @param {N} A - A is a node in a binary tree.
99
157
  */
100
158
  protected _balanceRR(A: N): void;
101
159
  /**
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.
162
+ */
163
+ /**
164
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
165
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
166
+ *
102
167
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
103
168
  * @param {N} A - A is a node in a binary tree.
104
169
  */
@@ -40,13 +40,20 @@ class AVLTree extends bst_1.BST {
40
40
  return new AVLTreeNode(key, value);
41
41
  }
42
42
  /**
43
- * The function overrides the add method of a binary tree node and balances the tree after inserting
44
- * a new node.
45
- * @param {BTNKey | N | undefined} keyOrNode - The `keyOrNode` parameter can accept either a
46
- * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
47
- * @param [value] - The `value` parameter is the value that you want to assign to the new node that you
48
- * are adding to the binary search tree.
49
- * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
43
+ * 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.
44
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
45
+ */
46
+ /**
47
+ * 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.
48
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
49
+ *
50
+ * The function overrides the add method of a class, adds a key-value pair to a data structure, and
51
+ * balances the structure if necessary.
52
+ * @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
53
+ * `BTNKey`, `N`, `null`, or `undefined`.
54
+ * @param {V} [value] - The `value` parameter is the value associated with the key that is being
55
+ * added to the binary search tree.
56
+ * @returns The method is returning either a node (N) or undefined.
50
57
  */
51
58
  add(keyOrNode, value) {
52
59
  if (keyOrNode === null)
@@ -57,16 +64,23 @@ class AVLTree extends bst_1.BST {
57
64
  return inserted;
58
65
  }
59
66
  /**
60
- * The function overrides the delete method of a binary tree and balances the tree after deleting a
61
- * node if necessary.
62
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
63
- * `BTNKey` or a generic type `N`. It represents the property of the node that we are
64
- * searching for. It can be a specific key value or any other property of the node.
65
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
66
- * value. This value is compared with the `identifier` parameter to determine if the node should be
67
- * included in the result. The `callback` parameter has a default value of
68
- * `this._defaultOneParamCallback`
69
- * @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
67
+ * 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.
68
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
69
+ */
70
+ /**
71
+ * 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.
72
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
73
+ *
74
+ * The function overrides the delete method of a binary tree, performs the deletion, and then
75
+ * balances the tree if necessary.
76
+ * @param identifier - The `identifier` parameter is the value or condition used to identify the
77
+ * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
78
+ * `callback` function.
79
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
80
+ * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
81
+ * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
82
+ * parameter of type `N
83
+ * @returns The method is returning an array of `BiTreeDeleteResult<N>`.
70
84
  */
71
85
  delete(identifier, callback = this._defaultOneParamCallback) {
72
86
  if (identifier instanceof AVLTreeNode)
@@ -80,12 +94,14 @@ class AVLTree extends bst_1.BST {
80
94
  return deletedResults;
81
95
  }
82
96
  /**
83
- * The function swaps the key, value, and height properties between two nodes in a binary tree.
84
- * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
85
- * with the `destNode`.
86
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values
87
- * from the source node (`srcNode`) will be swapped to.
88
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
97
+ * The `_swap` function swaps the key, value, and height properties between two nodes in a binary
98
+ * tree.
99
+ * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
100
+ * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
101
+ * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
102
+ * node where the values from the source node will be swapped to.
103
+ * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
104
+ * if either `srcNode` or `destNode` is undefined.
89
105
  */
90
106
  _swap(srcNode, destNode) {
91
107
  srcNode = this.ensureNotKey(srcNode);
@@ -107,6 +123,13 @@ class AVLTree extends bst_1.BST {
107
123
  return undefined;
108
124
  }
109
125
  /**
126
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
127
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
128
+ */
129
+ /**
130
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
131
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
132
+ *
110
133
  * The function calculates the balance factor of a node in a binary tree.
111
134
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
112
135
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
@@ -123,6 +146,13 @@ class AVLTree extends bst_1.BST {
123
146
  return node.right.height - node.left.height;
124
147
  }
125
148
  /**
149
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
150
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
151
+ */
152
+ /**
153
+ * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
154
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
155
+ *
126
156
  * The function updates the height of a node in a binary tree based on the heights of its left and
127
157
  * right children.
128
158
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -140,6 +170,13 @@ class AVLTree extends bst_1.BST {
140
170
  node.height = 1 + Math.max(node.right.height, node.left.height);
141
171
  }
142
172
  /**
173
+ * 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.
174
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
175
+ */
176
+ /**
177
+ * 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.
178
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
179
+ *
143
180
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
144
181
  * to restore balance in an AVL tree after inserting a node.
145
182
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
@@ -185,6 +222,13 @@ class AVLTree extends bst_1.BST {
185
222
  }
186
223
  }
187
224
  /**
225
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
226
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
227
+ */
228
+ /**
229
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
230
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
231
+ *
188
232
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
189
233
  * @param {N} A - A is a node in a binary tree.
190
234
  */
@@ -219,6 +263,13 @@ class AVLTree extends bst_1.BST {
219
263
  this._updateHeight(B);
220
264
  }
221
265
  /**
266
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
267
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
268
+ */
269
+ /**
270
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
271
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
272
+ *
222
273
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
223
274
  * @param {N} A - A is a node in a binary tree.
224
275
  */
@@ -268,6 +319,13 @@ class AVLTree extends bst_1.BST {
268
319
  C && this._updateHeight(C);
269
320
  }
270
321
  /**
322
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
323
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
324
+ */
325
+ /**
326
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
327
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
328
+ *
271
329
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
272
330
  * @param {N} A - A is a node in a binary tree.
273
331
  */
@@ -303,6 +361,13 @@ class AVLTree extends bst_1.BST {
303
361
  B && this._updateHeight(B);
304
362
  }
305
363
  /**
364
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
365
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
366
+ */
367
+ /**
368
+ * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
369
+ * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
370
+ *
306
371
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
307
372
  * @param {N} A - A is a node in a binary tree.
308
373
  */