data-structure-typed 1.36.8 → 1.37.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 (85) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +8 -0
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +5 -5
  4. package/dist/data-structures/binary-tree/avl-tree.js +6 -6
  5. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +18 -95
  7. package/dist/data-structures/binary-tree/binary-tree.js +82 -183
  8. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/bst.d.ts +6 -20
  10. package/dist/data-structures/binary-tree/bst.js +22 -122
  11. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -67
  13. package/dist/data-structures/binary-tree/tree-multiset.js +10 -257
  14. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  15. package/dist/data-structures/graph/abstract-graph.js +4 -3
  16. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  17. package/dist/data-structures/hash/hash-map.d.ts +1 -1
  18. package/dist/data-structures/hash/hash-map.js +1 -1
  19. package/dist/data-structures/hash/hash-table.d.ts +3 -3
  20. package/dist/data-structures/hash/hash-table.js +3 -3
  21. package/dist/data-structures/heap/heap.js.map +1 -1
  22. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -3
  23. package/dist/data-structures/linked-list/skip-linked-list.js +3 -3
  24. package/dist/data-structures/queue/deque.d.ts +2 -2
  25. package/dist/data-structures/queue/deque.js +2 -2
  26. package/dist/data-structures/queue/queue.js +1 -1
  27. package/dist/data-structures/trie/trie.d.ts +2 -2
  28. package/dist/data-structures/trie/trie.js +2 -2
  29. package/dist/interfaces/binary-tree.d.ts +1 -1
  30. package/lib/data-structures/binary-tree/avl-tree.d.ts +5 -5
  31. package/lib/data-structures/binary-tree/avl-tree.js +6 -6
  32. package/lib/data-structures/binary-tree/binary-tree.d.ts +18 -95
  33. package/lib/data-structures/binary-tree/binary-tree.js +82 -183
  34. package/lib/data-structures/binary-tree/bst.d.ts +6 -20
  35. package/lib/data-structures/binary-tree/bst.js +22 -122
  36. package/lib/data-structures/binary-tree/tree-multiset.d.ts +6 -67
  37. package/lib/data-structures/binary-tree/tree-multiset.js +10 -257
  38. package/lib/data-structures/graph/abstract-graph.js +4 -3
  39. package/lib/data-structures/hash/hash-map.d.ts +1 -1
  40. package/lib/data-structures/hash/hash-map.js +1 -1
  41. package/lib/data-structures/hash/hash-table.d.ts +3 -3
  42. package/lib/data-structures/hash/hash-table.js +3 -3
  43. package/lib/data-structures/linked-list/skip-linked-list.d.ts +3 -3
  44. package/lib/data-structures/linked-list/skip-linked-list.js +3 -3
  45. package/lib/data-structures/queue/deque.d.ts +2 -2
  46. package/lib/data-structures/queue/deque.js +2 -2
  47. package/lib/data-structures/queue/queue.js +1 -1
  48. package/lib/data-structures/trie/trie.d.ts +2 -2
  49. package/lib/data-structures/trie/trie.js +2 -2
  50. package/lib/interfaces/binary-tree.d.ts +1 -1
  51. package/package.json +9 -7
  52. package/src/data-structures/binary-tree/avl-tree.ts +6 -6
  53. package/src/data-structures/binary-tree/binary-tree.ts +85 -274
  54. package/src/data-structures/binary-tree/bst.ts +22 -106
  55. package/src/data-structures/binary-tree/rb-tree.ts +3 -3
  56. package/src/data-structures/binary-tree/tree-multiset.ts +10 -249
  57. package/src/data-structures/graph/abstract-graph.ts +4 -3
  58. package/src/data-structures/hash/hash-map.ts +1 -1
  59. package/src/data-structures/hash/hash-table.ts +3 -3
  60. package/src/data-structures/heap/heap.ts +5 -2
  61. package/src/data-structures/linked-list/skip-linked-list.ts +3 -3
  62. package/src/data-structures/queue/deque.ts +2 -2
  63. package/src/data-structures/queue/queue.ts +1 -1
  64. package/src/data-structures/trie/trie.ts +2 -2
  65. package/src/interfaces/binary-tree.ts +1 -1
  66. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +19 -17
  67. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  68. package/test/unit/data-structures/binary-tree/bst.test.ts +72 -35
  69. package/test/unit/data-structures/binary-tree/overall.test.ts +4 -4
  70. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
  71. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +67 -37
  72. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  73. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  74. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  75. package/test/unit/data-structures/hash/hash-table.test.ts +5 -5
  76. package/test/unit/data-structures/heap/heap.test.ts +15 -12
  77. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +7 -7
  78. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  79. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  80. package/test/unit/data-structures/queue/deque.test.ts +20 -3
  81. package/test/unit/data-structures/queue/queue.test.ts +42 -0
  82. package/test/unit/data-structures/trie/trie.test.ts +5 -5
  83. package/test/utils/big-o.ts +64 -57
  84. package/umd/bundle.min.js +1 -1
  85. package/umd/bundle.min.js.map +1 -1
