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
@@ -5,67 +5,61 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AbstractBinaryTreeNodeProperties, AbstractRecursiveBinaryTreeNode, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../types';
8
+ import type { AbstractBinaryTreeNodeNested, AbstractBinaryTreeNodeProperties, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../types';
9
9
  import { AbstractBinaryTreeOptions, FamilyPosition, LoopType } from '../types';
10
10
  import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from '../interfaces';
11
- export declare abstract class AbstractBinaryTreeNode<T = number, FAMILY extends AbstractBinaryTreeNode<T, FAMILY> = AbstractRecursiveBinaryTreeNode<T>> implements IAbstractBinaryTreeNode<T, FAMILY> {
11
+ export declare abstract class AbstractBinaryTreeNode<T = any, NEIGHBOR extends AbstractBinaryTreeNode<T, NEIGHBOR> = AbstractBinaryTreeNodeNested<T>> implements IAbstractBinaryTreeNode<T, NEIGHBOR> {
12
12
  /**
13
- * The constructor function initializes a BinaryTreeNode object with an id, value, and count.
13
+ * The constructor function initializes a BinaryTreeNode object with an id and an optional value.
14
14
  * @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
15
- * for the binary tree node.
16
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
17
- * tree node. If no value is provided, it will be `undefined`.
18
- * @param {number} [count] - The `count` parameter is an optional parameter that represents the number of times the
19
- * value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
15
+ * of the binary tree node. It is used to distinguish one node from another in the binary tree.
16
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
17
+ * stored in the binary tree node. If no value is provided, it will be set to undefined.
20
18
  */
21
- constructor(id: BinaryTreeNodeId, val?: T, count?: number);
19
+ constructor(id: BinaryTreeNodeId, val?: T);
22
20
  private _id;
23
21
  get id(): BinaryTreeNodeId;
24
22
  set id(v: BinaryTreeNodeId);
25
23
  private _val;
26
24
  get val(): T | undefined;
27
25
  set val(value: T | undefined);
28
- private _left?;
29
- get left(): FAMILY | null | undefined;
30
- set left(v: FAMILY | null | undefined);
31
- private _right?;
32
- get right(): FAMILY | null | undefined;
33
- set right(v: FAMILY | null | undefined);
26
+ private _left;
27
+ get left(): NEIGHBOR | null | undefined;
28
+ set left(v: NEIGHBOR | null | undefined);
29
+ private _right;
30
+ get right(): NEIGHBOR | null | undefined;
31
+ set right(v: NEIGHBOR | null | undefined);
34
32
  private _parent;
35
- get parent(): FAMILY | null | undefined;
36
- set parent(v: FAMILY | null | undefined);
37
- private _familyPosition;
38
- get familyPosition(): FamilyPosition;
39
- set familyPosition(v: FamilyPosition);
40
- private _count;
41
- get count(): number;
42
- set count(v: number);
33
+ get parent(): NEIGHBOR | null | undefined;
34
+ set parent(v: NEIGHBOR | null | undefined);
43
35
  private _height;
44
36
  get height(): number;
45
37
  set height(v: number);
46
- abstract createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
47
- /**
48
- * The function swaps the location of two nodes in a binary tree.
49
- * @param {FAMILY} swapNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
50
- * @returns the `swapNode` object after swapping its properties with the properties of `this` object.
51
- */
52
- swapLocation(swapNode: FAMILY): FAMILY;
53
38
  /**
54
- * The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
55
- * @returns The `clone()` method is returning a new instance of the `FAMILY` class with the same `id`, `val`, and
56
- * `count` values as the current instance.
39
+ * The function determines the position of a node in a family tree structure.
40
+ * @returns a value of type `FamilyPosition`.
57
41
  */
58
- clone(): FAMILY | null;
42
+ get familyPosition(): FamilyPosition;
59
43
  }
60
- export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode<number>> implements IAbstractBinaryTree<N> {
44
+ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode> implements IAbstractBinaryTree<N> {
61
45
  /**
62
46
  * The protected constructor initializes the options for an abstract binary tree.
63
47
  * @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
64
48
  * tree.
65
49
  */
66
50
  protected constructor(options?: AbstractBinaryTreeOptions);
51
+ private _root;
52
+ get root(): N | null;
53
+ private _size;
54
+ get size(): number;
67
55
  private _loopType;
68
56
  get loopType(): LoopType;
57
+ private _autoIncrementId;
58
+ get autoIncrementId(): boolean;
59
+ private _maxId;
60
+ get maxId(): number;
61
+ private _isMergeDuplicatedVal;
62
+ get isMergeDuplicatedVal(): boolean;
69
63
  private _visitedId;
70
64
  get visitedId(): BinaryTreeNodeId[];
71
65
  private _visitedVal;
@@ -76,21 +70,17 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
76
70
  get visitedCount(): number[];
77
71
  private _visitedLeftSum;
78
72
  get visitedLeftSum(): number[];
79
- private _autoIncrementId;
80
- get autoIncrementId(): boolean;
81
- private _maxId;
82
- get maxId(): number;
83
- private _isDuplicatedVal;
84
- get isDuplicatedVal(): boolean;
85
- private _root;
86
- get root(): N | null;
87
- private _size;
88
- get size(): number;
89
- private _count;
90
- get count(): number;
91
- abstract createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
73
+ abstract createNode(id: BinaryTreeNodeId, val?: N['val']): N | null;
74
+ /**
75
+ * The `swapLocation` function swaps the location of two nodes in a binary tree.
76
+ * @param {N} srcNode - The source node that you want to swap with the destination node.
77
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
78
+ * be swapped to.
79
+ * @returns The `destNode` is being returned.
80
+ */
81
+ swapLocation(srcNode: N, destNode: N): N;
92
82
  /**
93
- * The clear function resets the state of an object by setting its properties to their initial values.
83
+ * The clear() function resets the root, size, and maxId properties to their initial values.
94
84
  */
95
85
  clear(): void;
96
86
  /**
@@ -99,126 +89,121 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
99
89
  */
100
90
  isEmpty(): boolean;
101
91
  /**
102
- * The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
103
- * already exists.
104
- * @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
105
- * identify each node in the binary tree.
106
- * @param {N} val - The value to be inserted into the binary tree.
107
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
108
- * value should be inserted into the binary tree. If not provided, it defaults to 1.
109
- * @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
110
- * is inserted, or `undefined` if the insertion fails.
92
+ * The `add` function adds a new node to a binary tree, updating the value of an existing node if it already exists.
93
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
94
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. If no value is
95
+ * provided, the default value will be the same as the `id` parameter.
96
+ * @param {number} [count] - The `count` parameter is an optional number that represents the number of times the value
97
+ * should be added to the binary tree. If not provided, the default value is `undefined`.
98
+ * @returns The function `add` returns either a `BinaryTreeNode` object (`N`), `null`, or `undefined`.
111
99
  */
112
100
  add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
113
101
  /**
114
- * The function adds a new node to a binary tree as the left or right child of a given parent node.
102
+ * The function adds a new node to the left or right child of a parent node, updating the size of the tree if
103
+ * necessary.
115
104
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
116
105
  * either a node object (`N`) or `null`.
117
106
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
118
107
  * child.
119
- * @returns either the left or right child node that was added to the parent node. It can also return `null` or
120
- * `undefined` in certain cases.
108
+ * @returns either the left child node, the right child node, or undefined.
121
109
  */
122
110
  addTo(newNode: N | null, parent: N): N | null | undefined;
123
111
  /**
124
- * The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
112
+ * The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes or
125
113
  * null/undefined values.
126
- * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
127
- * array of `N` objects.
128
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
114
+ * @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of `N` objects or an array of
115
+ * `N['val']` values.
116
+ * @returns The function `addMany` returns an array of values of type `N | null | undefined`.
129
117
  */
130
118
  addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
131
119
  /**
132
- * The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
133
- * was successful.
134
- * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
135
- * array of `N` objects.
136
- * @returns The method is returning a boolean value.
120
+ * The `fill` function clears the current data and adds new data, returning a boolean indicating if the operation was
121
+ * successful.
122
+ * @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of objects or an array of arrays.
123
+ * Each object or array should have a property called `val`.
124
+ * @returns a boolean value.
137
125
  */
138
126
  fill(data: N[] | Array<N['val']>): boolean;
139
127
  /**
140
- * The function removes a node from a binary tree and returns information about the deleted node.
141
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
142
- * It is of type `BinaryTreeNodeId`.
128
+ * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
129
+ * node that needs to be balanced.
130
+ * @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
131
+ * node ID (`BinaryTreeNodeId`).
143
132
  * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
144
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
145
- * not be decremented and the overall count of the binary tree will not be updated. If `
146
- * @returns An array of objects is being returned. Each object in the array has two properties: "deleted" and
147
- * "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
148
- * "needBalanced" property is always null.
133
+ * whether to ignore the count of the nodes in the binary tree. If `ignoreCount` is set to `true`, the count of the
134
+ * nodes in the binary tree will not be updated after removing a node. If `ignoreCount`
135
+ * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
149
136
  */
150
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
137
+ remove(nodeOrId: N | BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
151
138
  /**
152
- * The function calculates the depth of a binary tree node by traversing its parent nodes.
153
- * @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
154
- * meaning it can represent any type of data that we want to store in the node.
155
- * @returns The depth of the given binary tree node.
139
+ * The function calculates the depth of a node in a binary tree.
140
+ * @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
141
+ * @returns the depth of the given node or binary tree.
156
142
  */
157
- getDepth(node: N): number;
143
+ getDepth(beginRoot: N | BinaryTreeNodeId | null): number;
158
144
  /**
159
- * The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
160
- * approach.
161
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
162
- * `N | null`. It represents the starting node from which to calculate the height of the binary tree.
163
- * If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
145
+ * The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
146
+ * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
147
+ * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
148
+ * node), or `null`.
164
149
  * @returns the height of the binary tree.
165
150
  */
166
- getHeight(beginRoot?: N | null): number;
151
+ getHeight(beginRoot?: N | BinaryTreeNodeId | null): number;
167
152
  /**
168
153
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
169
154
  * approach.
170
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
171
- * `N | null`. It represents the starting node from which to calculate the minimum height of the binary
172
- * tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
155
+ * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
156
+ * represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
157
+ * for `beginRoot`, the `this.root` property is used as the default value.
173
158
  * @returns The function `getMinHeight` returns the minimum height of the binary tree.
174
159
  */
175
160
  getMinHeight(beginRoot?: N | null): number;
176
161
  /**
177
- * The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
178
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
179
- * of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
162
+ * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
163
+ * tree.
164
+ * @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
165
+ * tree or null if the tree is empty.
180
166
  * @returns The method is returning a boolean value.
181
167
  */
182
- isBalanced(beginRoot?: N | null): boolean;
168
+ isPerfectlyBalanced(beginRoot?: N | null): boolean;
183
169
  /**
184
- * The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
185
- * searching recursively or iteratively.
170
+ * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
186
171
  * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
187
172
  * generic type `N`. It represents the property of the binary tree node that you want to search for.
188
173
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
189
174
  * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
190
175
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
191
- * return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
192
- * function will stop traversing the tree and return the first matching node. If `
193
- * @returns The function `getNodes` returns an array of `N | null | undefined` objects.
176
+ * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
177
+ * function will stop traversing the tree and return the first matching node. If `only
178
+ * @returns an array of nodes (type N).
194
179
  */
195
180
  getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
196
181
  /**
197
- * The function checks if a binary tree node has a specific property or if any node in the tree has a specific
198
- * property.
199
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
200
- * generic type `N`. It represents the property of a binary tree node that you want to check.
182
+ * The function checks if a binary tree node has a specific property.
183
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
184
+ * It represents the property of the binary tree node that you want to check.
201
185
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
202
- * specifies the name of the property to check for in the nodes.
186
+ * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
203
187
  * @returns a boolean value.
204
188
  */
205
189
  has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
206
190
  /**
207
- * The function returns the first binary tree node that matches the given property name and value, or null if no match
208
- * is found.
209
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
210
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
191
+ * The function returns the first node that matches the given property name and value, or null if no matching node is
192
+ * found.
193
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
194
+ * It represents the property of the binary tree node that you want to search for.
211
195
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
212
- * specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
213
- * @returns a BinaryTreeNode object or null.
196
+ * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
197
+ * default value is set to `'id'`.
198
+ * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
199
+ * If no matching node is found, it returns null.
214
200
  */
215
201
  get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
216
202
  /**
217
- * The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
218
- * root of a binary tree.
219
- * @param node - The `node` parameter is a BinaryTreeNode object.
220
- * @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
221
- * the given `node` to the root of the binary tree.
203
+ * The function getPathToRoot takes a node and returns an array of nodes representing the path from the given node to
204
+ * the root node.
205
+ * @param {N} node - The parameter `node` represents a node in a tree data structure.
206
+ * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
222
207
  */
223
208
  getPathToRoot(node: N): N[];
224
209
  getLeftMost(): N | null;
@@ -226,7 +211,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
226
211
  getRightMost(): N | null;
227
212
  getRightMost(node: N): N;
228
213
  /**
229
- * The function `isBSTByRooted` checks if a binary tree is a binary search tree (BST) by rooted traversal.
214
+ * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
230
215
  * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
231
216
  * @returns a boolean value.
232
217
  */
@@ -239,60 +224,53 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
239
224
  */
240
225
  isBST(node?: N | null): boolean;
241
226
  /**
242
- * The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
243
- * traversal.
244
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
245
- * tree.
246
- * @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
247
- * represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
227
+ * The function calculates the size of a subtree by traversing it either recursively or iteratively.
228
+ * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
229
+ * binary tree.
230
+ * @returns the size of the subtree rooted at `subTreeRoot`.
248
231
  */
249
- getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
232
+ getSubTreeSize(subTreeRoot: N | null | undefined): number;
250
233
  /**
251
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
252
- * iteratively.
253
- * @param subTreeRoot - The subTreeRoot parameter is the root node of the subtree for which you want to calculate the
254
- * sum.
255
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
256
- * specifies the property of the `BinaryTreeNode` object to use for calculating the sum. If `propertyName` is not
257
- * provided, it defaults to `'val'`.
258
- * @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
234
+ * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
235
+ * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
236
+ * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
237
+ * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
238
+ * property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
239
+ * not provided, it defaults to 'id'.
240
+ * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
259
241
  */
260
- subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
242
+ subTreeSum(subTreeRoot: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
261
243
  /**
262
- * The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
263
- * @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
244
+ * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
245
+ * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
246
+ * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
264
247
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
265
- * each node in the subtree should be increased or decreased.
248
+ * each node in the subtree should be incremented.
266
249
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
267
- * specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
268
- * @returns a boolean value, which is `true`.
250
+ * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
251
+ * @returns a boolean value.
269
252
  */
270
- subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
253
+ subTreeAdd(subTreeRoot: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
271
254
  BFS(): BinaryTreeNodeId[];
272
255
  BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
273
256
  BFS(nodeOrPropertyName: 'val'): N['val'][];
274
257
  BFS(nodeOrPropertyName: 'node'): N[];
275
- BFS(nodeOrPropertyName: 'count'): number[];
276
258
  DFS(): BinaryTreeNodeId[];
277
259
  DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
278
260
  DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
279
261
  DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
280
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
281
262
  DFSIterative(): BinaryTreeNodeId[];
282
263
  DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
283
264
  DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
284
265
  DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
285
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
286
266
  levelIterative(node: N | null): BinaryTreeNodeId[];
287
267
  levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
288
268
  levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
289
269
  levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
290
- levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
291
270
  listLevels(node: N | null): BinaryTreeNodeId[][];
292
271
  listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
293
272
  listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
294
273
  listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
295
- listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
296
274
  /**
297
275
  * The function returns the predecessor of a given node in a binary tree.
298
276
  * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
@@ -302,56 +280,109 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
302
280
  morris(): BinaryTreeNodeId[];
303
281
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
304
282
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
283
+ /**
284
+ * Time complexity is O(n)
285
+ * Space complexity of Iterative DFS equals to recursive DFS which is O(n) because of the stack
286
+ */
305
287
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
306
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
288
+ /**
289
+ * The function sets the loop type for a protected variable.
290
+ * @param {LoopType} value - The value parameter is of type LoopType.
291
+ */
307
292
  protected _setLoopType(value: LoopType): void;
293
+ /**
294
+ * The function sets the value of the `_visitedId` property in a protected manner.
295
+ * @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
296
+ */
308
297
  protected _setVisitedId(value: BinaryTreeNodeId[]): void;
298
+ /**
299
+ * The function sets the value of the "_visitedVal" property to the given array.
300
+ * @param value - An array of type N.
301
+ */
309
302
  protected _setVisitedVal(value: Array<N>): void;
303
+ /**
304
+ * The function sets the value of the _visitedNode property.
305
+ * @param {N[]} value - N[] is an array of elements of type N.
306
+ */
310
307
  protected _setVisitedNode(value: N[]): void;
308
+ /**
309
+ * The function sets the value of the visitedCount property.
310
+ * @param {number[]} value - The value parameter is an array of numbers.
311
+ */
311
312
  protected setVisitedCount(value: number[]): void;
313
+ /**
314
+ * The function sets the value of the `_visitedLeftSum` property to the provided array.
315
+ * @param {number[]} value - An array of numbers that represents the visited left sum.
316
+ */
312
317
  protected _setVisitedLeftSum(value: number[]): void;
318
+ /**
319
+ * The function sets the value of the _autoIncrementId property.
320
+ * @param {boolean} value - The value parameter is a boolean that determines whether the id should be automatically
321
+ * incremented or not. If value is true, the id will be automatically incremented. If value is false, the id will not
322
+ * be automatically incremented.
323
+ */
313
324
  protected _setAutoIncrementId(value: boolean): void;
325
+ /**
326
+ * The function sets the maximum ID value.
327
+ * @param {number} value - The value parameter is a number that represents the new maximum ID value.
328
+ */
314
329
  protected _setMaxId(value: number): void;
330
+ /**
331
+ * The function sets the value of a protected property called "_isMergeDuplicatedVal".
332
+ * @param {boolean} value - The value parameter is a boolean value that determines whether the isMergeDuplicatedVal
333
+ * property should be set to true or false.
334
+ */
315
335
  protected _setIsDuplicatedVal(value: boolean): void;
336
+ /**
337
+ * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
338
+ * parent property of the value to undefined.
339
+ * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
340
+ */
316
341
  protected _setRoot(v: N | null): void;
342
+ /**
343
+ * The function sets the size of a protected variable.
344
+ * @param {number} v - number
345
+ */
317
346
  protected _setSize(v: number): void;
318
- protected _setCount(v: number): void;
319
347
  /**
320
- * The function resets the values of several arrays used for tracking visited nodes and their properties.
348
+ * The function `_resetResults` resets the values of several arrays used for tracking visited nodes and their
349
+ * properties.
321
350
  */
322
351
  protected _resetResults(): void;
323
352
  /**
324
353
  * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
325
354
  * a result array.
326
- * @param cur - The current binary tree node that is being checked.
327
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
328
- * traversal.
329
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
330
- * the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
355
+ * @param {N} cur - The current node being processed.
356
+ * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
357
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
358
+ * type. It represents the property value that we are comparing against in the switch statement.
331
359
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
332
- * specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
333
- * be one of the following values: 'id', 'count', or 'val'. If no `propertyName` is provided,
360
+ * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
361
+ * or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
334
362
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
335
363
  * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
336
364
  * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
337
- * @returns a boolean value indicating whether or not a node was pushed into the result array.
365
+ * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
338
366
  */
339
367
  protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
340
368
  /**
341
- * The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
342
- * provided property name or a default property name.
343
- * @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
344
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
345
- * can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
346
- * the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
369
+ * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
370
+ * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
371
+ * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
372
+ * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
373
+ * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
347
374
  */
348
375
  protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
349
376
  /**
350
- * The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting
351
- * to 'id'.
377
+ * The time complexity of Morris traversal is O(n), it's may slower than others
378
+ * The space complexity Morris traversal is O(1) because no using stack
379
+ */
380
+ /**
381
+ * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
382
+ * name.
352
383
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
353
- * can accept a value of type `NodeOrPropertyName`.
354
- * @returns The method returns an object of type `AbstractBinaryTreeNodeProperties<T>`.
384
+ * can accept either a `NodeOrPropertyName` type or be undefined.
385
+ * @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
355
386
  */
356
387
  protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
357
388
  }