data-structure-typed 1.18.8 → 1.19.1
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.
- package/README.md +169 -168
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +182 -148
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +288 -316
- package/dist/data-structures/binary-tree/avl-tree.d.ts +22 -14
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +11 -26
- package/dist/data-structures/binary-tree/bst.d.ts +62 -74
- package/dist/data-structures/binary-tree/bst.js +72 -96
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -14
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +186 -17
- package/dist/data-structures/binary-tree/tree-multiset.js +712 -28
- package/dist/data-structures/graph/abstract-graph.d.ts +107 -49
- package/dist/data-structures/graph/abstract-graph.js +104 -55
- package/dist/data-structures/graph/directed-graph.d.ts +95 -94
- package/dist/data-structures/graph/directed-graph.js +95 -95
- package/dist/data-structures/graph/undirected-graph.d.ts +62 -61
- package/dist/data-structures/graph/undirected-graph.js +62 -61
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +10 -15
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +3 -4
- package/dist/data-structures/interfaces/rb-tree.d.ts +1 -2
- package/dist/data-structures/interfaces/tree-multiset.d.ts +3 -3
- package/dist/data-structures/types/abstract-binary-tree.d.ts +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/utils.d.ts +0 -18
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +3 -8
- package/dist/utils/utils.js +1 -83
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +6 -2
- package/tsconfig.json +0 -17
|
@@ -8,52 +8,38 @@
|
|
|
8
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 = any,
|
|
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
|
|
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
|
-
*
|
|
16
|
-
* @param {T} [val] - The
|
|
17
|
-
* tree node. If no value is provided, it will be
|
|
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
|
|
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():
|
|
30
|
-
set left(v:
|
|
31
|
-
private _right
|
|
32
|
-
get right():
|
|
33
|
-
set right(v:
|
|
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():
|
|
36
|
-
set parent(v:
|
|
37
|
-
private _count;
|
|
38
|
-
get count(): number;
|
|
39
|
-
set count(v: number);
|
|
33
|
+
get parent(): NEIGHBOR | null | undefined;
|
|
34
|
+
set parent(v: NEIGHBOR | null | undefined);
|
|
40
35
|
private _height;
|
|
41
36
|
get height(): number;
|
|
42
37
|
set height(v: number);
|
|
43
|
-
get familyPosition(): FamilyPosition;
|
|
44
|
-
abstract createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
45
|
-
/**
|
|
46
|
-
* The function swaps the location of two nodes in a binary tree.
|
|
47
|
-
* @param {FAMILY} destNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
|
|
48
|
-
* @returns the `swapNode` object after swapping its properties with the properties of `this` object.
|
|
49
|
-
*/
|
|
50
|
-
swapLocation(destNode: FAMILY): FAMILY;
|
|
51
38
|
/**
|
|
52
|
-
* The
|
|
53
|
-
* @returns
|
|
54
|
-
* `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`.
|
|
55
41
|
*/
|
|
56
|
-
|
|
42
|
+
get familyPosition(): FamilyPosition;
|
|
57
43
|
}
|
|
58
44
|
export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode> implements IAbstractBinaryTree<N> {
|
|
59
45
|
/**
|
|
@@ -62,8 +48,18 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
62
48
|
* tree.
|
|
63
49
|
*/
|
|
64
50
|
protected constructor(options?: AbstractBinaryTreeOptions);
|
|
51
|
+
private _root;
|
|
52
|
+
get root(): N | null;
|
|
53
|
+
private _size;
|
|
54
|
+
get size(): number;
|
|
65
55
|
private _loopType;
|
|
66
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;
|
|
67
63
|
private _visitedId;
|
|
68
64
|
get visitedId(): BinaryTreeNodeId[];
|
|
69
65
|
private _visitedVal;
|
|
@@ -74,21 +70,17 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
74
70
|
get visitedCount(): number[];
|
|
75
71
|
private _visitedLeftSum;
|
|
76
72
|
get visitedLeftSum(): number[];
|
|
77
|
-
|
|
78
|
-
get autoIncrementId(): boolean;
|
|
79
|
-
private _maxId;
|
|
80
|
-
get maxId(): number;
|
|
81
|
-
private _isMergeDuplicatedVal;
|
|
82
|
-
get isMergeDuplicatedVal(): boolean;
|
|
83
|
-
private _root;
|
|
84
|
-
get root(): N | null;
|
|
85
|
-
private _size;
|
|
86
|
-
get size(): number;
|
|
87
|
-
private _count;
|
|
88
|
-
get count(): number;
|
|
89
|
-
abstract createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
73
|
+
abstract createNode(id: BinaryTreeNodeId, val?: N['val']): N | null;
|
|
90
74
|
/**
|
|
91
|
-
* The
|
|
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;
|
|
82
|
+
/**
|
|
83
|
+
* The clear() function resets the root, size, and maxId properties to their initial values.
|
|
92
84
|
*/
|
|
93
85
|
clear(): void;
|
|
94
86
|
/**
|
|
@@ -97,50 +89,49 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
97
89
|
*/
|
|
98
90
|
isEmpty(): boolean;
|
|
99
91
|
/**
|
|
100
|
-
* The `add` function
|
|
101
|
-
*
|
|
102
|
-
* @param
|
|
103
|
-
*
|
|
104
|
-
* @param {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
|
|
108
|
-
* 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`.
|
|
109
99
|
*/
|
|
110
100
|
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
111
101
|
/**
|
|
112
|
-
* The function adds a new node to
|
|
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.
|
|
113
104
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
|
|
114
105
|
* either a node object (`N`) or `null`.
|
|
115
106
|
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
|
|
116
107
|
* child.
|
|
117
|
-
* @returns either the left
|
|
118
|
-
* `undefined` in certain cases.
|
|
108
|
+
* @returns either the left child node, the right child node, or undefined.
|
|
119
109
|
*/
|
|
120
110
|
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
121
111
|
/**
|
|
122
|
-
* The `addMany` function
|
|
112
|
+
* The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes or
|
|
123
113
|
* null/undefined values.
|
|
124
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of
|
|
125
|
-
*
|
|
126
|
-
* @returns The function `addMany` returns an array of `N
|
|
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`.
|
|
127
117
|
*/
|
|
128
118
|
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
129
119
|
/**
|
|
130
|
-
* The `fill` function clears the current data and
|
|
131
|
-
*
|
|
132
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of
|
|
133
|
-
* array
|
|
134
|
-
* @returns
|
|
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.
|
|
135
125
|
*/
|
|
136
126
|
fill(data: N[] | Array<N['val']>): boolean;
|
|
137
127
|
/**
|
|
138
128
|
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
|
|
139
129
|
* node that needs to be balanced.
|
|
140
|
-
* @param {N | BinaryTreeNodeId
|
|
130
|
+
* @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
|
|
131
|
+
* node ID (`BinaryTreeNodeId`).
|
|
141
132
|
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
142
|
-
* whether to ignore the count of the
|
|
143
|
-
* not be
|
|
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`
|
|
144
135
|
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
145
136
|
*/
|
|
146
137
|
remove(nodeOrId: N | BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
@@ -151,69 +142,68 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
151
142
|
*/
|
|
152
143
|
getDepth(beginRoot: N | BinaryTreeNodeId | null): number;
|
|
153
144
|
/**
|
|
154
|
-
* The `getHeight` function calculates the maximum height of a binary tree
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* 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`.
|
|
159
149
|
* @returns the height of the binary tree.
|
|
160
150
|
*/
|
|
161
151
|
getHeight(beginRoot?: N | BinaryTreeNodeId | null): number;
|
|
162
152
|
/**
|
|
163
153
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
|
|
164
154
|
* approach.
|
|
165
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
166
|
-
*
|
|
167
|
-
*
|
|
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.
|
|
168
158
|
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
169
159
|
*/
|
|
170
160
|
getMinHeight(beginRoot?: N | null): number;
|
|
171
161
|
/**
|
|
172
|
-
* The function checks if a binary tree is balanced by comparing the minimum height and the
|
|
173
|
-
*
|
|
174
|
-
*
|
|
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.
|
|
175
166
|
* @returns The method is returning a boolean value.
|
|
176
167
|
*/
|
|
177
|
-
|
|
168
|
+
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
178
169
|
/**
|
|
179
|
-
* The function `getNodes` returns an array of
|
|
180
|
-
* 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.
|
|
181
171
|
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
182
172
|
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
183
173
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
184
174
|
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
185
175
|
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
186
|
-
* return only one node that matches the `nodeProperty` or `propertyName
|
|
187
|
-
* function will stop traversing the tree and return the first matching node. If `
|
|
188
|
-
* @returns
|
|
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).
|
|
189
179
|
*/
|
|
190
180
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
191
181
|
/**
|
|
192
|
-
* The function checks if a binary tree node has a specific property
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* 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.
|
|
196
185
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
197
|
-
* specifies the name of the property to
|
|
186
|
+
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
|
|
198
187
|
* @returns a boolean value.
|
|
199
188
|
*/
|
|
200
189
|
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
201
190
|
/**
|
|
202
|
-
* The function returns the first
|
|
203
|
-
*
|
|
204
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or
|
|
205
|
-
*
|
|
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.
|
|
206
195
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
207
|
-
* specifies the property
|
|
208
|
-
*
|
|
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.
|
|
209
200
|
*/
|
|
210
201
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
211
202
|
/**
|
|
212
|
-
* The function getPathToRoot returns an array of
|
|
213
|
-
* root
|
|
214
|
-
* @param node - The `node`
|
|
215
|
-
* @returns The function `getPathToRoot` returns an array of `N`
|
|
216
|
-
* 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[]`).
|
|
217
207
|
*/
|
|
218
208
|
getPathToRoot(node: N): N[];
|
|
219
209
|
getLeftMost(): N | null;
|
|
@@ -221,7 +211,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
221
211
|
getRightMost(): N | null;
|
|
222
212
|
getRightMost(node: N): N;
|
|
223
213
|
/**
|
|
224
|
-
* The function
|
|
214
|
+
* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
|
|
225
215
|
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
|
|
226
216
|
* @returns a boolean value.
|
|
227
217
|
*/
|
|
@@ -234,34 +224,30 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
234
224
|
*/
|
|
235
225
|
isBST(node?: N | null): boolean;
|
|
236
226
|
/**
|
|
237
|
-
* The function calculates the size
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
|
|
242
|
-
* 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`.
|
|
243
231
|
*/
|
|
244
|
-
|
|
232
|
+
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
245
233
|
/**
|
|
246
|
-
* The function `subTreeSum` calculates the sum of a specified property in a binary tree
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* @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`.
|
|
254
241
|
*/
|
|
255
242
|
subTreeSum(subTreeRoot: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
|
|
256
243
|
/**
|
|
257
244
|
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
|
|
258
245
|
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
259
|
-
* tree or the ID of a binary tree
|
|
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.
|
|
260
247
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
261
|
-
* each node in the subtree should be incremented
|
|
248
|
+
* each node in the subtree should be incremented.
|
|
262
249
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
263
|
-
* specifies the property of the binary tree node that should be modified.
|
|
264
|
-
* value is provided for `propertyName`, it defaults to 'id'.
|
|
250
|
+
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
|
|
265
251
|
* @returns a boolean value.
|
|
266
252
|
*/
|
|
267
253
|
subTreeAdd(subTreeRoot: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
@@ -269,27 +255,22 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
269
255
|
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
270
256
|
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
271
257
|
BFS(nodeOrPropertyName: 'node'): N[];
|
|
272
|
-
BFS(nodeOrPropertyName: 'count'): number[];
|
|
273
258
|
DFS(): BinaryTreeNodeId[];
|
|
274
259
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
275
260
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
276
261
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
277
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
278
262
|
DFSIterative(): BinaryTreeNodeId[];
|
|
279
263
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
280
264
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
281
265
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
282
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
283
266
|
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
284
267
|
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
285
268
|
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
286
269
|
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
287
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
288
270
|
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
289
271
|
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
290
272
|
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
291
273
|
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
292
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
293
274
|
/**
|
|
294
275
|
* The function returns the predecessor of a given node in a binary tree.
|
|
295
276
|
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
@@ -299,56 +280,109 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
299
280
|
morris(): BinaryTreeNodeId[];
|
|
300
281
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
301
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
|
+
*/
|
|
302
287
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
303
|
-
|
|
288
|
+
/**
|
|
289
|
+
* The function sets the loop type for a protected variable.
|
|
290
|
+
* @param {LoopType} value - The value parameter is of type LoopType.
|
|
291
|
+
*/
|
|
304
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
|
+
*/
|
|
305
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
|
+
*/
|
|
306
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
|
+
*/
|
|
307
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
|
+
*/
|
|
308
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
|
+
*/
|
|
309
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
|
+
*/
|
|
310
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
|
+
*/
|
|
311
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
|
+
*/
|
|
312
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
|
+
*/
|
|
313
341
|
protected _setRoot(v: N | null): void;
|
|
342
|
+
/**
|
|
343
|
+
* The function sets the size of a protected variable.
|
|
344
|
+
* @param {number} v - number
|
|
345
|
+
*/
|
|
314
346
|
protected _setSize(v: number): void;
|
|
315
|
-
protected _setCount(v: number): void;
|
|
316
347
|
/**
|
|
317
|
-
* The function resets the values of several arrays used for tracking visited nodes and their
|
|
348
|
+
* The function `_resetResults` resets the values of several arrays used for tracking visited nodes and their
|
|
349
|
+
* properties.
|
|
318
350
|
*/
|
|
319
351
|
protected _resetResults(): void;
|
|
320
352
|
/**
|
|
321
353
|
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
322
354
|
* a result array.
|
|
323
|
-
* @param cur - The current
|
|
324
|
-
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
* 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.
|
|
328
359
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
329
|
-
* specifies the property
|
|
330
|
-
*
|
|
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
|
|
331
362
|
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
332
363
|
* stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
|
|
333
364
|
* `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
|
|
334
|
-
* @returns a boolean value indicating whether
|
|
365
|
+
* @returns a boolean value indicating whether only one matching node should be pushed into the result array.
|
|
335
366
|
*/
|
|
336
367
|
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
|
|
337
368
|
/**
|
|
338
|
-
* The function `_accumulatedByPropertyName`
|
|
339
|
-
*
|
|
340
|
-
* @param
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* 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
|
|
344
374
|
*/
|
|
345
375
|
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
346
376
|
/**
|
|
347
|
-
* The
|
|
348
|
-
*
|
|
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.
|
|
349
383
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
350
|
-
* can accept a
|
|
351
|
-
* @returns The method returns an
|
|
384
|
+
* can accept either a `NodeOrPropertyName` type or be undefined.
|
|
385
|
+
* @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
|
|
352
386
|
*/
|
|
353
387
|
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
354
388
|
}
|