data-structure-typed 1.18.7 → 1.19.0

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 (269) hide show
  1. package/README.md +208 -419
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +12 -27
  8. package/dist/data-structures/binary-tree/bst.d.ts +66 -90
  9. package/dist/data-structures/binary-tree/bst.js +85 -163
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
  13. package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
  14. package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
  15. package/dist/data-structures/graph/abstract-graph.js +138 -72
  16. package/dist/data-structures/graph/directed-graph.d.ts +104 -101
  17. package/dist/data-structures/graph/directed-graph.js +134 -129
  18. package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
  19. package/dist/data-structures/graph/undirected-graph.js +107 -106
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
  21. package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
  22. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  23. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/data-structures/interfaces/bst.d.ts +4 -5
  25. package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
  26. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  27. package/dist/data-structures/tree/tree.d.ts +1 -4
  28. package/dist/data-structures/tree/tree.js +1 -12
  29. package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
  30. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  31. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  32. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  33. package/dist/data-structures/types/bst.d.ts +1 -1
  34. package/dist/data-structures/types/bst.js +1 -1
  35. package/dist/data-structures/types/directed-graph.js +1 -1
  36. package/dist/data-structures/types/helpers.d.ts +1 -8
  37. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  38. package/dist/data-structures/types/rb-tree.js +1 -1
  39. package/dist/data-structures/types/tree-multiset.d.ts +5 -5
  40. package/dist/utils/index.d.ts +1 -0
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/types/index.d.ts +1 -0
  43. package/dist/utils/types/index.js +1 -0
  44. package/dist/utils/types/validate-type.d.ts +19 -0
  45. package/dist/utils/types/validate-type.js +2 -0
  46. package/dist/utils/utils.d.ts +2 -2
  47. package/dist/utils/utils.js +0 -62
  48. package/dist/utils/validate-type.d.ts +45 -0
  49. package/dist/utils/validate-type.js +58 -0
  50. package/package.json +5 -2
  51. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  52. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  53. package/backup/recursive-type/src/assets/logo.png +0 -0
  54. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  55. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  56. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  57. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  59. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  60. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  64. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  65. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  66. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  67. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  68. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  69. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  70. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  71. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  86. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  87. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  88. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  90. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  91. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  92. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  93. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  96. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  97. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  98. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  99. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  100. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  101. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  102. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  103. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  104. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  105. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  106. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  108. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  109. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  114. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  115. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  116. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  117. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  118. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  119. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  120. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  121. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  122. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  123. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  124. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  125. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  126. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  127. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  128. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  129. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  130. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  131. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  132. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  133. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  134. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  135. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  136. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  137. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  138. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  139. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  140. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  141. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  142. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  143. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  144. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  145. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  146. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  147. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  149. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  150. package/backup/recursive-type/src/index.ts +0 -1
  151. package/backup/recursive-type/src/utils/index.ts +0 -2
  152. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  153. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  154. package/backup/recursive-type/src/utils/utils.ts +0 -78
  155. package/docs/.nojekyll +0 -1
  156. package/docs/assets/highlight.css +0 -92
  157. package/docs/assets/main.js +0 -58
  158. package/docs/assets/search.js +0 -1
  159. package/docs/assets/style.css +0 -1367
  160. package/docs/classes/AVLTree.html +0 -2451
  161. package/docs/classes/AVLTreeNode.html +0 -499
  162. package/docs/classes/AaTree.html +0 -172
  163. package/docs/classes/AbstractBinaryTree.html +0 -2118
  164. package/docs/classes/AbstractBinaryTreeNode.html +0 -524
  165. package/docs/classes/AbstractEdge.html +0 -295
  166. package/docs/classes/AbstractGraph.html +0 -1043
  167. package/docs/classes/AbstractVertex.html +0 -258
  168. package/docs/classes/ArrayDeque.html +0 -439
  169. package/docs/classes/BST.html +0 -2297
  170. package/docs/classes/BSTNode.html +0 -503
  171. package/docs/classes/BTree.html +0 -172
  172. package/docs/classes/BinaryIndexedTree.html +0 -341
  173. package/docs/classes/BinaryTree.html +0 -2133
  174. package/docs/classes/BinaryTreeNode.html +0 -501
  175. package/docs/classes/Character.html +0 -220
  176. package/docs/classes/CoordinateMap.html +0 -483
  177. package/docs/classes/CoordinateSet.html +0 -444
  178. package/docs/classes/Deque.html +0 -975
  179. package/docs/classes/DirectedEdge.html +0 -366
  180. package/docs/classes/DirectedGraph.html +0 -1443
  181. package/docs/classes/DirectedVertex.html +0 -254
  182. package/docs/classes/DoublyLinkedList.html +0 -968
  183. package/docs/classes/DoublyLinkedListNode.html +0 -297
  184. package/docs/classes/HashTable.html +0 -172
  185. package/docs/classes/Heap.html +0 -423
  186. package/docs/classes/HeapItem.html +0 -255
  187. package/docs/classes/Matrix2D.html +0 -502
  188. package/docs/classes/MatrixNTI2D.html +0 -240
  189. package/docs/classes/MaxHeap.html +0 -436
  190. package/docs/classes/MaxPriorityQueue.html +0 -836
  191. package/docs/classes/MinHeap.html +0 -437
  192. package/docs/classes/MinPriorityQueue.html +0 -838
  193. package/docs/classes/Navigator.html +0 -313
  194. package/docs/classes/ObjectDeque.html +0 -455
  195. package/docs/classes/Pair.html +0 -172
  196. package/docs/classes/PriorityQueue.html +0 -760
  197. package/docs/classes/Queue.html +0 -392
  198. package/docs/classes/RBTree.html +0 -2388
  199. package/docs/classes/RBTreeNode.html +0 -516
  200. package/docs/classes/SegmentTree.html +0 -434
  201. package/docs/classes/SegmentTreeNode.html +0 -357
  202. package/docs/classes/SinglyLinkedList.html +0 -788
  203. package/docs/classes/SinglyLinkedListNode.html +0 -270
  204. package/docs/classes/SkipLinkedList.html +0 -172
  205. package/docs/classes/SplayTree.html +0 -172
  206. package/docs/classes/Stack.html +0 -368
  207. package/docs/classes/TreeMap.html +0 -172
  208. package/docs/classes/TreeMultiSet.html +0 -2297
  209. package/docs/classes/TreeMultiSetNode.html +0 -499
  210. package/docs/classes/TreeNode.html +0 -343
  211. package/docs/classes/TreeSet.html +0 -172
  212. package/docs/classes/Trie.html +0 -372
  213. package/docs/classes/TrieNode.html +0 -280
  214. package/docs/classes/TwoThreeTree.html +0 -172
  215. package/docs/classes/UndirectedEdge.html +0 -337
  216. package/docs/classes/UndirectedGraph.html +0 -1210
  217. package/docs/classes/UndirectedVertex.html +0 -254
  218. package/docs/classes/Vector2D.html +0 -805
  219. package/docs/enums/CP.html +0 -181
  220. package/docs/enums/FamilyPosition.html +0 -181
  221. package/docs/enums/LoopType.html +0 -182
  222. package/docs/enums/RBColor.html +0 -174
  223. package/docs/enums/TopologicalProperty.html +0 -181
  224. package/docs/index.html +0 -645
  225. package/docs/interfaces/IAVLTree.html +0 -1378
  226. package/docs/interfaces/IAVLTreeNode.html +0 -405
  227. package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
  228. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
  229. package/docs/interfaces/IAbstractGraph.html +0 -433
  230. package/docs/interfaces/IBST.html +0 -1271
  231. package/docs/interfaces/IBSTNode.html +0 -408
  232. package/docs/interfaces/IDirectedGraph.html +0 -572
  233. package/docs/interfaces/IUNDirectedGraph.html +0 -465
  234. package/docs/modules.html +0 -262
  235. package/docs/types/AVLTreeOptions.html +0 -150
  236. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
  237. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
  238. package/docs/types/AbstractBinaryTreeOptions.html +0 -156
  239. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
  240. package/docs/types/BSTComparator.html +0 -162
  241. package/docs/types/BSTOptions.html +0 -152
  242. package/docs/types/BinaryTreeDeletedResult.html +0 -159
  243. package/docs/types/BinaryTreeNodeId.html +0 -147
  244. package/docs/types/BinaryTreeNodePropertyName.html +0 -147
  245. package/docs/types/BinaryTreeOptions.html +0 -150
  246. package/docs/types/DFSOrderPattern.html +0 -147
  247. package/docs/types/DijkstraResult.html +0 -167
  248. package/docs/types/Direction.html +0 -147
  249. package/docs/types/EdgeId.html +0 -147
  250. package/docs/types/HeapOptions.html +0 -168
  251. package/docs/types/IdObject.html +0 -157
  252. package/docs/types/KeyValObject.html +0 -152
  253. package/docs/types/NavigatorParams.html +0 -181
  254. package/docs/types/NodeOrPropertyName.html +0 -147
  255. package/docs/types/PriorityQueueComparator.html +0 -167
  256. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
  257. package/docs/types/PriorityQueueOptions.html +0 -161
  258. package/docs/types/RBTreeOptions.html +0 -150
  259. package/docs/types/RecursiveAVLTreeNode.html +0 -152
  260. package/docs/types/RecursiveBSTNode.html +0 -152
  261. package/docs/types/RecursiveBinaryTreeNode.html +0 -152
  262. package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
  263. package/docs/types/SegmentTreeNodeVal.html +0 -147
  264. package/docs/types/TopologicalStatus.html +0 -147
  265. package/docs/types/TreeMultiSetOptions.html +0 -152
  266. package/docs/types/Turning.html +0 -147
  267. package/docs/types/VertexId.html +0 -147
  268. package/notes/bst.test.ts +0 -181
  269. package/notes/note.md +0 -34
