min-heap-typed 1.50.0 → 1.50.2
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/dist/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/data-structures/binary-tree/bst.js +30 -71
- package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/data-structures/graph/abstract-graph.js +3 -0
- package/dist/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/data-structures/graph/directed-graph.js +26 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/data-structures/graph/undirected-graph.js +25 -0
- package/dist/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/data-structures/hash/hash-map.js +160 -25
- package/dist/data-structures/heap/heap.d.ts +66 -6
- package/dist/data-structures/heap/heap.js +66 -6
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/queue/deque.d.ts +49 -19
- package/dist/data-structures/queue/deque.js +101 -47
- package/dist/data-structures/queue/queue.d.ts +39 -5
- package/dist/data-structures/queue/queue.js +47 -5
- package/dist/data-structures/stack/stack.d.ts +16 -0
- package/dist/data-structures/stack/stack.js +22 -0
- package/dist/data-structures/trie/trie.d.ts +38 -1
- package/dist/data-structures/trie/trie.js +41 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +172 -19
- package/src/data-structures/binary-tree/avl-tree.ts +97 -97
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +89 -131
- package/src/data-structures/binary-tree/rb-tree.ts +127 -155
- package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +28 -0
- package/src/data-structures/hash/hash-map.ts +175 -34
- package/src/data-structures/heap/heap.ts +66 -6
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
- package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/queue/deque.ts +108 -49
- package/src/data-structures/queue/queue.ts +51 -5
- package/src/data-structures/stack/stack.ts +24 -0
- package/src/data-structures/trie/trie.ts +45 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -12,19 +12,47 @@ import { IterableEntryBase } from '../base';
|
|
|
12
12
|
/**
|
|
13
13
|
* Represents a node in a binary tree.
|
|
14
14
|
* @template V - The type of data stored in the node.
|
|
15
|
-
* @template
|
|
15
|
+
* @template NODE - The type of the family relationship in the binary tree.
|
|
16
16
|
*/
|
|
17
|
-
export declare class BinaryTreeNode<K = any, V = any,
|
|
17
|
+
export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
|
|
18
18
|
key: K;
|
|
19
19
|
value?: V;
|
|
20
|
-
parent?:
|
|
20
|
+
parent?: NODE;
|
|
21
|
+
/**
|
|
22
|
+
* The constructor function initializes an object with a key and an optional value.
|
|
23
|
+
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
24
|
+
* constructor. It is used to set the value of the "key" property of the object being created.
|
|
25
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
26
|
+
* value associated with the key in the constructor.
|
|
27
|
+
*/
|
|
21
28
|
constructor(key: K, value?: V);
|
|
22
|
-
protected _left?:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
protected _left?: NODE | null;
|
|
30
|
+
/**
|
|
31
|
+
* The function returns the value of the `_left` property, which can be of type `NODE`, `null`, or
|
|
32
|
+
* `undefined`.
|
|
33
|
+
* @returns The left node of the current node is being returned. It can be either a NODE object,
|
|
34
|
+
* null, or undefined.
|
|
35
|
+
*/
|
|
36
|
+
get left(): NODE | null | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The function sets the left child of a node and updates its parent reference.
|
|
39
|
+
* @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
40
|
+
* `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
set left(v: NODE | null | undefined);
|
|
43
|
+
protected _right?: NODE | null;
|
|
44
|
+
/**
|
|
45
|
+
* The function returns the right node of a binary tree or null if it doesn't exist.
|
|
46
|
+
* @returns The method is returning the value of the `_right` property, which can be a `NODE` object,
|
|
47
|
+
* `null`, or `undefined`.
|
|
48
|
+
*/
|
|
49
|
+
get right(): NODE | null | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The function sets the right child of a node and updates its parent.
|
|
52
|
+
* @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
53
|
+
* `undefined`.
|
|
54
|
+
*/
|
|
55
|
+
set right(v: NODE | null | undefined);
|
|
28
56
|
/**
|
|
29
57
|
* Get the position of the node within its family.
|
|
30
58
|
* @returns {FamilyPosition} - The family position of the node.
|
|
@@ -38,7 +66,7 @@ export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K
|
|
|
38
66
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
39
67
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
40
68
|
*/
|
|
41
|
-
export declare class BinaryTree<K = any, V = any,
|
|
69
|
+
export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, NODE, TREE> = BinaryTree<K, V, NODE, BinaryTreeNested<K, V, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, NODE, TREE> {
|
|
42
70
|
iterationType: IterationType;
|
|
43
71
|
/**
|
|
44
72
|
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
|
|
@@ -49,20 +77,33 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
49
77
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
50
78
|
* required.
|
|
51
79
|
*/
|
|
52
|
-
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V,
|
|
80
|
+
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K>);
|
|
53
81
|
protected _extractor: (key: K) => number;
|
|
82
|
+
/**
|
|
83
|
+
* The function returns the value of the `_extractor` property.
|
|
84
|
+
* @returns The `_extractor` property is being returned.
|
|
85
|
+
*/
|
|
54
86
|
get extractor(): (key: K) => number;
|
|
55
|
-
protected _root?:
|
|
56
|
-
|
|
87
|
+
protected _root?: NODE | null;
|
|
88
|
+
/**
|
|
89
|
+
* The function returns the root node, which can be of type NODE, null, or undefined.
|
|
90
|
+
* @returns The method is returning the value of the `_root` property, which can be of type `NODE`,
|
|
91
|
+
* `null`, or `undefined`.
|
|
92
|
+
*/
|
|
93
|
+
get root(): NODE | null | undefined;
|
|
57
94
|
protected _size: number;
|
|
95
|
+
/**
|
|
96
|
+
* The function returns the size of an object.
|
|
97
|
+
* @returns The size of the object, which is a number.
|
|
98
|
+
*/
|
|
58
99
|
get size(): number;
|
|
59
100
|
/**
|
|
60
101
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
61
102
|
* @param {K} key - The key for the new node.
|
|
62
103
|
* @param {V} value - The value for the new node.
|
|
63
|
-
* @returns {
|
|
104
|
+
* @returns {NODE} - The newly created BinaryTreeNode.
|
|
64
105
|
*/
|
|
65
|
-
createNode(key: K, value?: V):
|
|
106
|
+
createNode(key: K, value?: V): NODE;
|
|
66
107
|
/**
|
|
67
108
|
* The function creates a binary tree with the given options.
|
|
68
109
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -72,14 +113,14 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
72
113
|
*/
|
|
73
114
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
74
115
|
/**
|
|
75
|
-
* The function `
|
|
76
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V,
|
|
116
|
+
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
117
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
77
118
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
78
|
-
* `
|
|
119
|
+
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
|
|
79
120
|
* is provided, it will be `undefined`.
|
|
80
|
-
* @returns a value of type
|
|
121
|
+
* @returns a value of type NODE (node), or null, or undefined.
|
|
81
122
|
*/
|
|
82
|
-
|
|
123
|
+
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | null | undefined;
|
|
83
124
|
/**
|
|
84
125
|
* Time Complexity: O(n)
|
|
85
126
|
* Space Complexity: O(log n)
|
|
@@ -90,7 +131,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
90
131
|
*
|
|
91
132
|
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
92
133
|
* key, otherwise it returns the key itself.
|
|
93
|
-
* @param {K |
|
|
134
|
+
* @param {K | NODE | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`,
|
|
94
135
|
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
95
136
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
96
137
|
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
@@ -98,74 +139,70 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
98
139
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
99
140
|
* itself if it is not a valid node key.
|
|
100
141
|
*/
|
|
101
|
-
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
142
|
+
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
102
143
|
/**
|
|
103
144
|
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
104
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,
|
|
105
|
-
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class
|
|
145
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
|
|
146
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class NODE.
|
|
106
147
|
*/
|
|
107
|
-
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
148
|
+
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
108
149
|
/**
|
|
109
150
|
* The function checks if a given value is an entry in a binary tree node.
|
|
110
|
-
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,
|
|
111
|
-
* two type parameters V and
|
|
151
|
+
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
|
|
152
|
+
* two type parameters V and NODE, representing the value and node type respectively.
|
|
112
153
|
* @returns a boolean value.
|
|
113
154
|
*/
|
|
114
|
-
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
115
|
-
/**
|
|
116
|
-
* Time complexity: O(n)
|
|
117
|
-
* Space complexity: O(log n)
|
|
118
|
-
*/
|
|
155
|
+
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
|
|
119
156
|
/**
|
|
120
157
|
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
121
158
|
* BinaryTreeNode and its key is not NaN.
|
|
122
159
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
123
160
|
* @returns a boolean value.
|
|
124
161
|
*/
|
|
125
|
-
isRealNode(node: KeyOrNodeOrEntry<K, V,
|
|
162
|
+
isRealNode(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
|
|
126
163
|
/**
|
|
127
164
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
128
165
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
129
166
|
* @returns a boolean value.
|
|
130
167
|
*/
|
|
131
|
-
isNIL(node: KeyOrNodeOrEntry<K, V,
|
|
168
|
+
isNIL(node: KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
132
169
|
/**
|
|
133
170
|
* The function checks if a given node is a real node or null.
|
|
134
171
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
135
172
|
* @returns a boolean value.
|
|
136
173
|
*/
|
|
137
|
-
isNodeOrNull(node: KeyOrNodeOrEntry<K, V,
|
|
174
|
+
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
138
175
|
/**
|
|
139
|
-
* Time Complexity O(
|
|
176
|
+
* Time Complexity O(n)
|
|
140
177
|
* Space Complexity O(1)
|
|
141
178
|
*/
|
|
142
179
|
/**
|
|
143
|
-
* Time Complexity O(
|
|
180
|
+
* Time Complexity O(n)
|
|
144
181
|
* Space Complexity O(1)
|
|
145
182
|
*
|
|
146
183
|
* The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
|
|
147
184
|
* existing node with the same key.
|
|
148
185
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
|
|
149
186
|
* @param {V} [value] - The value to be inserted into the binary tree.
|
|
150
|
-
* @returns The function `add` returns either a node (`
|
|
187
|
+
* @returns The function `add` returns either a node (`NODE`), `null`, or `undefined`.
|
|
151
188
|
*/
|
|
152
|
-
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
189
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
153
190
|
/**
|
|
154
|
-
* Time Complexity: O(k
|
|
191
|
+
* Time Complexity: O(k * n)
|
|
155
192
|
* Space Complexity: O(1)
|
|
156
193
|
* Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
|
|
157
194
|
*/
|
|
158
195
|
/**
|
|
159
|
-
* Time Complexity: O(k
|
|
196
|
+
* Time Complexity: O(k * n)
|
|
160
197
|
* Space Complexity: O(1)
|
|
161
198
|
*
|
|
162
199
|
* The `addMany` function takes in a collection of keysOrNodesOrEntries and an optional collection of values, and
|
|
163
200
|
* adds each node with its corresponding value to the data structure.
|
|
164
201
|
* @param keysOrNodesOrEntries - An iterable collection of KeyOrNodeOrEntry objects.
|
|
165
202
|
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
166
|
-
* @returns The function `addMany` returns an array of `
|
|
203
|
+
* @returns The function `addMany` returns an array of `NODE`, `null`, or `undefined` values.
|
|
167
204
|
*/
|
|
168
|
-
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V,
|
|
205
|
+
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
169
206
|
/**
|
|
170
207
|
* Time Complexity: O(k * n)
|
|
171
208
|
* Space Complexity: O(1)
|
|
@@ -177,81 +214,73 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
177
214
|
*
|
|
178
215
|
* The `refill` function clears the current data and adds new key-value pairs to the data structure.
|
|
179
216
|
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries. These can be of type
|
|
180
|
-
* KeyOrNodeOrEntry<K, V,
|
|
217
|
+
* KeyOrNodeOrEntry<K, V, NODE>.
|
|
181
218
|
* @param [values] - The `values` parameter is an optional iterable that contains the values to be
|
|
182
219
|
* associated with the keys or nodes or entries in the `keysOrNodesOrEntries` parameter. If provided,
|
|
183
220
|
* the values will be associated with the corresponding keys or nodes or entries in the
|
|
184
221
|
* `keysOrNodesOrEntries` iterable
|
|
185
222
|
*/
|
|
186
|
-
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
|
|
224
|
+
delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
225
|
+
delete<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
226
|
+
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
227
|
+
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
228
|
+
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
229
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
230
|
+
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
231
|
+
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
232
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
195
233
|
/**
|
|
196
234
|
* Time Complexity: O(n)
|
|
197
|
-
* Space Complexity: O(
|
|
235
|
+
* Space Complexity: O(log n)
|
|
198
236
|
*/
|
|
199
237
|
/**
|
|
200
238
|
* Time Complexity: O(n)
|
|
201
|
-
* Space Complexity: O(
|
|
239
|
+
* Space Complexity: O(log n)
|
|
202
240
|
*
|
|
203
|
-
* The function
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* @param
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* @returns
|
|
241
|
+
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
242
|
+
* recursive or iterative iteration.
|
|
243
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
244
|
+
* It is used to find the node with the matching key value.
|
|
245
|
+
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
|
|
246
|
+
* the node with the given key should be performed iteratively or recursively. It has two possible
|
|
247
|
+
* values:
|
|
248
|
+
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
249
|
+
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
211
250
|
*/
|
|
212
|
-
|
|
251
|
+
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
252
|
+
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
253
|
+
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
254
|
+
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
255
|
+
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
256
|
+
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
257
|
+
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
213
258
|
/**
|
|
214
|
-
* Time Complexity: O(
|
|
259
|
+
* Time Complexity: O(1)
|
|
215
260
|
* Space Complexity: O(1)
|
|
216
261
|
*/
|
|
217
262
|
/**
|
|
218
|
-
* Time Complexity: O(
|
|
219
|
-
* Space Complexity: O(
|
|
263
|
+
* Time Complexity: O(1)
|
|
264
|
+
* Space Complexity: O(1)
|
|
220
265
|
*
|
|
221
|
-
*
|
|
222
|
-
* iterative traversal.
|
|
223
|
-
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
224
|
-
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
225
|
-
* `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
226
|
-
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
227
|
-
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
228
|
-
* values:
|
|
229
|
-
* @returns the height of the binary tree.
|
|
266
|
+
* Clear the binary tree, removing all nodes.
|
|
230
267
|
*/
|
|
231
|
-
|
|
268
|
+
clear(): void;
|
|
232
269
|
/**
|
|
233
|
-
* Time Complexity: O(
|
|
234
|
-
* Space Complexity: O(
|
|
235
|
-
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
270
|
+
* Time Complexity: O(1)
|
|
271
|
+
* Space Complexity: O(1)
|
|
236
272
|
*/
|
|
237
273
|
/**
|
|
238
|
-
* Time Complexity: O(
|
|
239
|
-
* Space Complexity: O(
|
|
274
|
+
* Time Complexity: O(1)
|
|
275
|
+
* Space Complexity: O(1)
|
|
240
276
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
244
|
-
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
245
|
-
* type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
246
|
-
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
247
|
-
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
248
|
-
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
277
|
+
* Check if the binary tree is empty.
|
|
278
|
+
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
249
279
|
*/
|
|
250
|
-
|
|
280
|
+
isEmpty(): boolean;
|
|
251
281
|
/**
|
|
252
282
|
* Time Complexity: O(n)
|
|
253
283
|
* Space Complexity: O(log n)
|
|
254
|
-
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
255
284
|
*/
|
|
256
285
|
/**
|
|
257
286
|
* Time Complexity: O(n)
|
|
@@ -259,93 +288,104 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
259
288
|
*
|
|
260
289
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
261
290
|
* height of the tree.
|
|
262
|
-
* @param {K |
|
|
291
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
263
292
|
* for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
|
|
264
|
-
* value of a binary tree node), `
|
|
293
|
+
* value of a binary tree node), `NODE` (a node of a binary tree), `null`, or `undefined`. If
|
|
265
294
|
* @returns a boolean value.
|
|
266
295
|
*/
|
|
267
|
-
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V,
|
|
268
|
-
/**
|
|
269
|
-
* Time Complexity: O(n)
|
|
270
|
-
* Space Complexity: O(log n)
|
|
271
|
-
*/
|
|
272
|
-
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
273
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
274
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
296
|
+
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
275
297
|
/**
|
|
276
298
|
* Time Complexity: O(n)
|
|
277
|
-
* Space Complexity: O(
|
|
299
|
+
* Space Complexity: O(1)
|
|
278
300
|
*/
|
|
279
|
-
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
280
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
281
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
282
301
|
/**
|
|
283
302
|
* Time Complexity: O(n)
|
|
284
|
-
* Space Complexity: O(
|
|
303
|
+
* Space Complexity: O(1)
|
|
304
|
+
*
|
|
305
|
+
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
306
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the root
|
|
307
|
+
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
|
|
308
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
309
|
+
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
310
|
+
* possible values:
|
|
311
|
+
* @returns a boolean value.
|
|
285
312
|
*/
|
|
286
|
-
|
|
287
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
288
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
313
|
+
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
289
314
|
/**
|
|
290
315
|
* Time Complexity: O(n)
|
|
291
|
-
* Space Complexity: O(
|
|
316
|
+
* Space Complexity: O(1)
|
|
292
317
|
*/
|
|
293
318
|
/**
|
|
294
319
|
* Time Complexity: O(n)
|
|
295
|
-
* Space Complexity: O(
|
|
320
|
+
* Space Complexity: O(1)
|
|
296
321
|
*
|
|
297
|
-
* The function
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* @param
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* @returns
|
|
305
|
-
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
322
|
+
* The function calculates the depth of a given node in a binary tree.
|
|
323
|
+
* @param {K | NODE | null | undefined} dist - The `dist` parameter represents the node in
|
|
324
|
+
* the binary tree whose depth we want to find. It can be of type `K`, `NODE`, `null`, or
|
|
325
|
+
* `undefined`.
|
|
326
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
327
|
+
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
|
|
328
|
+
* `NODE` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
329
|
+
* @returns the depth of the `dist` relative to the `beginRoot`.
|
|
306
330
|
*/
|
|
307
|
-
|
|
308
|
-
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
309
|
-
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
310
|
-
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
331
|
+
getDepth(dist: KeyOrNodeOrEntry<K, V, NODE>, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): number;
|
|
311
332
|
/**
|
|
312
|
-
* Time Complexity: O(
|
|
333
|
+
* Time Complexity: O(n)
|
|
313
334
|
* Space Complexity: O(1)
|
|
314
335
|
*/
|
|
315
336
|
/**
|
|
316
|
-
* Time Complexity: O(
|
|
317
|
-
* Space Complexity: O(
|
|
337
|
+
* Time Complexity: O(n)
|
|
338
|
+
* Space Complexity: O(log n)
|
|
318
339
|
*
|
|
319
|
-
*
|
|
340
|
+
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
|
|
341
|
+
* iterative traversal.
|
|
342
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
343
|
+
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
344
|
+
* `K`, `NODE`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
345
|
+
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
346
|
+
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
347
|
+
* values:
|
|
348
|
+
* @returns the height of the binary tree.
|
|
320
349
|
*/
|
|
321
|
-
|
|
350
|
+
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
322
351
|
/**
|
|
323
|
-
* Time Complexity: O(
|
|
324
|
-
* Space Complexity: O(
|
|
352
|
+
* Time Complexity: O(n)
|
|
353
|
+
* Space Complexity: O(log n)
|
|
325
354
|
*/
|
|
326
355
|
/**
|
|
327
|
-
* Time Complexity: O(
|
|
328
|
-
* Space Complexity: O(
|
|
356
|
+
* Time Complexity: O(n)
|
|
357
|
+
* Space Complexity: O(log n)
|
|
329
358
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
359
|
+
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
360
|
+
* recursive or iterative approach.
|
|
361
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
362
|
+
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
363
|
+
* type `K`, `NODE`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
364
|
+
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
365
|
+
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
366
|
+
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
332
367
|
*/
|
|
333
|
-
|
|
368
|
+
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
334
369
|
/**
|
|
370
|
+
* Time Complexity: O(log n)
|
|
371
|
+
* Space Complexity: O(log n)
|
|
372
|
+
* /
|
|
373
|
+
|
|
374
|
+
/**
|
|
335
375
|
* Time Complexity: O(log n)
|
|
336
376
|
* Space Complexity: O(log n)
|
|
337
377
|
*
|
|
338
378
|
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
|
|
339
379
|
* structure, with the option to reverse the order of the nodes.
|
|
340
|
-
* @param {K |
|
|
341
|
-
* starting node from which you want to find the path to the root. It can be of type `K`, `
|
|
380
|
+
* @param {K | NODE | null | undefined} beginNode - The `beginRoot` parameter represents the
|
|
381
|
+
* starting node from which you want to find the path to the root. It can be of type `K`, `NODE`,
|
|
342
382
|
* `null`, or `undefined`.
|
|
343
383
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
344
384
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
345
385
|
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
346
|
-
* @returns The function `getPathToRoot` returns an array of nodes (`
|
|
386
|
+
* @returns The function `getPathToRoot` returns an array of nodes (`NODE[]`).
|
|
347
387
|
*/
|
|
348
|
-
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V,
|
|
388
|
+
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
349
389
|
/**
|
|
350
390
|
* Time Complexity: O(log n)
|
|
351
391
|
* Space Complexity: O(1)
|
|
@@ -356,15 +396,15 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
356
396
|
*
|
|
357
397
|
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
|
|
358
398
|
* iteratively.
|
|
359
|
-
* @param {K |
|
|
360
|
-
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `
|
|
399
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
400
|
+
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `NODE` (a
|
|
361
401
|
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
|
|
362
402
|
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
|
|
363
403
|
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
|
|
364
|
-
* @returns The function `getLeftMost` returns the leftmost node (`
|
|
404
|
+
* @returns The function `getLeftMost` returns the leftmost node (`NODE`) in the binary tree. If there
|
|
365
405
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
366
406
|
*/
|
|
367
|
-
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V,
|
|
407
|
+
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
368
408
|
/**
|
|
369
409
|
* Time Complexity: O(log n)
|
|
370
410
|
* Space Complexity: O(1)
|
|
@@ -375,47 +415,30 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
375
415
|
*
|
|
376
416
|
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
|
|
377
417
|
* iteratively.
|
|
378
|
-
* @param {K |
|
|
379
|
-
* starting node from which we want to find the rightmost node. It can be of type `K`, `
|
|
418
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
419
|
+
* starting node from which we want to find the rightmost node. It can be of type `K`, `NODE`,
|
|
380
420
|
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
|
|
381
421
|
* current object.
|
|
382
422
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
383
423
|
* type of iteration to use when finding the rightmost node. It can have one of two values:
|
|
384
|
-
* @returns The function `getRightMost` returns the rightmost node (`
|
|
424
|
+
* @returns The function `getRightMost` returns the rightmost node (`NODE`) in a binary tree. If there
|
|
385
425
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
386
426
|
*/
|
|
387
|
-
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V,
|
|
427
|
+
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
388
428
|
/**
|
|
389
429
|
* Time Complexity: O(log n)
|
|
390
430
|
* Space Complexity: O(1)
|
|
391
431
|
*/
|
|
392
432
|
/**
|
|
393
|
-
* Time Complexity: O(n)
|
|
433
|
+
* Time Complexity: O(log n)
|
|
394
434
|
* Space Complexity: O(1)
|
|
395
435
|
*
|
|
396
|
-
* The function
|
|
397
|
-
* @param {
|
|
398
|
-
*
|
|
399
|
-
* @
|
|
400
|
-
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
401
|
-
* possible values:
|
|
402
|
-
* @returns a boolean value.
|
|
403
|
-
*/
|
|
404
|
-
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
405
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
406
|
-
dfs<C extends BTNCallback<N | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
407
|
-
/**
|
|
408
|
-
* Time complexity: O(n)
|
|
409
|
-
* Space complexity: O(n)
|
|
410
|
-
*/
|
|
411
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
412
|
-
bfs<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
413
|
-
/**
|
|
414
|
-
* Time complexity: O(n)
|
|
415
|
-
* Space complexity: O(n)
|
|
436
|
+
* The function returns the predecessor of a given node in a tree.
|
|
437
|
+
* @param {NODE} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
438
|
+
* tree.
|
|
439
|
+
* @returns the predecessor of the given 'node'.
|
|
416
440
|
*/
|
|
417
|
-
|
|
418
|
-
listLevels<C extends BTNCallback<N | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
441
|
+
getPredecessor(node: NODE): NODE;
|
|
419
442
|
/**
|
|
420
443
|
* Time Complexity: O(log n)
|
|
421
444
|
* Space Complexity: O(1)
|
|
@@ -424,19 +447,18 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
424
447
|
* Time Complexity: O(log n)
|
|
425
448
|
* Space Complexity: O(1)
|
|
426
449
|
*
|
|
427
|
-
* The function returns the predecessor of a given node in a tree.
|
|
428
|
-
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
429
|
-
* tree.
|
|
430
|
-
* @returns the predecessor of the given 'node'.
|
|
431
|
-
*/
|
|
432
|
-
getPredecessor(node: N): N;
|
|
433
|
-
/**
|
|
434
450
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
435
|
-
* @param {K |
|
|
451
|
+
* @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
|
|
436
452
|
* @returns the successor of the given node or key. The successor is the node that comes immediately
|
|
437
453
|
* after the given node in the inorder traversal of the binary tree.
|
|
438
454
|
*/
|
|
439
|
-
getSuccessor(x?: K |
|
|
455
|
+
getSuccessor(x?: K | NODE | null): NODE | null | undefined;
|
|
456
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
457
|
+
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
458
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
459
|
+
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
460
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
461
|
+
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
440
462
|
/**
|
|
441
463
|
* Time complexity: O(n)
|
|
442
464
|
* Space complexity: O(n)
|
|
@@ -448,19 +470,19 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
448
470
|
* The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
|
|
449
471
|
* algorithm.
|
|
450
472
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
451
|
-
* the tree. It takes a single parameter of type `
|
|
473
|
+
* the tree. It takes a single parameter of type `NODE` (the type of the nodes in the tree) and returns
|
|
452
474
|
* a value of any type.
|
|
453
475
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
454
476
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
455
477
|
* following values:
|
|
456
|
-
* @param {K |
|
|
478
|
+
* @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
457
479
|
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
458
480
|
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
459
481
|
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
460
482
|
* `callback` function on each node in the binary tree. The type of the array nodes is determined
|
|
461
483
|
* by the return type of the `callback` function.
|
|
462
484
|
*/
|
|
463
|
-
morris<C extends BTNCallback<
|
|
485
|
+
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
|
|
464
486
|
/**
|
|
465
487
|
* Time complexity: O(n)
|
|
466
488
|
* Space complexity: O(n)
|
|
@@ -523,36 +545,59 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
523
545
|
* Space Complexity: O(n)
|
|
524
546
|
*
|
|
525
547
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
526
|
-
* @param {K |
|
|
548
|
+
* @param {K | NODE | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | NODE | null |
|
|
527
549
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
528
550
|
* following types:
|
|
529
551
|
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
530
552
|
*/
|
|
531
|
-
print(beginRoot?: KeyOrNodeOrEntry<K, V,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
553
|
+
print(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): void;
|
|
554
|
+
/**
|
|
555
|
+
* The function `_getIterator` is a protected generator function that returns an iterator for the
|
|
556
|
+
* key-value pairs in a binary search tree.
|
|
557
|
+
* @param node - The `node` parameter represents the current node in the binary search tree. It is an
|
|
558
|
+
* optional parameter with a default value of `this.root`, which means if no node is provided, the
|
|
559
|
+
* root node of the tree will be used as the starting point for iteration.
|
|
560
|
+
* @returns The function `_getIterator` returns an `IterableIterator` of key-value pairs `[K, V |
|
|
561
|
+
* undefined]`.
|
|
562
|
+
*/
|
|
563
|
+
protected _getIterator(node?: NODE | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
564
|
+
/**
|
|
565
|
+
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
566
|
+
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
567
|
+
* @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
|
|
568
|
+
* It can be of type `NODE`, `null`, or `undefined`.
|
|
569
|
+
* @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
|
|
570
|
+
* following properties:
|
|
571
|
+
* @returns The function `_displayAux` returns a `NodeDisplayLayout` which is an array containing the
|
|
572
|
+
* following elements:
|
|
573
|
+
* 1. `mergedLines`: An array of strings representing the lines of the node display.
|
|
574
|
+
* 2. `totalWidth`: The total width of the node display.
|
|
575
|
+
* 3. `totalHeight`: The total height of the node display.
|
|
576
|
+
* 4. `middleIndex`: The index of the middle character
|
|
577
|
+
*/
|
|
578
|
+
protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
579
|
+
protected _defaultOneParamCallback: (node: NODE | null | undefined) => K | undefined;
|
|
535
580
|
/**
|
|
536
581
|
* Swap the data of two nodes in the binary tree.
|
|
537
|
-
* @param {
|
|
538
|
-
* @param {
|
|
539
|
-
* @returns {
|
|
582
|
+
* @param {NODE} srcNode - The source node to swap.
|
|
583
|
+
* @param {NODE} destNode - The destination node to swap.
|
|
584
|
+
* @returns {NODE} - The destination node after the swap.
|
|
540
585
|
*/
|
|
541
|
-
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V,
|
|
586
|
+
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, NODE>, destNode: KeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
542
587
|
/**
|
|
543
588
|
* The function replaces an old node with a new node in a binary tree.
|
|
544
|
-
* @param {
|
|
589
|
+
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
545
590
|
* tree.
|
|
546
|
-
* @param {
|
|
591
|
+
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
|
|
547
592
|
* tree.
|
|
548
593
|
* @returns The method is returning the newNode.
|
|
549
594
|
*/
|
|
550
|
-
protected _replaceNode(oldNode:
|
|
595
|
+
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
551
596
|
/**
|
|
552
597
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
553
598
|
* it also sets the parent property of the value to undefined.
|
|
554
|
-
* @param {
|
|
555
|
-
* type `
|
|
599
|
+
* @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`, which means it can either be of
|
|
600
|
+
* type `NODE` or `null`.
|
|
556
601
|
*/
|
|
557
|
-
protected _setRoot(v:
|
|
602
|
+
protected _setRoot(v: NODE | null | undefined): void;
|
|
558
603
|
}
|