diff --git a/README.md b/README.md
index c18dbc5..73690df 100644
--- a/README.md
+++ b/README.md
@@ -788,52 +788,52 @@ avl2.print();
[//]: # (No deletion!!! Start of Replace Section)
avl-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 34.57 | 28.93 | 0.01 |
10,000 add & delete randomly | 80.91 | 12.36 | 0.02 |
10,000 addMany | 38.81 | 25.76 | 0.01 |
10,000 get | 32.58 | 30.69 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 28.01 | 35.70 | 3.60e-4 |
10,000 add & delete randomly | 68.19 | 14.66 | 0.00 |
10,000 addMany | 34.37 | 29.10 | 3.01e-4 |
10,000 get | 28.61 | 34.96 | 2.81e-4 |
binary-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 add randomly | 14.61 | 68.46 | 0.00 |
1,000 add & delete randomly | 21.50 | 46.51 | 0.01 |
1,000 addMany | 15.57 | 64.22 | 0.01 |
1,000 get | 32.93 | 30.36 | 0.02 |
1,000 has | 26.55 | 37.67 | 0.02 |
1,000 dfs | 181.64 | 5.51 | 0.03 |
1,000 bfs | 94.85 | 10.54 | 0.05 |
1,000 morris | 316.07 | 3.16 | 0.04 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 add randomly | 13.78 | 72.57 | 9.19e-5 |
1,000 add & delete randomly | 21.50 | 46.52 | 1.81e-4 |
1,000 addMany | 15.91 | 62.85 | 1.16e-4 |
1,000 get | 18.16 | 55.08 | 1.86e-4 |
1,000 has | 18.16 | 55.06 | 1.82e-4 |
1,000 dfs | 161.46 | 6.19 | 5.35e-4 |
1,000 bfs | 56.32 | 17.76 | 4.17e-4 |
1,000 morris | 257.59 | 3.88 | 6.92e-4 |
bst
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 27.63 | 36.19 | 0.01 |
10,000 add & delete randomly | 73.15 | 13.67 | 0.02 |
10,000 addMany | 27.44 | 36.44 | 0.01 |
10,000 get | 37.03 | 27.01 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 add randomly | 26.94 | 37.12 | 2.41e-4 |
10,000 add & delete randomly | 69.33 | 14.42 | 5.46e-4 |
10,000 addMany | 28.17 | 35.50 | 3.03e-4 |
10,000 get | 31.40 | 31.85 | 2.49e-4 |
rb-tree
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 113.44 | 8.82 | 0.02 |
100,000 add & delete randomly | 283.31 | 3.53 | 0.03 |
100,000 getNode | 89.35 | 11.19 | 0.01 |
100,000 add & iterator | 143.95 | 6.95 | 0.03 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add | 84.95 | 11.77 | 0.00 |
100,000 add & delete randomly | 214.08 | 4.67 | 0.00 |
100,000 getNode | 43.21 | 23.14 | 3.41e-4 |
100,000 add & iterator | 115.98 | 8.62 | 0.00 |
comparison
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
SRC PQ 10,000 add | 0.16 | 6180.55 | 3.37e-5 |
CJS PQ 10,000 add | 0.17 | 6004.31 | 4.09e-5 |
MJS PQ 10,000 add | 0.66 | 1512.95 | 1.66e-4 |
SRC PQ 10,000 add & pop | 3.89 | 256.83 | 7.53e-4 |
CJS PQ 10,000 add & pop | 4.02 | 248.66 | 0.00 |
MJS PQ 10,000 add & pop | 3.78 | 264.62 | 8.38e-4 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
SRC PQ 10,000 add | 0.14 | 6958.08 | 1.96e-6 |
CJS PQ 10,000 add | 0.14 | 6945.48 | 1.85e-6 |
MJS PQ 10,000 add | 0.57 | 1758.67 | 6.72e-6 |
SRC PQ 10,000 add & pop | 3.41 | 293.06 | 3.56e-5 |
CJS PQ 10,000 add & pop | 3.40 | 293.88 | 3.65e-5 |
MJS PQ 10,000 add & pop | 3.30 | 302.86 | 3.70e-5 |
directed-graph
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.12 | 8625.55 | 2.88e-5 |
1,000 addEdge | 8.52 | 117.35 | 0.00 |
1,000 getVertex | 0.05 | 1.92e+4 | 1.11e-5 |
1,000 getEdge | 20.83 | 48.02 | 0.00 |
tarjan | 195.71 | 5.11 | 0.02 |
tarjan all | 191.98 | 5.21 | 0.02 |
topologicalSort | 155.83 | 6.42 | 0.03 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000 addVertex | 0.10 | 9990.48 | 1.15e-6 |
1,000 addEdge | 6.30 | 158.81 | 7.72e-4 |
1,000 getVertex | 0.05 | 2.15e+4 | 3.77e-7 |
1,000 getEdge | 22.56 | 44.33 | 0.00 |
tarjan | 213.11 | 4.69 | 0.01 |
tarjan all | 212.23 | 4.71 | 9.29e-4 |
topologicalSort | 170.96 | 5.85 | 0.00 |
hash-map
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 129.78 | 7.71 | 0.05 |
1,000,000 Map set | 276.67 | 3.61 | 0.03 |
1,000,000 Set add | 239.70 | 4.17 | 0.04 |
1,000,000 set & get | 143.96 | 6.95 | 0.04 |
1,000,000 Map set & get | 371.31 | 2.69 | 0.10 |
1,000,000 Set add & has | 247.24 | 4.04 | 0.05 |
1,000,000 ObjKey set & get | 396.42 | 2.52 | 0.06 |
1,000,000 Map ObjKey set & get | 411.40 | 2.43 | 0.10 |
1,000,000 Set ObjKey add & has | 357.45 | 2.80 | 0.05 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 set | 120.97 | 8.27 | 0.05 |
1,000,000 Map set | 217.88 | 4.59 | 0.03 |
1,000,000 Set add | 171.45 | 5.83 | 0.02 |
1,000,000 set & get | 116.49 | 8.58 | 0.02 |
1,000,000 Map set & get | 271.49 | 3.68 | 0.02 |
1,000,000 Set add & has | 173.05 | 5.78 | 0.02 |
1,000,000 ObjKey set & get | 314.33 | 3.18 | 0.04 |
1,000,000 Map ObjKey set & get | 275.93 | 3.62 | 0.06 |
1,000,000 Set ObjKey add & has | 277.40 | 3.60 | 0.08 |
heap
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 88.96 | 11.24 | 0.02 |
100,000 add & dfs | 38.81 | 25.77 | 0.01 |
10,000 fib add & pop | 399.77 | 2.50 | 0.01 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 80.18 | 12.47 | 0.00 |
100,000 add & dfs | 35.40 | 28.25 | 0.00 |
10,000 fib add & pop | 360.71 | 2.77 | 0.00 |
doubly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 264.62 | 3.78 | 0.08 |
1,000,000 unshift | 264.00 | 3.79 | 0.05 |
1,000,000 unshift & shift | 211.89 | 4.72 | 0.07 |
1,000,000 insertBefore | 467.62 | 2.14 | 0.22 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 242.04 | 4.13 | 0.04 |
1,000,000 unshift | 204.37 | 4.89 | 0.03 |
1,000,000 unshift & shift | 178.89 | 5.59 | 0.03 |
1,000,000 insertBefore | 325.64 | 3.07 | 0.07 |
singly-linked-list
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 push & pop | 260.65 | 3.84 | 0.04 |
10,000 insertBefore | 283.61 | 3.53 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 push & pop | 216.93 | 4.61 | 0.02 |
10,000 insertBefore | 247.43 | 4.04 | 0.00 |
max-priority-queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 refill & poll | 10.29 | 97.16 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
10,000 refill & poll | 8.92 | 112.15 | 1.68e-4 |
priority-queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 117.05 | 8.54 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 add & pop | 101.57 | 9.85 | 0.00 |
deque
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 15.96 | 62.68 | 0.00 |
1,000,000 push & pop | 25.90 | 38.61 | 0.01 |
1,000,000 push & shift | 26.33 | 37.98 | 0.00 |
1,000,000 unshift & shift | 24.90 | 40.16 | 0.00 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 13.83 | 72.30 | 1.57e-4 |
1,000,000 push & pop | 22.78 | 43.90 | 4.69e-4 |
1,000,000 push & shift | 23.80 | 42.02 | 1.75e-4 |
1,000,000 unshift & shift | 22.04 | 45.37 | 2.74e-4 |
queue
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 44.53 | 22.46 | 0.01 |
1,000,000 push & shift | 92.57 | 10.80 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 39.17 | 25.53 | 0.00 |
1,000,000 push & shift | 82.12 | 12.18 | 0.00 |
stack
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 59.07 | 16.93 | 0.02 |
1,000,000 push & pop | 52.68 | 18.98 | 0.02 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
1,000,000 push | 40.20 | 24.88 | 0.01 |
1,000,000 push & pop | 49.27 | 20.30 | 0.01 |
trie
-
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 68.45 | 14.61 | 0.02 |
100,000 getWords | 134.22 | 7.45 | 0.04 |
+
test name | time taken (ms) | executions per sec | sample deviation |
---|
100,000 push | 45.29 | 22.08 | 6.76e-4 |
100,000 getWords | 86.68 | 11.54 | 0.00 |
[//]: # (No deletion!!! End of Replace Section)
diff --git a/package-lock.json b/package-lock.json
index b817ca2..c3d47f3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "data-structure-typed",
- "version": "1.48.0",
+ "version": "1.48.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "data-structure-typed",
- "version": "1.48.0",
+ "version": "1.48.2",
"license": "MIT",
"devDependencies": {
"@swc/core": "^1.3.96",
@@ -39,7 +39,7 @@
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typedoc": "^0.25.1",
- "typescript": "^5.2.2"
+ "typescript": "^5.3.2"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
diff --git a/package.json b/package.json
index 9e67c9e..a70a2ce 100644
--- a/package.json
+++ b/package.json
@@ -88,7 +88,7 @@
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typedoc": "^0.25.1",
- "typescript": "^5.2.2"
+ "typescript": "^5.3.2"
},
"keywords": [
"data",
diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts
index d5e13b0..51fd590 100644
--- a/src/data-structures/binary-tree/avl-tree.ts
+++ b/src/data-structures/binary-tree/avl-tree.ts
@@ -12,16 +12,15 @@ import type {
AVLTreeOptions,
BiTreeDeleteResult,
BSTNodeKeyOrNode,
- BTNKey,
BTNodeExemplar
} from '../../types';
import { BTNCallback } from '../../types';
import { IBinaryTree } from '../../interfaces';
-export class AVLTreeNode = AVLTreeNodeNested> extends BSTNode {
+export class AVLTreeNode = AVLTreeNodeNested> extends BSTNode {
height: number;
- constructor(key: BTNKey, value?: V) {
+ constructor(key: K, value?: V) {
super(key, value);
this.height = 0;
}
@@ -37,35 +36,35 @@ export class AVLTreeNode = AVLTreeNodeNeste
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
*/
-export class AVLTree = AVLTreeNode>, TREE extends AVLTree = AVLTree>>
- extends BST
- implements IBinaryTree {
+export class AVLTree = AVLTreeNode>, TREE extends AVLTree = AVLTree>>
+ extends BST
+ implements IBinaryTree {
/**
* The constructor function initializes an AVLTree object with optional elements and options.
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar`
+ * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar`
* objects. It represents a collection of elements that will be added to the AVL tree during
* initialization.
* @param [options] - The `options` parameter is an optional object that allows you to customize the
* behavior of the AVL tree. It is of type `Partial`, which means that you can
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
*/
- constructor(elements?: Iterable>, options?: Partial) {
+ constructor(elements?: Iterable>, options?: Partial>) {
super([], options);
if (elements) super.addMany(elements);
}
/**
* The function creates a new AVL tree node with the specified key and value.
- * @param {BTNKey} key - The key parameter is the key value that will be associated with
+ * @param {K} key - The key parameter is the key value that will be associated with
* the new node. It is used to determine the position of the node in the binary search tree.
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
* type `V`, which means it can be any value that is assignable to the `value` property of the
* node type `N`.
* @returns a new AVLTreeNode object with the specified key and value.
*/
- override createNode(key: BTNKey, value?: V): N {
- return new AVLTreeNode(key, value) as N;
+ override createNode(key: K, value?: V): N {
+ return new AVLTreeNode(key, value) as N;
}
/**
@@ -75,19 +74,19 @@ export class AVLTree = AVLTreeNode([], {
+ override createTree(options?: AVLTreeOptions): TREE {
+ return new AVLTree([], {
iterationType: this.iterationType,
- comparator: this.comparator, ...options
+ variant: this.variant, ...options
}) as TREE;
}
/**
* The function checks if an exemplar is an instance of AVLTreeNode.
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar`.
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar`.
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
*/
- override isNode(exemplar: BTNodeExemplar): exemplar is N {
+ override isNode(exemplar: BTNodeExemplar): exemplar is N {
return exemplar instanceof AVLTreeNode;
}
@@ -106,7 +105,7 @@ export class AVLTree = AVLTreeNode): N | undefined {
+ override add(keyOrNodeOrEntry: BTNodeExemplar): N | undefined {
if (keyOrNodeOrEntry === null) return undefined;
const inserted = super.add(keyOrNodeOrEntry);
if (inserted) this._balancePath(inserted);
@@ -151,14 +150,14 @@ export class AVLTree = AVLTreeNode, destNode: BSTNodeKeyOrNode): N | undefined {
+ protected override _swapProperties(srcNode: BSTNodeKeyOrNode, destNode: BSTNodeKeyOrNode): N | undefined {
srcNode = this.ensureNode(srcNode);
destNode = this.ensureNode(destNode);
diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts
index 7ee9f45..52dd980 100644
--- a/src/data-structures/binary-tree/binary-tree.ts
+++ b/src/data-structures/binary-tree/binary-tree.ts
@@ -10,7 +10,6 @@ import type {
BinaryTreeNodeNested,
BinaryTreeOptions,
BTNCallback,
- BTNKey,
BTNodeEntry,
BTNodeExemplar,
BTNodeKeyOrNode,
@@ -35,14 +34,14 @@ import { IterablePairBase } from "../base";
* @template V - The type of data stored in the node.
* @template N - The type of the family relationship in the binary tree.
*/
-export class BinaryTreeNode = BinaryTreeNode>> {
- key: BTNKey;
+export class BinaryTreeNode = BinaryTreeNode>> {
+ key: K;
value?: V;
parent?: N;
- constructor(key: BTNKey, value?: V) {
+ constructor(key: K, value?: V) {
this.key = key;
this.value = value;
}
@@ -105,9 +104,9 @@ export class BinaryTreeNode = BinaryTree
* 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
*/
-export class BinaryTree = BinaryTreeNode>, TREE extends BinaryTree = BinaryTree>> extends IterablePairBase
+export class BinaryTree = BinaryTreeNode>, TREE extends BinaryTree = BinaryTree>> extends IterablePairBase
- implements IBinaryTree {
+ implements IBinaryTree {
iterationType = IterationType.ITERATIVE
/**
@@ -119,13 +118,16 @@ export class BinaryTree = BinaryTreeNode
* `Partial`, which means that not all properties of `BinaryTreeOptions` are
* required.
*/
- constructor(elements?: Iterable>, options?: Partial) {
+ constructor(elements?: Iterable>, options?: Partial>) {
super();
if (options) {
- const { iterationType } = options;
+ const { iterationType, extractor } = options;
if (iterationType) {
this.iterationType = iterationType;
}
+ if (extractor) {
+ this._extractor = extractor;
+ }
}
this._size = 0;
@@ -133,6 +135,12 @@ export class BinaryTree = BinaryTreeNode
if (elements) this.addMany(elements);
}
+ protected _extractor = (key: K) => Number(key)
+
+ get extractor() {
+ return this._extractor;
+ }
+
protected _root?: N | null;
get root(): N | null | undefined {
@@ -147,12 +155,12 @@ export class BinaryTree = BinaryTreeNode
/**
* Creates a new instance of BinaryTreeNode with the given key and value.
- * @param {BTNKey} key - The key for the new node.
+ * @param {K} key - The key for the new node.
* @param {V} value - The value for the new node.
* @returns {N} - The newly created BinaryTreeNode.
*/
- createNode(key: BTNKey, value?: V): N {
- return new BinaryTreeNode(key, value) as N;
+ createNode(key: K, value?: V): N {
+ return new BinaryTreeNode(key, value) as N;
}
/**
@@ -162,27 +170,27 @@ export class BinaryTree = BinaryTreeNode
* you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
* @returns a new instance of a binary tree.
*/
- createTree(options?: Partial): TREE {
- return new BinaryTree([], { iterationType: this.iterationType, ...options }) as TREE;
+ createTree(options?: Partial>): TREE {
+ return new BinaryTree([], { iterationType: this.iterationType, ...options }) as TREE;
}
/**
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar`.
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar`.
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
*/
- isNode(exemplar: BTNodeExemplar): exemplar is N {
+ isNode(exemplar: BTNodeExemplar): exemplar is N {
return exemplar instanceof BinaryTreeNode;
}
/**
* The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
* object.
- * @param exemplar - BTNodeExemplar - A generic type representing the exemplar parameter of the
+ * @param exemplar - BTNodeExemplar - A generic type representing the exemplar parameter of the
* function. It can be any type.
* @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
*/
- exemplarToNode(exemplar: BTNodeExemplar): N | null | undefined {
+ exemplarToNode(exemplar: BTNodeExemplar): N | null | undefined {
if (exemplar === undefined) return;
let node: N | null | undefined;
@@ -199,7 +207,7 @@ export class BinaryTree = BinaryTreeNode
}
} else if (this.isNode(exemplar)) {
node = exemplar;
- } else if (this.isNodeKey(exemplar)) {
+ } else if (this.isNotNodeInstance(exemplar)) {
node = this.createNode(exemplar);
} else {
return;
@@ -209,11 +217,11 @@ export class BinaryTree = BinaryTreeNode
/**
* The function checks if a given value is an entry in a binary tree node.
- * @param kne - BTNodeExemplar - A generic type representing a node in a binary tree. It has
+ * @param kne - BTNodeExemplar - A generic type representing a node in a binary tree. It has
* two type parameters V and N, representing the value and node type respectively.
* @returns a boolean value.
*/
- isEntry(kne: BTNodeExemplar): kne is BTNodeEntry {
+ isEntry(kne: BTNodeExemplar): kne is BTNodeEntry {
return Array.isArray(kne) && kne.length === 2;
}
@@ -230,7 +238,7 @@ export class BinaryTree = BinaryTreeNode
* @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
* @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
*/
- add(keyOrNodeOrEntry: BTNodeExemplar): N | null | undefined {
+ add(keyOrNodeOrEntry: BTNodeExemplar): N | null | undefined {
let inserted: N | null | undefined;
const newNode = this.exemplarToNode(keyOrNodeOrEntry);
@@ -279,11 +287,11 @@ export class BinaryTree = BinaryTreeNode
* The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
* current instance, and returns an array of the inserted nodes.
* @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
- * `BTNodeExemplar` objects.
+ * `BTNodeExemplar` objects.
* @returns The function `addMany` returns an array of values, where each value is either of type
* `N`, `null`, or `undefined`.
*/
- addMany(nodes: Iterable>): (N | null | undefined)[] {
+ addMany(nodes: Iterable>): (N | null | undefined)[] {
// TODO not sure addMany not be run multi times
const inserted: (N | null | undefined)[] = [];
for (const kne of nodes) {
@@ -305,7 +313,7 @@ export class BinaryTree = BinaryTreeNode
* @param nodesOrKeysOrEntries - The parameter `nodesOrKeysOrEntries` is an iterable object that can
* contain either `BTNodeExemplar` objects, keys, or entries.
*/
- refill(nodesOrKeysOrEntries: Iterable>): void {
+ refill(nodesOrKeysOrEntries: Iterable>): void {
this.clear();
this.addMany(nodesOrKeysOrEntries);
}
@@ -315,7 +323,7 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(1)
*/
- delete>(identifier: BTNKey, callback?: C): BiTreeDeleteResult[];
+ delete>(identifier: K, callback?: C): BiTreeDeleteResult[];
delete>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult[];
@@ -396,15 +404,15 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(1)
*
* The function calculates the depth of a given node in a binary tree.
- * @param {BTNKey | N | null | undefined} distNode - The `distNode` parameter represents the node in
- * the binary tree whose depth we want to find. It can be of type `BTNKey`, `N`, `null`, or
+ * @param {K | N | null | undefined} distNode - The `distNode` parameter represents the node in
+ * the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
* `undefined`.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
- * from which we want to calculate the depth. It can be either a `BTNKey` (binary tree node key) or
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
+ * from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
* @returns the depth of the `distNode` relative to the `beginRoot`.
*/
- getDepth(distNode: BTNodeKeyOrNode, beginRoot: BTNodeKeyOrNode = this.root): number {
+ getDepth(distNode: BTNodeKeyOrNode, beginRoot: BTNodeKeyOrNode = this.root): number {
distNode = this.ensureNode(distNode);
beginRoot = this.ensureNode(beginRoot);
let depth = 0;
@@ -429,15 +437,15 @@ export class BinaryTree = BinaryTreeNode
*
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
* iterative traversal.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the height. It can be of type
- * `BTNKey`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
+ * `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
* height of the tree using a recursive approach or an iterative approach. It can have two possible
* values:
* @returns the height of the binary tree.
*/
- getHeight(beginRoot: BTNodeKeyOrNode = this.root, iterationType = this.iterationType): number {
+ getHeight(beginRoot: BTNodeKeyOrNode = this.root, iterationType = this.iterationType): number {
beginRoot = this.ensureNode(beginRoot);
if (!beginRoot) return -1;
@@ -479,14 +487,14 @@ export class BinaryTree = BinaryTreeNode
*
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
* recursive or iterative approach.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
- * type `BTNKey`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
+ * type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
* to calculate the minimum height of a binary tree. It can have two possible values:
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
*/
- getMinHeight(beginRoot: BTNodeKeyOrNode = this.root, iterationType = this.iterationType): number {
+ getMinHeight(beginRoot: BTNodeKeyOrNode = this.root, iterationType = this.iterationType): number {
beginRoot = this.ensureNode(beginRoot);
if (!beginRoot) return -1;
@@ -541,12 +549,12 @@ export class BinaryTree = BinaryTreeNode
*
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
* height of the tree.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
- * for calculating the height and minimum height of a binary tree. It can be either a `BTNKey` (a key
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
+ * for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
* @returns a boolean value.
*/
- isPerfectlyBalanced(beginRoot: BTNodeKeyOrNode = this.root): boolean {
+ isPerfectlyBalanced(beginRoot: BTNodeKeyOrNode = this.root): boolean {
return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
}
@@ -555,11 +563,11 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(log n)
*/
- getNodes>(
- identifier: BTNKey,
+ getNodes>(
+ identifier: K,
callback?: C,
onlyOne?: boolean,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N[];
@@ -567,7 +575,7 @@ export class BinaryTree = BinaryTreeNode
identifier: N | null | undefined,
callback?: C,
onlyOne?: boolean,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N[];
@@ -575,7 +583,7 @@ export class BinaryTree = BinaryTreeNode
identifier: ReturnType,
callback: C,
onlyOne?: boolean,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N[];
@@ -597,7 +605,7 @@ export class BinaryTree = BinaryTreeNode
* matches the identifier. If set to true, the function will stop iterating once it finds a matching
* node and return that node. If set to false (default), the function will continue iterating and
* return all nodes that match the identifier.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
* starting node for the traversal. It can be either a key, a node object, or `null`/`undefined`. If
* it is `null` or `undefined`, an empty array will be returned.
* @param iterationType - The `iterationType` parameter determines the type of iteration used to
@@ -608,7 +616,7 @@ export class BinaryTree = BinaryTreeNode
identifier: ReturnType | null | undefined,
callback: C = this._defaultOneParamCallback as C,
onlyOne = false,
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): N[] {
if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode)
@@ -653,24 +661,24 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(log n).
*/
- has>(
- identifier: BTNKey,
+ has>(
+ identifier: K,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): boolean;
has>(
identifier: N | null | undefined,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): boolean;
has>(
identifier: ReturnType | null | undefined,
callback: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): boolean;
@@ -686,8 +694,8 @@ export class BinaryTree = BinaryTreeNode
* the binary tree. It is used to filter the nodes based on certain conditions. The `callback`
* function should return a boolean value indicating whether the node should be included in the
* result or not.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
- * for the search in the binary tree. It can be specified as a `BTNKey` (a unique identifier for a
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
+ * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
* node in the binary tree), a node object (`N`), or `null`/`undefined` to start the search from
* @param iterationType - The `iterationType` parameter is a variable that determines the type of
* iteration to be performed on the binary tree. It is used to specify whether the iteration should
@@ -697,7 +705,7 @@ export class BinaryTree = BinaryTreeNode
has>(
identifier: ReturnType | null | undefined,
callback: C = this._defaultOneParamCallback as C,
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): boolean {
if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode)
@@ -711,24 +719,24 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(log n).
*/
- getNode>(
- identifier: BTNKey,
+ getNode>(
+ identifier: K,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N | null | undefined;
getNode>(
identifier: N | null | undefined,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N | null | undefined;
getNode>(
identifier: ReturnType,
callback: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): N | null | undefined;
@@ -745,7 +753,7 @@ export class BinaryTree = BinaryTreeNode
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the binary tree. It is used to determine if a node matches the given identifier. The `callback`
* function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
* for searching the binary tree. It can be either a key value, a node object, or `null`/`undefined`.
* If `null` or `undefined` is passed, the search will start from the root of the binary tree.
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
@@ -756,7 +764,7 @@ export class BinaryTree = BinaryTreeNode
getNode>(
identifier: ReturnType | null | undefined,
callback: C = this._defaultOneParamCallback as C,
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): N | null | undefined {
if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode)
@@ -776,7 +784,7 @@ export class BinaryTree = BinaryTreeNode
*
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
* recursive or iterative iteration.
- * @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
+ * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
* It is used to find the node with the matching key value.
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
* the node with the given key should be performed iteratively or recursively. It has two possible
@@ -784,7 +792,7 @@ export class BinaryTree = BinaryTreeNode
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
* found in the binary tree. If no node is found, it returns `undefined`.
*/
- getNodeByKey(key: BTNKey, iterationType = IterationType.ITERATIVE): N | undefined {
+ getNodeByKey(key: K, iterationType = IterationType.ITERATIVE): N | undefined {
if (!this.root) return undefined;
if (iterationType === IterationType.RECURSIVE) {
const _dfs = (cur: N): N | undefined => {
@@ -817,7 +825,7 @@ export class BinaryTree = BinaryTreeNode
/**
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
* key, otherwise it returns the key itself.
- * @param {BTNKey | N | null | undefined} key - The `key` parameter can be of type `BTNKey`, `N`,
+ * @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to be used when searching for a node by key. It has a default value of
@@ -825,28 +833,28 @@ export class BinaryTree = BinaryTreeNode
* @returns either the node corresponding to the given key if it is a valid node key, or the key
* itself if it is not a valid node key.
*/
- ensureNode(key: BTNodeKeyOrNode, iterationType = IterationType.ITERATIVE): N | null | undefined {
- return this.isNodeKey(key) ? this.getNodeByKey(key, iterationType) : key;
+ ensureNode(key: BTNodeKeyOrNode, iterationType = IterationType.ITERATIVE): N | null | undefined {
+ return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
}
- get>(
- identifier: BTNKey,
+ get>(
+ identifier: K,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): V | undefined;
get>(
identifier: N | null | undefined,
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): V | undefined;
get>(
identifier: ReturnType,
callback: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType
): V | undefined;
@@ -863,8 +871,8 @@ export class BinaryTree = BinaryTreeNode
* the binary tree. It is used to determine whether a node matches the given identifier. The callback
* function should return a value that can be compared to the identifier to determine if it is a
* match.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
- * for the search in the binary tree. It can be specified as a `BTNKey` (a unique identifier for a
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
+ * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
* node), a node object of type `N`, or `null`/`undefined` to start the search from the root of
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
* be performed when searching for a node in the binary tree. It is an optional parameter with a
@@ -875,7 +883,7 @@ export class BinaryTree = BinaryTreeNode
get>(
identifier: ReturnType | null | undefined,
callback: C = this._defaultOneParamCallback as C,
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): V | undefined {
if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode)
@@ -911,15 +919,15 @@ export class BinaryTree = BinaryTreeNode
*
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
* structure, with the option to reverse the order of the nodes.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
- * starting node from which you want to find the path to the root. It can be of type `BTNKey`, `N`,
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * starting node from which you want to find the path to the root. It can be of type `K`, `N`,
* `null`, or `undefined`.
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
*/
- getPathToRoot(beginRoot: BTNodeKeyOrNode, isReverse = true): N[] {
+ getPathToRoot(beginRoot: BTNodeKeyOrNode, isReverse = true): N[] {
// TODO to support get path through passing key
const result: N[] = [];
beginRoot = this.ensureNode(beginRoot);
@@ -947,8 +955,8 @@ export class BinaryTree = BinaryTreeNode
*
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
* iteratively.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
- * for finding the leftmost node in a binary tree. It can be either a `BTNKey` (a key value), `N` (a
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
+ * for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
@@ -956,7 +964,7 @@ export class BinaryTree = BinaryTreeNode
* is no leftmost node, it returns `null` or `undefined` depending on the input.
*/
getLeftMost(
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): N | null | undefined {
beginRoot = this.ensureNode(beginRoot);
@@ -992,8 +1000,8 @@ export class BinaryTree = BinaryTreeNode
*
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
* iteratively.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
- * starting node from which we want to find the rightmost node. It can be of type `BTNKey`, `N`,
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
* current object.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
@@ -1002,7 +1010,7 @@ export class BinaryTree = BinaryTreeNode
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
*/
getRightMost(
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType
): N | null | undefined {
// TODO support get right most by passing key in
@@ -1037,23 +1045,24 @@ export class BinaryTree = BinaryTreeNode
* Space Complexity: O(1)
*
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
* possible values:
* @returns a boolean value.
*/
- isSubtreeBST(beginRoot: BTNodeKeyOrNode, iterationType = this.iterationType): boolean {
+ isSubtreeBST(beginRoot: BTNodeKeyOrNode, iterationType = this.iterationType): boolean {
// TODO there is a bug
beginRoot = this.ensureNode(beginRoot);
if (!beginRoot) return true;
if (iterationType === IterationType.RECURSIVE) {
- const dfs = (cur: N | null | undefined, min: BTNKey, max: BTNKey): boolean => {
+ const dfs = (cur: N | null | undefined, min: number, max: number): boolean => {
if (!cur) return true;
- if (cur.key <= min || cur.key >= max) return false;
- return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
+ const numKey = this.extractor(cur.key);
+ if (numKey <= min || numKey >= max) return false;
+ return dfs(cur.left, min, numKey) && dfs(cur.right, numKey, max);
};
return dfs(beginRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
@@ -1067,8 +1076,9 @@ export class BinaryTree = BinaryTreeNode
curr = curr.left;
}
curr = stack.pop()!;
- if (!curr || prev >= curr.key) return false;
- prev = curr.key;
+ const numKey = this.extractor(curr.key);
+ if (!curr || prev >= numKey) return false;
+ prev = numKey;
curr = curr.right;
}
return true;
@@ -1103,21 +1113,21 @@ export class BinaryTree = BinaryTreeNode
subTreeTraverse>(
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: false
): ReturnType[];
subTreeTraverse>(
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: undefined
): ReturnType[];
subTreeTraverse>(
callback?: C,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: true
): ReturnType[];
@@ -1131,8 +1141,8 @@ export class BinaryTree = BinaryTreeNode
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
* the subtree traversal. It takes a single parameter, which is the current node being traversed, and
* returns a value of any type.
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
- * starting node or key from which the subtree traversal should begin. It can be of type `BTNKey`,
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
+ * starting node or key from which the subtree traversal should begin. It can be of type `K`,
* `N`, `null`, or `undefined`. If not provided, the `root` property of the current object is used as
* the default value.
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -1146,7 +1156,7 @@ export class BinaryTree = BinaryTreeNode
*/
subTreeTraverse>(
callback: C = this._defaultOneParamCallback as C,
- beginRoot: BTNodeKeyOrNode = this.root,
+ beginRoot: BTNodeKeyOrNode = this.root,
iterationType = this.iterationType,
includeNull = false
): ReturnType[] {
@@ -1224,19 +1234,19 @@ export class BinaryTree = BinaryTreeNode
}
/**
- * The function "isNodeKey" checks if a potential key is a number.
+ * The function "isNotNodeInstance" checks if a potential key is a number.
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
* data type.
* @returns a boolean value indicating whether the potentialKey is of type number or not.
*/
- isNodeKey(potentialKey: any): potentialKey is number {
- return typeof potentialKey === 'number';
+ isNotNodeInstance(potentialKey: BTNodeKeyOrNode): potentialKey is K {
+ return !(potentialKey instanceof BinaryTreeNode)
}
dfs>(
callback?: C,
pattern?: DFSOrderPattern,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: false
): ReturnType[];
@@ -1244,7 +1254,7 @@ export class BinaryTree = BinaryTreeNode
dfs>(
callback?: C,
pattern?: DFSOrderPattern,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: undefined
): ReturnType[];
@@ -1252,7 +1262,7 @@ export class BinaryTree = BinaryTreeNode
dfs>(
callback?: C,
pattern?: DFSOrderPattern,
- beginRoot?: BTNodeKeyOrNode,
+ beginRoot?: BTNodeKeyOrNode,
iterationType?: IterationType,
includeNull?: true
): ReturnType[];
@@ -1269,7 +1279,7 @@ export class BinaryTree = BinaryTreeNode
* `null`, or `undefined`, and returns a value of any type. The default value for this parameter is
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
* nodes are traversed during the depth-first search. It can have one of the following values:
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
* for the depth-first search traversal. It can be specified as a key, a node object, or
* `null`/`undefined`. If not provided, the `beginRoot` will default to the root node of the tree.
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
@@ -1283,7 +1293,7 @@ export class BinaryTree = BinaryTreeNode
dfs>(
callback: C = this._defaultOneParamCallback as C,
pattern: DFSOrderPattern = 'in',
- beginRoot: BTNodeKeyOrNode