@@ -6,27 +6,35 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, RecursiveAVLTreeNode } from '../types';
9
+ import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
10
10
  import { IAVLTree, IAVLTreeNode } from '../interfaces';
11
- export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
12
- createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
11
+ export declare class AVLTreeNode<T = any, NEIGHBOR extends AVLTreeNode<T, NEIGHBOR> = AVLTreeNodeNested<T>> extends BSTNode<T, NEIGHBOR> implements IAVLTreeNode<T, NEIGHBOR> {
13
12
  }
14
- export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> implements IAVLTree<N> {
13
+ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {
14
+ /**
15
+ * This is a constructor function for an AVL tree data structure in TypeScript.
16
+ * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
17
+ * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
18
+ * options.
19
+ */
15
20
  constructor(options?: AVLTreeOptions);
16
- createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
17
21
  /**
18
- * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
19
- * balances the tree.
20
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
21
- * update in the AVL tree.
22
- * @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
23
- * `id`. It can be of type `N` (the generic type) or `null`.
24
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
25
- * of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
26
- * to `1`, indicating that the value should be inserted once.
27
- * @returns The method is returning either an N object or null.
22
+ * The function creates a new AVL tree node with the given id and value.
23
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
24
+ * identify each node in the tree.
25
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
26
+ * that will be stored in the node.
27
+ * @returns a new AVLTreeNode object with the specified id and value.
28
+ */
29
+ createNode(id: BinaryTreeNodeId, val?: N['val']): N;
30
+ /**
31
+ * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
32
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
33
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
34
+ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
35
+ * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
28
36
  */
29
- add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
37
+ add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined;
30
38
  /**
31
39
  * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
32
40
  * then balances the tree if necessary.
@@ -40,34 +40,40 @@ var AVLTreeNode = /** @class */ (function (_super) {
40
40
  function AVLTreeNode() {
41
41
  return _super !== null && _super.apply(this, arguments) || this;
42
42
  }
43
- AVLTreeNode.prototype.createNode = function (id, val, count) {
44
- return new AVLTreeNode(id, (val === undefined ? id : val), count);
45
- };
46
43
  return AVLTreeNode;
47
44
  }(bst_1.BSTNode));
48
45
  exports.AVLTreeNode = AVLTreeNode;
49
46
  var AVLTree = /** @class */ (function (_super) {
50
47
  __extends(AVLTree, _super);
48
+ /**
49
+ * This is a constructor function for an AVL tree data structure in TypeScript.
50
+ * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
51
+ * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
52
+ * options.
53
+ */
51
54
  function AVLTree(options) {
52
55
  return _super.call(this, options) || this;
53
56
  }
54
- AVLTree.prototype.createNode = function (id, val, count) {
55
- return new AVLTreeNode(id, (val === undefined ? id : val), count);
57
+ /**
58
+ * The function creates a new AVL tree node with the given id and value.
59
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
60
+ * identify each node in the tree.
61
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
62
+ * that will be stored in the node.
63
+ * @returns a new AVLTreeNode object with the specified id and value.
64
+ */
65
+ AVLTree.prototype.createNode = function (id, val) {
66
+ return new AVLTreeNode(id, val);
56
67
  };
57
68
  /**
58
- * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
59
- * balances the tree.
60
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
61
- * update in the AVL tree.
62
- * @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
63
- * `id`. It can be of type `N` (the generic type) or `null`.
64
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
65
- * of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
66
- * to `1`, indicating that the value should be inserted once.
67
- * @returns The method is returning either an N object or null.
69
+ * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
70
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
71
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
72
+ * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
73
+ * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
68
74
  */
69
- AVLTree.prototype.add = function (id, val, count) {
70
- var inserted = _super.prototype.add.call(this, id, val, count);
75
+ AVLTree.prototype.add = function (id, val) {
76
+ var inserted = _super.prototype.add.call(this, id, val);
71
77
  if (inserted)
72
78
  this.balancePath(inserted);
73
79
  return inserted;
@@ -5,40 +5,26 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeId, RecursiveBinaryTreeNode } from '../types';
9
- import { BinaryTreeOptions } from '../types';
8
+ import type { BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions } from '../types';
10
9
  import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
11
10
  import { IBinaryTree, IBinaryTreeNode } from '../interfaces/binary-tree';
12
- export declare class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
13
- /**
14
- * The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
15
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
16
- * `BinaryTreeNodeId`, which could be a string or a number depending on how you want to identify your nodes.
17
- * @param {T} [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the
18
- * value stored in the node.
19
- * @param {number} [count] - The count parameter is an optional parameter that represents the number of times the value
20
- * appears in the binary tree node.
21
- * @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
22
- */
23
- createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
11
+ export declare class BinaryTreeNode<T = any, NEIGHBOR extends BinaryTreeNode<T, NEIGHBOR> = BinaryTreeNodeNested<T>> extends AbstractBinaryTreeNode<T, NEIGHBOR> implements IBinaryTreeNode<T, NEIGHBOR> {
24
12
  }
25
13
  export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {
26
14
  /**
27
- * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
28
- * isDuplicatedVal based on the provided options.
29
- * @param [options] - An optional object that can contain the following properties:
15
+ * This is a constructor function for a binary tree class that takes an optional options parameter.
16
+ * @param {BinaryTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
17
+ * constructor of the `BinaryTree` class. It allows you to customize the behavior of the binary tree by providing
18
+ * different configuration options.
30
19
  */
31
20
  constructor(options?: BinaryTreeOptions);
32
21
  /**
33
- * The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
34
- * it returns null.
22
+ * The function creates a new binary tree node with an optional value.
35
23
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
36
- * `BinaryTreeNodeId`.
37
- * @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
38
- * or `null`.
39
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
40
- * of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
41
- * @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
24
+ * `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
25
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
26
+ * stored in the node.
27
+ * @returns a new instance of a BinaryTreeNode with the specified id and value.
42
28
  */
43
- createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
29
+ createNode(id: BinaryTreeNodeId, val?: N['val']): N;
44
30
  }
@@ -29,45 +29,30 @@ var BinaryTreeNode = /** @class */ (function (_super) {
29
29
  function BinaryTreeNode() {
30
30
  return _super !== null && _super.apply(this, arguments) || this;
31
31
  }
32
- /**
33
- * The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
34
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
35
- * `BinaryTreeNodeId`, which could be a string or a number depending on how you want to identify your nodes.
36
- * @param {T} [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the
37
- * value stored in the node.
38
- * @param {number} [count] - The count parameter is an optional parameter that represents the number of times the value
39
- * appears in the binary tree node.
40
- * @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
41
- */
42
- BinaryTreeNode.prototype.createNode = function (id, val, count) {
43
- return new BinaryTreeNode(id, (val === undefined ? id : val), count);
44
- };
45
32
  return BinaryTreeNode;
46
33
  }(abstract_binary_tree_1.AbstractBinaryTreeNode));
47
34
  exports.BinaryTreeNode = BinaryTreeNode;
48
35
  var BinaryTree = /** @class */ (function (_super) {
49
36
  __extends(BinaryTree, _super);
50
37
  /**
51
- * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
52
- * isDuplicatedVal based on the provided options.
53
- * @param [options] - An optional object that can contain the following properties:
38
+ * This is a constructor function for a binary tree class that takes an optional options parameter.
39
+ * @param {BinaryTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
40
+ * constructor of the `BinaryTree` class. It allows you to customize the behavior of the binary tree by providing
41
+ * different configuration options.
54
42
  */
55
43
  function BinaryTree(options) {
56
- return _super.call(this) || this;
44
+ return _super.call(this, options) || this;
57
45
  }
58
46
  /**
59
- * The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
60
- * it returns null.
47
+ * The function creates a new binary tree node with an optional value.
61
48
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
62
- * `BinaryTreeNodeId`.
63
- * @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
64
- * or `null`.
65
- * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
66
- * of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
67
- * @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
49
+ * `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
50
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
51
+ * stored in the node.
52
+ * @returns a new instance of a BinaryTreeNode with the specified id and value.
68
53
  */
69
- BinaryTree.prototype.createNode = function (id, val, count) {
70
- return new BinaryTreeNode(id, val === undefined ? id : val, count);
54
+ BinaryTree.prototype.createNode = function (id, val) {
55
+ return new BinaryTreeNode(id, val);
71
56
  };
72
57
  return BinaryTree;
73
58
  }(abstract_binary_tree_1.AbstractBinaryTree));
@@ -5,131 +5,107 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode } from '../types';
9
- import { BinaryTreeDeletedResult, BSTOptions, CP } from '../types';
8
+ import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions } from '../types';
9
+ import { CP } from '../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBST, IBSTNode } from '../interfaces';
12
- export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBSTNode<T, FAMILY> {
13
- /**
14
- * The function creates a new binary search tree node with the specified id, value, and count.
15
- * @param {BinaryTreeNodeId} id - The id parameter is the identifier for the binary tree node. It is used to uniquely
16
- * identify each node in the tree.
17
- * @param {T} [val] - The "val" parameter represents the value that will be stored in the binary tree node. It is an
18
- * optional parameter, meaning it can be omitted when calling the "createNode" function.
19
- * @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary
20
- * search tree node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
21
- * @returns The method is returning a new instance of the BSTNode class, casted as the FAMILY type.
22
- */
23
- createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
12
+ export declare class BSTNode<T = any, NEIGHBOR extends BSTNode<T, NEIGHBOR> = BSTNodeNested<T>> extends BinaryTreeNode<T, NEIGHBOR> implements IBSTNode<T, NEIGHBOR> {
24
13
  }
25
- export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBST<N> {
14
+ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBST<N> {
26
15
  /**
27
- * The constructor function accepts an optional options object and sets the comparator property if provided.
28
- * @param [options] - An optional object that can contain the following properties:
16
+ * The constructor function initializes a binary search tree object with an optional comparator function.
17
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
29
18
  */
30
19
  constructor(options?: BSTOptions);
31
20
  /**
32
- * The function creates a new binary search tree node with the given id, value, and count.
33
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
34
- * `BinaryTreeNodeId`.
35
- * @param {N['val'] | null} [val] - The `val` parameter is the value that will be stored in the node. It can be of any
36
- * type `N['val']` or `null`.
37
- * @param {number} [count] - The `count` parameter is an optional parameter that represents the number of occurrences
38
- * of a particular value in the binary search tree node.
39
- * @returns a new instance of the BSTNode class, casted as type N.
21
+ * The function creates a new binary search tree node with the given id and value.
22
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
23
+ * identify each node in the binary tree.
24
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
25
+ * that will be stored in the node.
26
+ * @returns a new instance of the BSTNode class with the specified id and value.
40
27
  */
41
- createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
28
+ createNode(id: BinaryTreeNodeId, val?: N['val']): N;
42
29
  /**
43
- * The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
44
- * the ID matches, and returns the inserted node.
45
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
46
- * determine the position of the node in the binary search tree.
47
- * @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
48
- * be of type `N` (the generic type) or `null`.
49
- * @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
50
- * the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
51
- * inserted once.
52
- * @returns The method `add` returns a `N` object or `null`.
30
+ * The `add` function adds a new node to a binary tree, ensuring that duplicates are not accepted.
31
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add. It
32
+ * is of type `BinaryTreeNodeId`.
33
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It represents
34
+ * the value associated with the node.
35
+ * @returns The function `add` returns the inserted node (`inserted`) if it was successfully added to the binary tree.
36
+ * If the node was not added (e.g., due to a duplicate ID), it returns `null` or `undefined`.
53
37
  */
54
- add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
38
+ add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined;
55
39
  /**
56
- * The `get` function returns the first node in a binary search tree that matches the given property value or name.
40
+ * The function returns the first node in a binary tree that matches the given property name and value.
57
41
  * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
58
- * generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
42
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
59
43
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
60
- * specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
61
- * `'id'`.
62
- * @returns The method is returning a N object or null.
44
+ * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
45
+ * @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
63
46
  */
64
47
  get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
65
48
  /**
66
49
  * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
67
50
  * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
68
- * @returns The function `lastKey()` returns the ID of the rightmost node in a binary tree. If the comparison between
69
- * the first two elements in the tree is less than, it returns the ID of the rightmost node. If the comparison is
70
- * greater than, it returns the ID of the leftmost node. Otherwise, it also returns the ID of the rightmost node. If
71
- * there are no nodes in
51
+ * @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
52
+ * the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
53
+ * equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
72
54
  */
73
55
  lastKey(): BinaryTreeNodeId;
74
56
  /**
75
- * The `remove` function in this TypeScript code removes a node from a binary search tree and returns information about
76
- * the deleted node and any nodes that need to be balanced.
77
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that needs to be removed
78
- * from the binary search tree.
79
- * @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
80
- * set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
81
- * set to false or not provided, the count of the node will be taken into account and the
82
- * @returns an array of `BSTDeletedResult<N>` objects.
83
- */
84
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
85
- /**
86
- * The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
87
- * option to specify the property name and whether to return only one node.
88
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
89
- * generic type `N`. It represents the property value that you want to search for in the binary search tree.
57
+ * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
58
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
59
+ * `N` type. It represents the property of the binary tree node that you want to compare with.
90
60
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
91
- * specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
92
- * `'id'`.
93
- * @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
94
- * nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
95
- * to false or not provided, the function will return all nodes that match the given nodeProperty.
96
- * @returns an array of N objects.
61
+ * specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
62
+ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
63
+ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
64
+ * is set to `true`, the function will return an array with only one node (if
65
+ * @returns an array of nodes (type N).
97
66
  */
98
67
  getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
99
68
  /**
100
- * The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
101
- * a binary search tree.
102
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node for which you want to
103
- * calculate the lesser sum.
69
+ * The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
70
+ * less than a given node.
71
+ * @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
104
72
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
105
- * specifies the property of the binary tree node to use for calculating the sum. If not provided, it defaults to 'id'.
73
+ * specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
106
74
  * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
107
- * binary search tree that have a property value lesser than the given `id`.
75
+ * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
108
76
  */
109
- lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
77
+ lesserSum(beginNode: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
110
78
  /**
111
- * The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
112
- * that have a greater value than a given node.
113
- * @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
114
- * contains properties such as `id` and `count`.
79
+ * The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
80
+ * have a greater value than a given node.
81
+ * @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
82
+ * `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
115
83
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
116
- * each node should be increased.
117
- * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
118
- * property of the BSTNode to be modified. It can be either 'id' or 'count'. If propertyName is not provided, it
119
- * defaults to 'id'.
84
+ * each greater node should be increased.
85
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
86
+ * specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
87
+ * 'id'.
120
88
  * @returns a boolean value.
121
89
  */
122
- allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
90
+ allGreaterNodesAdd(node: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
91
+ /**
92
+ * Balancing Adjustment:
93
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
94
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
95
+ *
96
+ * Use Cases and Efficiency:
97
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
98
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
99
+ */
123
100
  /**
124
- * The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
125
- * recursive or iterative approach.
126
- * @returns The `balance()` function returns a boolean value.
101
+ * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
102
+ * constructs a balanced binary search tree using either a recursive or iterative approach.
103
+ * @returns The function `perfectlyBalance()` returns a boolean value.
127
104
  */
128
- balance(): boolean;
105
+ perfectlyBalance(): boolean;
129
106
  /**
130
- * The function `isAVLBalanced` checks if a binary search tree is balanced according to the AVL tree property.
131
- * @returns The function `isAVLBalanced()` returns a boolean value. It returns `true` if the binary search tree (BST)
132
- * is balanced according to the AVL tree property, and `false` otherwise.
107
+ * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
108
+ * @returns a boolean value.
133
109
  */
134
110
  isAVLBalanced(): boolean;
135
111
  protected _comparator: BSTComparator;