data-structure-typed 1.34.8 → 1.34.9
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +0 -0
- package/README.md +8 -8
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +280 -423
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +63 -89
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +11 -30
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +127 -214
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +19 -43
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.js +80 -122
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +147 -218
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +338 -572
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +145 -275
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +46 -87
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +90 -179
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +85 -247
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +87 -128
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/pair.js.map +1 -1
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-map.js.map +1 -1
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/hash/tree-set.js.map +1 -1
- package/dist/data-structures/heap/heap.js +56 -80
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +57 -70
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.js +63 -84
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/queue.js +57 -157
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/tree.js +32 -45
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/utils/utils.js +22 -107
- package/dist/utils/utils.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +79 -78
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +61 -141
- package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -0
- package/lib/data-structures/binary-tree/avl-tree.js +22 -0
- package/lib/data-structures/binary-tree/bst.d.ts +3 -3
- package/lib/data-structures/binary-tree/bst.js +12 -15
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +16 -18
- package/lib/data-structures/binary-tree/tree-multiset.js +26 -36
- package/lib/data-structures/graph/abstract-graph.d.ts +2 -2
- package/lib/data-structures/graph/abstract-graph.js +5 -5
- package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
- package/lib/data-structures/priority-queue/priority-queue.js +3 -3
- package/lib/interfaces/abstract-binary-tree.d.ts +23 -28
- package/lib/interfaces/avl-tree.d.ts +3 -1
- package/lib/interfaces/bst.d.ts +2 -1
- package/lib/types/data-structures/abstract-binary-tree.js +0 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +151 -203
- package/src/data-structures/binary-tree/avl-tree.ts +29 -0
- package/src/data-structures/binary-tree/bst.ts +12 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +27 -39
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/interfaces/abstract-binary-tree.ts +23 -36
- package/src/interfaces/avl-tree.ts +3 -1
- package/src/interfaces/bst.ts +1 -1
- package/src/types/data-structures/abstract-binary-tree.ts +0 -1
- package/test/integration/avl-tree.test.ts +24 -24
- package/test/integration/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -9
- package/test/unit/data-structures/binary-tree/bst.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +9 -9
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -10,31 +10,22 @@ import { AbstractBinaryTreeOptions, FamilyPosition, LoopType } from '../../types
|
|
|
10
10
|
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from '../../interfaces';
|
|
11
11
|
export declare abstract class AbstractBinaryTreeNode<V = any, NEIGHBOR extends AbstractBinaryTreeNode<V, NEIGHBOR> = AbstractBinaryTreeNodeNested<V>> implements IAbstractBinaryTreeNode<V, NEIGHBOR> {
|
|
12
12
|
/**
|
|
13
|
-
* The constructor function initializes a BinaryTreeNode object with
|
|
13
|
+
* The constructor function initializes a BinaryTreeNode object with a key and an optional value.
|
|
14
14
|
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
|
|
15
15
|
* of the binary tree node. It is used to distinguish one node from another in the binary tree.
|
|
16
16
|
* @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be
|
|
17
17
|
* stored in the binary tree node. If no value is provided, it will be set to undefined.
|
|
18
18
|
*/
|
|
19
19
|
protected constructor(key: BinaryTreeNodeKey, val?: V);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
set key(v: BinaryTreeNodeKey);
|
|
23
|
-
private _val;
|
|
24
|
-
get val(): V | undefined;
|
|
25
|
-
set val(value: V | undefined);
|
|
20
|
+
key: BinaryTreeNodeKey;
|
|
21
|
+
val: V | undefined;
|
|
26
22
|
private _left;
|
|
27
23
|
get left(): NEIGHBOR | null | undefined;
|
|
28
24
|
set left(v: NEIGHBOR | null | undefined);
|
|
29
25
|
private _right;
|
|
30
26
|
get right(): NEIGHBOR | null | undefined;
|
|
31
27
|
set right(v: NEIGHBOR | null | undefined);
|
|
32
|
-
|
|
33
|
-
get parent(): NEIGHBOR | null | undefined;
|
|
34
|
-
set parent(v: NEIGHBOR | null | undefined);
|
|
35
|
-
private _height;
|
|
36
|
-
get height(): number;
|
|
37
|
-
set height(v: number);
|
|
28
|
+
parent: NEIGHBOR | null | undefined;
|
|
38
29
|
/**
|
|
39
30
|
* The function determines the position of a node in a family tree structure.
|
|
40
31
|
* @returns a value of type `FamilyPosition`.
|
|
@@ -54,12 +45,9 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
54
45
|
get size(): number;
|
|
55
46
|
private _loopType;
|
|
56
47
|
get loopType(): LoopType;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
get visitedVal(): N['val'][];
|
|
61
|
-
private _visitedNode;
|
|
62
|
-
get visitedNode(): N[];
|
|
48
|
+
visitedKey: BinaryTreeNodeKey[];
|
|
49
|
+
visitedVal: N['val'][];
|
|
50
|
+
visitedNode: N[];
|
|
63
51
|
abstract createNode(key: BinaryTreeNodeKey, val?: N['val']): N | null;
|
|
64
52
|
/**
|
|
65
53
|
* The `swapLocation` function swaps the location of two nodes in a binary tree.
|
|
@@ -95,24 +83,24 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
95
83
|
/**
|
|
96
84
|
* The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
|
|
97
85
|
* values, and adds them to the binary tree.
|
|
98
|
-
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]}
|
|
86
|
+
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
|
|
99
87
|
* objects, or null values.
|
|
100
88
|
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
|
|
101
89
|
* the nodes or node IDs being added. It is used to set the value of each node being added. If `data` is not provided,
|
|
102
90
|
* the value of the nodes will be `undefined`.
|
|
103
91
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
104
92
|
*/
|
|
105
|
-
addMany(
|
|
93
|
+
addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
|
|
106
94
|
/**
|
|
107
|
-
* The `
|
|
108
|
-
* @param {(BinaryTreeNodeKey | N)[]}
|
|
95
|
+
* The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
|
|
96
|
+
* @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
|
|
109
97
|
* `BinaryTreeNodeKey` or `N` values.
|
|
110
98
|
* @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
|
|
111
|
-
* the nodes being added. If provided, the length of the `data` array should be equal to the length of the `
|
|
99
|
+
* the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
|
|
112
100
|
* array. Each value in the `data` array will be assigned to the
|
|
113
101
|
* @returns The method is returning a boolean value.
|
|
114
102
|
*/
|
|
115
|
-
|
|
103
|
+
refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
|
|
116
104
|
/**
|
|
117
105
|
* The `remove` function in TypeScript is used to delete a node from a binary search tree and returns an array of objects
|
|
118
106
|
* containing the deleted node and the node that needs to be balanced.
|
|
@@ -126,7 +114,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
126
114
|
* @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter can be one of the following:
|
|
127
115
|
* @returns the depth of the given node or binary tree.
|
|
128
116
|
*/
|
|
129
|
-
getDepth(beginRoot
|
|
117
|
+
getDepth(beginRoot?: N | BinaryTreeNodeKey | null): number;
|
|
130
118
|
/**
|
|
131
119
|
* The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
|
|
132
120
|
* @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
|
|
@@ -229,13 +217,13 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
229
217
|
/**
|
|
230
218
|
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
|
|
231
219
|
* recursion optimization.
|
|
232
|
-
* @param {N | null} [
|
|
220
|
+
* @param {N | null} [beginRoot] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
|
|
233
221
|
* starting node from which we want to find the rightmost node. If no node is provided, the function will default to
|
|
234
222
|
* using the root node of the data structure.
|
|
235
223
|
* @returns The `getRightMost` function returns the rightmost node in a binary tree. It returns the rightmost node
|
|
236
224
|
* starting from that node.
|
|
237
225
|
*/
|
|
238
|
-
getRightMost(
|
|
226
|
+
getRightMost(beginRoot: N): N;
|
|
239
227
|
/**
|
|
240
228
|
* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
|
|
241
229
|
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
|
|
@@ -276,80 +264,97 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
276
264
|
*/
|
|
277
265
|
subTreeAdd(subTreeRoot: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
278
266
|
/**
|
|
279
|
-
* Performs a breadth-first search (
|
|
267
|
+
* Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.
|
|
280
268
|
* @returns An array of binary tree node IDs.
|
|
281
269
|
*/
|
|
282
|
-
|
|
270
|
+
bfs(): BinaryTreeNodeKey[];
|
|
283
271
|
/**
|
|
284
|
-
* Performs a breadth-first search (
|
|
272
|
+
* Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on the specified property name.
|
|
285
273
|
* @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
|
|
286
274
|
* @returns An array of values corresponding to the specified property.
|
|
287
275
|
*/
|
|
288
|
-
|
|
276
|
+
bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
289
277
|
/**
|
|
290
|
-
* Performs a breadth-first search (
|
|
278
|
+
* Performs a breadth-first search (bfs) on a binary tree, accumulating the 'val' property of each node.
|
|
291
279
|
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
292
280
|
* @returns An array of 'val' properties from each node.
|
|
293
281
|
*/
|
|
294
|
-
|
|
282
|
+
bfs(nodeOrPropertyName: 'val'): N['val'][];
|
|
295
283
|
/**
|
|
296
|
-
* Performs a breadth-first search (
|
|
284
|
+
* Performs a breadth-first search (bfs) on a binary tree, accumulating nodes themselves.
|
|
297
285
|
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
298
286
|
* @returns An array of binary tree nodes.
|
|
299
287
|
*/
|
|
300
|
-
|
|
288
|
+
bfs(nodeOrPropertyName: 'node'): N[];
|
|
301
289
|
/**
|
|
302
|
-
* Performs a depth-first search (
|
|
290
|
+
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
|
|
303
291
|
* @returns An array of binary tree node IDs.
|
|
304
292
|
*/
|
|
305
|
-
|
|
293
|
+
dfs(): BinaryTreeNodeKey[];
|
|
306
294
|
/**
|
|
307
|
-
* Performs a depth-first search (
|
|
295
|
+
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
|
|
296
|
+
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
297
|
+
* @returns An array of values corresponding to the specified property.
|
|
298
|
+
*/
|
|
299
|
+
dfs(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
|
|
300
|
+
/**
|
|
301
|
+
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
|
|
308
302
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
309
303
|
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
310
304
|
* @returns An array of values corresponding to the specified property.
|
|
311
305
|
*/
|
|
312
|
-
|
|
306
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
313
307
|
/**
|
|
314
|
-
* Performs a depth-first search (
|
|
308
|
+
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
|
|
315
309
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
316
310
|
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
317
311
|
* @returns An array of 'val' properties from each node.
|
|
318
312
|
*/
|
|
319
|
-
|
|
313
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
|
|
320
314
|
/**
|
|
321
|
-
* Performs a depth-first search (
|
|
315
|
+
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
|
|
322
316
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
323
317
|
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
324
318
|
* @returns An array of binary tree nodes.
|
|
325
319
|
*/
|
|
326
|
-
|
|
320
|
+
dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
|
327
321
|
/**
|
|
328
|
-
* Performs an iterative depth-first search (
|
|
322
|
+
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
|
|
329
323
|
* @returns An array of binary tree node IDs.
|
|
330
324
|
*/
|
|
331
|
-
|
|
325
|
+
dfsIterative(): BinaryTreeNodeKey[];
|
|
326
|
+
/**
|
|
327
|
+
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
|
|
328
|
+
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
329
|
+
* @returns An array of values corresponding to the specified property.
|
|
330
|
+
*/
|
|
331
|
+
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
|
|
332
332
|
/**
|
|
333
|
-
* Performs an iterative depth-first search (
|
|
333
|
+
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
|
|
334
334
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
335
335
|
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
336
336
|
* @returns An array of values corresponding to the specified property.
|
|
337
337
|
*/
|
|
338
|
-
|
|
338
|
+
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
339
339
|
/**
|
|
340
|
-
* Performs an iterative depth-first search (
|
|
340
|
+
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
|
|
341
341
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
342
342
|
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
343
343
|
* @returns An array of 'val' properties from each node.
|
|
344
344
|
*/
|
|
345
|
-
|
|
345
|
+
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
|
|
346
346
|
/**
|
|
347
|
-
* Performs an iterative depth-first search (
|
|
347
|
+
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
|
|
348
348
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
349
349
|
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
350
350
|
* @returns An array of binary tree nodes.
|
|
351
351
|
*/
|
|
352
|
-
|
|
352
|
+
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
|
353
|
+
/**
|
|
354
|
+
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
|
|
355
|
+
* @returns An array of binary tree node IDs.
|
|
356
|
+
*/
|
|
357
|
+
levelIterative(): BinaryTreeNodeKey[];
|
|
353
358
|
/**
|
|
354
359
|
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
|
|
355
360
|
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
@@ -362,21 +367,26 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
362
367
|
* @param {string} nodeOrPropertyName - The name of the property to accumulate.
|
|
363
368
|
* @returns An array of values corresponding to the specified property.
|
|
364
369
|
*/
|
|
365
|
-
levelIterative(node: N | null, nodeOrPropertyName
|
|
370
|
+
levelIterative(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
366
371
|
/**
|
|
367
372
|
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates the 'val' property of each node.
|
|
368
373
|
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
369
374
|
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
|
|
370
375
|
* @returns An array of 'val' properties from each node.
|
|
371
376
|
*/
|
|
372
|
-
levelIterative(node: N | null, nodeOrPropertyName
|
|
377
|
+
levelIterative(node: N | null, nodeOrPropertyName: 'val'): N['val'][];
|
|
373
378
|
/**
|
|
374
379
|
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates nodes themselves.
|
|
375
380
|
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
|
|
376
381
|
* @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
|
|
377
382
|
* @returns An array of binary tree nodes.
|
|
378
383
|
*/
|
|
379
|
-
levelIterative(node: N | null, nodeOrPropertyName
|
|
384
|
+
levelIterative(node: N | null, nodeOrPropertyName: 'node'): N[];
|
|
385
|
+
/**
|
|
386
|
+
* Collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
387
|
+
* @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
|
|
388
|
+
*/
|
|
389
|
+
listLevels(): BinaryTreeNodeKey[][];
|
|
380
390
|
/**
|
|
381
391
|
* Collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
382
392
|
* @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
|
|
@@ -389,21 +399,21 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
389
399
|
* @param {'key} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
|
|
390
400
|
* @returns A 2D array of values corresponding to the specified property.
|
|
391
401
|
*/
|
|
392
|
-
listLevels(node: N | null, nodeOrPropertyName
|
|
402
|
+
listLevels(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[][];
|
|
393
403
|
/**
|
|
394
404
|
* Collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
395
405
|
* @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
|
|
396
406
|
* @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
|
|
397
407
|
* @returns A 2D array of 'val' properties from each node.
|
|
398
408
|
*/
|
|
399
|
-
listLevels(node: N | null, nodeOrPropertyName
|
|
409
|
+
listLevels(node: N | null, nodeOrPropertyName: 'val'): N['val'][][];
|
|
400
410
|
/**
|
|
401
411
|
* Collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
402
412
|
* @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
|
|
403
413
|
* @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
|
|
404
414
|
* @returns A 2D array of binary tree nodes.
|
|
405
415
|
*/
|
|
406
|
-
listLevels(node: N | null, nodeOrPropertyName
|
|
416
|
+
listLevels(node: N | null, nodeOrPropertyName: 'node'): N[][];
|
|
407
417
|
/**
|
|
408
418
|
* The function returns the predecessor of a given node in a binary tree.
|
|
409
419
|
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
@@ -412,7 +422,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
412
422
|
getPredecessor(node: N): N;
|
|
413
423
|
/**
|
|
414
424
|
* Time complexity is O(n)
|
|
415
|
-
* Space complexity of Iterative
|
|
425
|
+
* Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
|
|
416
426
|
*/
|
|
417
427
|
/**
|
|
418
428
|
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
|
|
@@ -425,21 +435,27 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
425
435
|
* @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
|
|
426
436
|
* @returns An array of values corresponding to the specified property.
|
|
427
437
|
*/
|
|
428
|
-
morris(pattern
|
|
438
|
+
morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
439
|
+
/**
|
|
440
|
+
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
|
|
441
|
+
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
442
|
+
* @returns An array of values corresponding to the specified property.
|
|
443
|
+
*/
|
|
444
|
+
morris(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
|
|
429
445
|
/**
|
|
430
446
|
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.
|
|
431
447
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
432
448
|
* @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
|
|
433
449
|
* @returns An array of 'val' properties from each node.
|
|
434
450
|
*/
|
|
435
|
-
morris(pattern
|
|
451
|
+
morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
|
|
436
452
|
/**
|
|
437
453
|
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates nodes themselves.
|
|
438
454
|
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
|
|
439
455
|
* @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
|
|
440
456
|
* @returns An array of binary tree nodes.
|
|
441
457
|
*/
|
|
442
|
-
morris(pattern
|
|
458
|
+
morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
|
443
459
|
/**
|
|
444
460
|
* The function adds a new node to a binary tree if there is an available position.
|
|
445
461
|
* @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
|
|
@@ -456,21 +472,6 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
456
472
|
* @param {LoopType} value - The value parameter is of type LoopType.
|
|
457
473
|
*/
|
|
458
474
|
protected _setLoopType(value: LoopType): void;
|
|
459
|
-
/**
|
|
460
|
-
* The function sets the value of the `_visitedKey` property in a protected manner.
|
|
461
|
-
* @param {BinaryTreeNodeKey[]} value - value is an array of BinaryTreeNodeKey values.
|
|
462
|
-
*/
|
|
463
|
-
protected _setVisitedKey(value: BinaryTreeNodeKey[]): void;
|
|
464
|
-
/**
|
|
465
|
-
* The function sets the value of the "_visitedVal" property to the given array.
|
|
466
|
-
* @param value - An array of type N.
|
|
467
|
-
*/
|
|
468
|
-
protected _setVisitedVal(value: Array<N>): void;
|
|
469
|
-
/**
|
|
470
|
-
* The function sets the value of the _visitedNode property.
|
|
471
|
-
* @param {N[]} value - N[] is an array of elements of type N.
|
|
472
|
-
*/
|
|
473
|
-
protected _setVisitedNode(value: N[]): void;
|
|
474
475
|
/**
|
|
475
476
|
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the
|
|
476
477
|
* parent property of the value to undefined.
|
|
@@ -512,7 +513,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
512
513
|
*/
|
|
513
514
|
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
514
515
|
/**
|
|
515
|
-
* The time complexity of Morris traversal is O(n), it
|
|
516
|
+
* The time complexity of Morris traversal is O(n), it may slower than others
|
|
516
517
|
* The space complexity Morris traversal is O(1) because no using stack
|
|
517
518
|
*/
|
|
518
519
|
/**
|