priority-queue-typed 1.47.5 → 1.47.6
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/binary-tree/avl-tree.d.ts +8 -8
- package/dist/data-structures/binary-tree/avl-tree.js +23 -15
- package/dist/data-structures/binary-tree/binary-tree.d.ts +65 -28
- package/dist/data-structures/binary-tree/binary-tree.js +66 -82
- package/dist/data-structures/binary-tree/bst.d.ts +38 -37
- package/dist/data-structures/binary-tree/bst.js +56 -40
- package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -7
- package/dist/data-structures/binary-tree/rb-tree.js +26 -17
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +16 -16
- package/dist/data-structures/binary-tree/tree-multimap.js +31 -22
- package/dist/data-structures/graph/abstract-graph.js +1 -1
- package/dist/data-structures/heap/heap.d.ts +19 -21
- package/dist/data-structures/heap/heap.js +52 -34
- package/dist/data-structures/heap/max-heap.d.ts +2 -5
- package/dist/data-structures/heap/max-heap.js +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -5
- package/dist/data-structures/heap/min-heap.js +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +9 -1
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +8 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
- package/dist/data-structures/priority-queue/max-priority-queue.js +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -5
- package/dist/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/data-structures/queue/deque.d.ts +1 -0
- package/dist/data-structures/queue/deque.js +3 -0
- package/dist/data-structures/queue/queue.d.ts +1 -0
- package/dist/data-structures/queue/queue.js +3 -0
- package/dist/data-structures/stack/stack.d.ts +2 -1
- package/dist/data-structures/stack/stack.js +10 -2
- package/dist/interfaces/binary-tree.d.ts +3 -1
- package/dist/types/common.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/types/data-structures/heap/heap.d.ts +4 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +27 -17
- package/src/data-structures/binary-tree/binary-tree.ts +114 -97
- package/src/data-structures/binary-tree/bst.ts +67 -47
- package/src/data-structures/binary-tree/rb-tree.ts +34 -20
- package/src/data-structures/binary-tree/tree-multimap.ts +43 -25
- package/src/data-structures/graph/abstract-graph.ts +1 -1
- package/src/data-structures/heap/heap.ts +57 -39
- package/src/data-structures/heap/max-heap.ts +5 -5
- package/src/data-structures/heap/min-heap.ts +5 -5
- package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +4 -0
- package/src/data-structures/queue/queue.ts +4 -0
- package/src/data-structures/stack/stack.ts +12 -3
- package/src/interfaces/binary-tree.ts +13 -1
- package/src/types/common.ts +5 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -3
- package/src/types/data-structures/heap/heap.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
|
@@ -7,21 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
9
|
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BTNKey } from '../../types';
|
|
10
|
-
import { BTNCallback } from '../../types';
|
|
10
|
+
import { BTNCallback, IterableEntriesOrKeys } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
13
|
height: number;
|
|
14
14
|
constructor(key: BTNKey, value?: V);
|
|
15
15
|
}
|
|
16
16
|
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>, TREE extends AVLTree<V, N, TREE> = AVLTree<V, N, AVLTreeNested<V, N>>> extends BST<V, N, TREE> implements IBinaryTree<V, N, TREE> {
|
|
17
|
-
options: AVLTreeOptions;
|
|
18
17
|
/**
|
|
19
18
|
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
20
19
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
21
20
|
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
22
21
|
* options.
|
|
23
22
|
*/
|
|
24
|
-
constructor(options?: AVLTreeOptions);
|
|
23
|
+
constructor(elements?: IterableEntriesOrKeys<V>, options?: Partial<AVLTreeOptions>);
|
|
25
24
|
/**
|
|
26
25
|
* The function creates a new AVL tree node with the specified key and value.
|
|
27
26
|
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
@@ -33,10 +32,6 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
33
32
|
*/
|
|
34
33
|
createNode(key: BTNKey, value?: V): N;
|
|
35
34
|
createTree(options?: AVLTreeOptions): TREE;
|
|
36
|
-
/**
|
|
37
|
-
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
38
|
-
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
39
|
-
*/
|
|
40
35
|
/**
|
|
41
36
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
42
37
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -51,7 +46,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
51
46
|
*/
|
|
52
47
|
add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined;
|
|
53
48
|
/**
|
|
54
|
-
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The
|
|
49
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
55
50
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
56
51
|
*/
|
|
57
52
|
/**
|
|
@@ -70,6 +65,11 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
70
65
|
* @returns The method is returning an array of `BiTreeDeleteResult<N>`.
|
|
71
66
|
*/
|
|
72
67
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
|
|
68
|
+
/**
|
|
69
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
70
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
71
|
+
*/
|
|
72
|
+
init(elements: IterableEntriesOrKeys<V>): void;
|
|
73
73
|
/**
|
|
74
74
|
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
75
75
|
* tree.
|
|
@@ -9,7 +9,6 @@ exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
|
9
9
|
* @license MIT License
|
|
10
10
|
*/
|
|
11
11
|
const bst_1 = require("./bst");
|
|
12
|
-
const types_1 = require("../../types");
|
|
13
12
|
class AVLTreeNode extends bst_1.BSTNode {
|
|
14
13
|
constructor(key, value) {
|
|
15
14
|
super(key, value);
|
|
@@ -24,14 +23,10 @@ class AVLTree extends bst_1.BST {
|
|
|
24
23
|
* constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
|
|
25
24
|
* options.
|
|
26
25
|
*/
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super(options);
|
|
29
|
-
if (
|
|
30
|
-
this.
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
this.options = { iterationType: types_1.IterationType.ITERATIVE, comparator: (a, b) => a - b };
|
|
34
|
-
}
|
|
26
|
+
constructor(elements, options) {
|
|
27
|
+
super([], options);
|
|
28
|
+
if (elements)
|
|
29
|
+
this.init(elements);
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
32
|
* The function creates a new AVL tree node with the specified key and value.
|
|
@@ -46,12 +41,8 @@ class AVLTree extends bst_1.BST {
|
|
|
46
41
|
return new AVLTreeNode(key, value);
|
|
47
42
|
}
|
|
48
43
|
createTree(options) {
|
|
49
|
-
return new AVLTree(Object.assign(
|
|
44
|
+
return new AVLTree([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
|
|
50
45
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
53
|
-
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
54
|
-
*/
|
|
55
46
|
/**
|
|
56
47
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
57
48
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -73,7 +64,7 @@ class AVLTree extends bst_1.BST {
|
|
|
73
64
|
return inserted;
|
|
74
65
|
}
|
|
75
66
|
/**
|
|
76
|
-
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The
|
|
67
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
77
68
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
78
69
|
*/
|
|
79
70
|
/**
|
|
@@ -102,6 +93,23 @@ class AVLTree extends bst_1.BST {
|
|
|
102
93
|
}
|
|
103
94
|
return deletedResults;
|
|
104
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
98
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
99
|
+
*/
|
|
100
|
+
init(elements) {
|
|
101
|
+
if (elements) {
|
|
102
|
+
for (const entryOrKey of elements) {
|
|
103
|
+
if (Array.isArray(entryOrKey)) {
|
|
104
|
+
const [key, value] = entryOrKey;
|
|
105
|
+
this.add(key, value);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.add(entryOrKey);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
105
113
|
/**
|
|
106
114
|
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
107
115
|
* tree.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } from '../../types';
|
|
9
|
-
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
|
|
9
|
+
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterableEntriesOrKeys, IterationType, NodeDisplayLayout } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a node in a binary tree.
|
|
@@ -63,12 +63,12 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
63
63
|
* @template N - The type of the binary tree's nodes.
|
|
64
64
|
*/
|
|
65
65
|
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>, TREE extends BinaryTree<V, N, TREE> = BinaryTree<V, N, BinaryTreeNested<V, N>>> implements IBinaryTree<V, N, TREE> {
|
|
66
|
-
|
|
66
|
+
iterationType: IterationType;
|
|
67
67
|
/**
|
|
68
68
|
* Creates a new instance of BinaryTree.
|
|
69
69
|
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
|
70
70
|
*/
|
|
71
|
-
constructor(options?: BinaryTreeOptions);
|
|
71
|
+
constructor(elements?: IterableEntriesOrKeys<V>, options?: Partial<BinaryTreeOptions>);
|
|
72
72
|
protected _root?: N | null;
|
|
73
73
|
/**
|
|
74
74
|
* Get the root node of the binary tree.
|
|
@@ -86,12 +86,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
86
86
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
87
87
|
*/
|
|
88
88
|
createNode(key: BTNKey, value?: V): N;
|
|
89
|
-
createTree(options?: BinaryTreeOptions): TREE;
|
|
90
|
-
/**
|
|
91
|
-
* Time Complexity: O(n)
|
|
92
|
-
* Space Complexity: O(1)
|
|
93
|
-
* 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.
|
|
94
|
-
*/
|
|
89
|
+
createTree(options?: Partial<BinaryTreeOptions>): TREE;
|
|
95
90
|
/**
|
|
96
91
|
* Time Complexity: O(n)
|
|
97
92
|
* Space Complexity: O(1)
|
|
@@ -107,8 +102,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
107
102
|
*/
|
|
108
103
|
add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | null | undefined;
|
|
109
104
|
/**
|
|
110
|
-
* Time Complexity: O(
|
|
105
|
+
* Time Complexity: O(n)
|
|
111
106
|
* Space Complexity: O(1)
|
|
107
|
+
* 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.
|
|
112
108
|
*/
|
|
113
109
|
/**
|
|
114
110
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
@@ -142,6 +138,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
142
138
|
* @returns The method is returning a boolean value.
|
|
143
139
|
*/
|
|
144
140
|
refill(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
143
|
+
* Space Complexity: O(1)
|
|
144
|
+
*/
|
|
145
145
|
delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C): BiTreeDeleteResult<N>[];
|
|
146
146
|
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
|
|
147
147
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
|
|
@@ -165,8 +165,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
165
165
|
getDepth(distNode: BTNKey | N | null | undefined, beginRoot?: BTNKey | N | null | undefined): number;
|
|
166
166
|
/**
|
|
167
167
|
* Time Complexity: O(n)
|
|
168
|
-
* Space Complexity: O(
|
|
169
|
-
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
168
|
+
* Space Complexity: O(1)
|
|
170
169
|
*/
|
|
171
170
|
/**
|
|
172
171
|
* Time Complexity: O(n)
|
|
@@ -182,7 +181,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
182
181
|
* values:
|
|
183
182
|
* @returns the height of the binary tree.
|
|
184
183
|
*/
|
|
185
|
-
getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType
|
|
184
|
+
getHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
186
185
|
/**
|
|
187
186
|
* Time Complexity: O(n)
|
|
188
187
|
* Space Complexity: O(log n)
|
|
@@ -201,10 +200,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
201
200
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
202
201
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
203
202
|
*/
|
|
204
|
-
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType
|
|
203
|
+
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
205
204
|
/**
|
|
206
205
|
* Time Complexity: O(n)
|
|
207
206
|
* Space Complexity: O(log n)
|
|
207
|
+
* Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType)
|
|
208
208
|
*/
|
|
209
209
|
/**
|
|
210
210
|
* Time Complexity: O(n)
|
|
@@ -218,12 +218,24 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
218
218
|
* @returns a boolean value.
|
|
219
219
|
*/
|
|
220
220
|
isPerfectlyBalanced(beginRoot?: BTNKey | N | null | undefined): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Time Complexity: O(n)
|
|
223
|
+
* Space Complexity: O(log n)
|
|
224
|
+
*/
|
|
221
225
|
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
222
226
|
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
223
227
|
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
228
|
+
/**
|
|
229
|
+
* Time Complexity: O(n)
|
|
230
|
+
* Space Complexity: O(log n).
|
|
231
|
+
*/
|
|
224
232
|
has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
225
233
|
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
226
234
|
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Time Complexity: O(n)
|
|
237
|
+
* Space Complexity: O(log n).
|
|
238
|
+
*/
|
|
227
239
|
getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
228
240
|
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
229
241
|
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
@@ -246,6 +258,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
246
258
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
247
259
|
*/
|
|
248
260
|
getNodeByKey(key: BTNKey, iterationType?: IterationType): N | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Time Complexity: O(n)
|
|
263
|
+
* Space Complexity: O(log n)
|
|
264
|
+
*/
|
|
249
265
|
/**
|
|
250
266
|
* The function `ensureNotKey` returns the node corresponding to the given key if it is a valid node
|
|
251
267
|
* key, otherwise it returns the key itself.
|
|
@@ -261,6 +277,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
261
277
|
get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
262
278
|
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
263
279
|
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Time Complexity: O(n)
|
|
282
|
+
* Space Complexity: O(log n)
|
|
283
|
+
*/
|
|
264
284
|
/**
|
|
265
285
|
* Clear the binary tree, removing all nodes.
|
|
266
286
|
*/
|
|
@@ -270,10 +290,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
270
290
|
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
271
291
|
*/
|
|
272
292
|
isEmpty(): boolean;
|
|
273
|
-
/**
|
|
274
|
-
* Time Complexity: O(log n)
|
|
275
|
-
* Space Complexity: O(log n)
|
|
276
|
-
*/
|
|
277
293
|
/**
|
|
278
294
|
* Time Complexity: O(log n)
|
|
279
295
|
* Space Complexity: O(log n)
|
|
@@ -291,7 +307,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
291
307
|
getPathToRoot(beginRoot: BTNKey | N | null | undefined, isReverse?: boolean): N[];
|
|
292
308
|
/**
|
|
293
309
|
* Time Complexity: O(log n)
|
|
294
|
-
* Space Complexity: O(
|
|
310
|
+
* Space Complexity: O(log n)
|
|
295
311
|
*/
|
|
296
312
|
/**
|
|
297
313
|
* Time Complexity: O(log n)
|
|
@@ -307,7 +323,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
307
323
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
308
324
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
309
325
|
*/
|
|
310
|
-
getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType
|
|
326
|
+
getLeftMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
311
327
|
/**
|
|
312
328
|
* Time Complexity: O(log n)
|
|
313
329
|
* Space Complexity: O(1)
|
|
@@ -327,9 +343,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
327
343
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
328
344
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
329
345
|
*/
|
|
330
|
-
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType
|
|
346
|
+
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
331
347
|
/**
|
|
332
|
-
* Time Complexity: O(n)
|
|
348
|
+
* Time Complexity: O(log n)
|
|
333
349
|
* Space Complexity: O(1)
|
|
334
350
|
*/
|
|
335
351
|
/**
|
|
@@ -344,7 +360,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
344
360
|
* possible values:
|
|
345
361
|
* @returns a boolean value.
|
|
346
362
|
*/
|
|
347
|
-
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType
|
|
363
|
+
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
348
364
|
/**
|
|
349
365
|
* Time Complexity: O(n)
|
|
350
366
|
* Space Complexity: O(1)
|
|
@@ -360,10 +376,18 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
360
376
|
* expected to be
|
|
361
377
|
* @returns a boolean value.
|
|
362
378
|
*/
|
|
363
|
-
isBST(iterationType?: IterationType
|
|
379
|
+
isBST(iterationType?: IterationType): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Time Complexity: O(n)
|
|
382
|
+
* Space Complexity: O(1)
|
|
383
|
+
*/
|
|
364
384
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
365
385
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
366
386
|
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
387
|
+
/**
|
|
388
|
+
* Time complexity: O(n)
|
|
389
|
+
* Space complexity: O(log n)
|
|
390
|
+
*/
|
|
367
391
|
/**
|
|
368
392
|
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
369
393
|
* BinaryTreeNode and its key is not NaN.
|
|
@@ -393,12 +417,24 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
393
417
|
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
394
418
|
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
395
419
|
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
420
|
+
/**
|
|
421
|
+
* Time complexity: O(n)
|
|
422
|
+
* Space complexity: O(n)
|
|
423
|
+
*/
|
|
396
424
|
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
397
425
|
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
398
426
|
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
427
|
+
/**
|
|
428
|
+
* Time complexity: O(n)
|
|
429
|
+
* Space complexity: O(n)
|
|
430
|
+
*/
|
|
399
431
|
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
400
432
|
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
401
433
|
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
434
|
+
/**
|
|
435
|
+
* Time complexity: O(n)
|
|
436
|
+
* Space complexity: O(n)
|
|
437
|
+
*/
|
|
402
438
|
getPredecessor(node: N): N;
|
|
403
439
|
/**
|
|
404
440
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
@@ -407,10 +443,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
407
443
|
* after the given node in the inorder traversal of the binary tree.
|
|
408
444
|
*/
|
|
409
445
|
getSuccessor(x?: BTNKey | N | null): N | null | undefined;
|
|
410
|
-
/**
|
|
411
|
-
* Time complexity: O(n)
|
|
412
|
-
* Space complexity: O(1)
|
|
413
|
-
*/
|
|
414
446
|
/**
|
|
415
447
|
* Time complexity: O(n)
|
|
416
448
|
* Space complexity: O(1)
|
|
@@ -430,6 +462,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
430
462
|
* by the return type of the `callback` function.
|
|
431
463
|
*/
|
|
432
464
|
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
|
|
465
|
+
/**
|
|
466
|
+
* Time complexity: O(n)
|
|
467
|
+
* Space complexity: O(1)
|
|
468
|
+
*/
|
|
433
469
|
/**
|
|
434
470
|
* The `forEach` function iterates over each entry in a tree and calls a callback function with the
|
|
435
471
|
* entry and the tree as arguments.
|
|
@@ -484,6 +520,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
484
520
|
* @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.
|
|
485
521
|
*/
|
|
486
522
|
print(beginRoot?: BTNKey | N | null | undefined, options?: BinaryTreePrintOptions): void;
|
|
523
|
+
init(elements: IterableEntriesOrKeys<V>): void;
|
|
487
524
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
488
525
|
protected _defaultOneParamCallback: (node: N) => number;
|
|
489
526
|
/**
|