@@ -52,10 +52,10 @@ export declare class SkipList<K, V> {
52
52
  */
53
53
  get(key: K): V | undefined;
54
54
  /**
55
- * The `remove` function removes a node with a specific key from a Skip List data structure.
55
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
56
56
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
57
- * @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
57
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
58
58
  * skip list, and `false` if the key was not found in the skip list.
59
59
  */
60
- remove(key: K): boolean;
60
+ delete(key: K): boolean;
61
61
  }
@@ -109,12 +109,12 @@ class SkipList {
109
109
  return undefined;
110
110
  }
111
111
  /**
112
- * The `remove` function removes a node with a specific key from a Skip List data structure.
112
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
113
113
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
114
- * @returns The `remove` method returns a boolean value. It returns `true` if the key was successfully removed from the
114
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
115
115
  * skip list, and `false` if the key was not found in the skip list.
116
116
  */
117
- remove(key) {
117
+ delete(key) {
118
118
  const update = new Array(this.maxLevel).fill(this.head);
119
119
  let current = this.head;
120
120
  for (let i = this.level - 1; i >= 0; i--) {
@@ -150,12 +150,12 @@ export declare class ArrayDeque<E> {
150
150
  */
151
151
  insert(index: number, value: E): E[];
152
152
  /**
153
- * The remove function removes an element from an array at a specified index.
153
+ * The delete function removes an element from an array at a specified index.
154
154
  * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
155
155
  * is a number that represents the index of the element to be removed.
156
156
  * @returns The method is returning an array containing the removed element.
157
157
  */
158
- remove(index: number): E[];
158
+ delete(index: number): E[];
159
159
  /**
160
160
  * The function checks if an array called "_nodes" is empty.
161
161
  * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
@@ -256,12 +256,12 @@ class ArrayDeque {
256
256
  return this._nodes.splice(index, 0, value);
257
257
  }
258
258
  /**
259
- * The remove function removes an element from an array at a specified index.
259
+ * The delete function removes an element from an array at a specified index.
260
260
  * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
261
261
  * is a number that represents the index of the element to be removed.
262
262
  * @returns The method is returning an array containing the removed element.
263
263
  */
264
- remove(index) {
264
+ delete(index) {
265
265
  return this._nodes.splice(index, 1);
266
266
  }
267
267
  /**
@@ -94,7 +94,7 @@ class Queue {
94
94
  this.offset += 1;
95
95
  if (this.offset * 2 < this.nodes.length)
96
96
  return first;
97
- // only remove dequeued elements when reaching half size
97
+ // only delete dequeued elements when reaching half size
98
98
  // to decrease latency of shifting elements.
99
99
  this.nodes = this.nodes.slice(this.offset);
100
100
  this.offset = 0;
@@ -45,10 +45,10 @@ export declare class Trie {
45
45
  private _caseProcess;
46
46
  /**
47
47
  * Remove a word from the Trie structure.
48
- * @param{string} word - The word to remove.
48
+ * @param{string} word - The word to delete.
49
49
  * @returns {boolean} True if the word was successfully removed.
50
50
  */
51
- remove(word: string): boolean;
51
+ delete(word: string): boolean;
52
52
  getHeight(): number;
53
53
  /**
54
54
  * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
@@ -100,10 +100,10 @@ class Trie {
100
100
  }
101
101
  /**
102
102
  * Remove a word from the Trie structure.
103
- * @param{string} word - The word to remove.
103
+ * @param{string} word - The word to delete.
104
104
  * @returns {boolean} True if the word was successfully removed.
105
105
  */
106
- remove(word) {
106
+ delete(word) {
107
107
  word = this._caseProcess(word);
108
108
  let isDeleted = false;
109
109
  const dfs = (cur, i) => {
@@ -3,5 +3,5 @@ import { BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../types';
3
3
  export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
6
+ delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -21,13 +21,13 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
21
21
  */
22
22
  constructor(options?: AVLTreeOptions);
23
23
  /**
24
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
25
- * @param {N} srcNode - The source node that you want to swap with the destination node.
24
+ * The `_swap` function swaps the location of two nodes in a binary tree.
25
+ * @param {N} srcNode - The source node that you want to _swap with the destination node.
26
26
  * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
27
27
  * be swapped to.
28
28
  * @returns The `destNode` is being returned.
29
29
  */
30
- swapLocation(srcNode: N, destNode: N): N;
30
+ protected _swap(srcNode: N, destNode: N): N;
31
31
  /**
32
32
  * The function creates a new AVL tree node with the given key and value.
33
33
  * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
@@ -46,13 +46,13 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
46
46
  */
47
47
  add(key: BinaryTreeNodeKey, val?: N['val']): N | null | undefined;
48
48
  /**
49
- * The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
49
+ * The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
50
50
  * deletion.
51
51
  * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
52
52
  * removed.
53
53
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
54
54
  */
55
- remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
55
+ delete(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
56
56
  /**
57
57
  * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
58
58
  * height of its right subtree.
@@ -23,13 +23,13 @@ export class AVLTree extends BST {
23
23
  super(options);
24
24
  }
25
25
  /**
26
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
27
- * @param {N} srcNode - The source node that you want to swap with the destination node.
26
+ * The `_swap` function swaps the location of two nodes in a binary tree.
27
+ * @param {N} srcNode - The source node that you want to _swap with the destination node.
28
28
  * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
29
29
  * be swapped to.
30
30
  * @returns The `destNode` is being returned.
31
31
  */
32
- swapLocation(srcNode, destNode) {
32
+ _swap(srcNode, destNode) {
33
33
  const { key, val, height } = destNode;
34
34
  const tempNode = this.createNode(key, val);
35
35
  if (tempNode) {
@@ -69,14 +69,14 @@ export class AVLTree extends BST {
69
69
  return inserted;
70
70
  }
71
71
  /**
72
- * The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
72
+ * The function overrides the delete method of a binary tree and performs additional operations to balance the tree after
73
73
  * deletion.
74
74
  * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
75
75
  * removed.
76
76
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
77
77
  */
78
- remove(key) {
79
- const deletedResults = super.remove(key);
78
+ delete(key) {
79
+ const deletedResults = super.delete(key);
80
80
  for (const { needBalanced } of deletedResults) {
81
81
  if (needBalanced) {
82
82
  this._balancePath(needBalanced);
@@ -55,17 +55,18 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
55
55
  get size(): number;
56
56
  private _loopType;
57
57
  get loopType(): LoopType;
58
+ set loopType(v: LoopType);
58
59
  visitedKey: BinaryTreeNodeKey[];
59
60
  visitedVal: N['val'][];
60
61
  visitedNode: N[];
61
62
  /**
62
- * The `swapLocation` function swaps the location of two nodes in a binary tree.
63
- * @param {N} srcNode - The source node that you want to swap with the destination node.
63
+ * The `_swap` function swaps the location of two nodes in a binary tree.
64
+ * @param {N} srcNode - The source node that you want to _swap with the destination node.
64
65
  * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
65
66
  * be swapped to.
66
67
  * @returns The `destNode` is being returned.
67
68
  */
68
- swapLocation(srcNode: N, destNode: N): N;
69
+ protected _swap(srcNode: N, destNode: N): N;
69
70
  /**
70
71
  * The clear() function resets the root, size, and maxKey properties to their initial values.
71
72
  */
@@ -111,13 +112,13 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
111
112
  */
112
113
  refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
113
114
  /**
114
- * The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
115
+ * The `delete` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
115
116
  * containing the deleted node and the node that needs to be balanced.
116
117
  * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object (`N`) or a binary tree
117
118
  * node ID (`BinaryTreeNodeKey`).
118
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
119
+ * @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
119
120
  */
120
- remove(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
121
+ delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
121
122
  /**
122
123
  * The function calculates the depth of a node in a binary tree.
123
124
  * @param {N | BinaryTreeNodeKey | null} distNode - The `distNode` parameter can be any node of the tree
@@ -236,10 +237,10 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
236
237
  getRightMost(beginRoot: N): N;
237
238
  /**
238
239
  * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
239
- * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
240
+ * @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
240
241
  * @returns a boolean value.
241
242
  */
242
- isSubtreeBST(node: N | null): boolean;
243
+ isSubtreeBST(subTreeRoot: N | null): boolean;
243
244
  /**
244
245
  * The function isBST checks if the binary tree is valid binary search tree.
245
246
  * @returns The `isBST()` function is returning a boolean value.
@@ -253,26 +254,14 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
253
254
  */
254
255
  getSubTreeSize(subTreeRoot: N | null | undefined): number;
255
256
  /**
256
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
257
- * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
258
- * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
259
- * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
260
- * property of the binary tree node to use for calculating the sum. It can be either 'key' or 'val'. If propertyName is
261
- * not provided, it defaults to 'key'.
262
- * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
263
- */
264
- subTreeSum(subTreeRoot: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number;
265
- /**
266
- * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
257
+ * The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
267
258
  * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
268
259
  * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
269
- * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
270
- * each node in the subtree should be incremented.
271
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
260
+ * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
272
261
  * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
273
262
  * @returns a boolean value.
274
263
  */
275
- subTreeAdd(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
264
+ subTreeForeach(subTreeRoot: N | BinaryTreeNodeKey | null, callback: (node: N) => any): boolean;
276
265
  /**
277
266
  * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.
278
267
  * @returns An array of binary tree node IDs.
@@ -311,87 +300,26 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
311
300
  * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
312
301
  * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
313
302
  * @param {string} nodeOrPropertyName - The name of the property to accumulate.
303
+ * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
314
304
  * @returns An array of values corresponding to the specified property.
315
305
  */
316
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
306
+ dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key', loopType?: LoopType): BinaryTreeNodeKey[];
317
307
  /**
318
308
  * Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
319
309
  * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
320
310
  * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
311
+ * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
321
312
  * @returns An array of 'val' properties from each node.
322
313
  */
323
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
314
+ dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val', loopType?: LoopType): N[];
324
315
  /**
325
316
  * Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
326
317
  * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
327
318
  * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
319
+ * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
328
320
  * @returns An array of binary tree nodes.
329
321
  */
330
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
331
- /**
332
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
333
- * @returns An array of binary tree node IDs.
334
- */
335
- dfsIterative(): BinaryTreeNodeKey[];
336
- /**
337
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
338
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
339
- * @returns An array of values corresponding to the specified property.
340
- */
341
- dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
342
- /**
343
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
344
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
345
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
346
- * @returns An array of values corresponding to the specified property.
347
- */
348
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
349
- /**
350
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
351
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
352
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
353
- * @returns An array of 'val' properties from each node.
354
- */
355
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
356
- /**
357
- * Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
358
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
359
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
360
- * @returns An array of binary tree nodes.
361
- */
362
- dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
363
- /**
364
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
365
- * @returns An array of binary tree node IDs.
366
- */
367
- levelIterative(): BinaryTreeNodeKey[];
368
- /**
369
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
370
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
371
- * @returns An array of binary tree node IDs.
372
- */
373
- levelIterative(node: N | null): BinaryTreeNodeKey[];
374
- /**
375
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on the specified property name.
376
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
377
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
378
- * @returns An array of values corresponding to the specified property.
379
- */
380
- levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
381
- /**
382
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
383
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
384
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
385
- * @returns An array of 'val' properties from each node.
386
- */
387
- levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
388
- /**
389
- * Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
390
- * @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
391
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
392
- * @returns An array of binary tree nodes.
393
- */
394
- levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
322
+ dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node', loopType?: LoopType): N[];
395
323
  /**
396
324
  * Collects nodes from a binary tree by a specified property and organizes them into levels.
397
325
  * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
@@ -477,11 +405,6 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
477
405
  * undefined.
478
406
  */
479
407
  protected _addTo(newNode: N | null, parent: N): N | null | undefined;
480
- /**
481
- * The function sets the loop type for a protected variable.
482
- * @param {LoopType} value - The value parameter is of type LoopType.
483
- */
484
- protected _setLoopType(value: LoopType): void;
485
408
  /**
486
409
  * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
487
410
  * parent property of the value to undefined.