min-heap-typed 1.50.2 → 1.50.4
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 +6 -0
- package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +51 -20
- package/dist/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/data-structures/binary-tree/index.js +2 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/index.js +2 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -32,10 +32,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
32
32
|
get elements() {
|
|
33
33
|
return this._elements;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Time Complexity: O(n), where n is the number of elements in the input array. Similar to the constructor, it requires iterating through each element.
|
|
37
|
-
* Space Complexity: O(n), as it creates a new stack with the elements from the input array.
|
|
38
|
-
*/
|
|
39
35
|
/**
|
|
40
36
|
* The size() function returns the number of elements in an array.
|
|
41
37
|
* @returns The size of the elements array.
|
|
@@ -44,8 +40,12 @@ class Stack extends base_1.IterableElementBase {
|
|
|
44
40
|
return this.elements.length;
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
|
-
* Time Complexity: O(n)
|
|
48
|
-
* Space Complexity: O(n)
|
|
43
|
+
* Time Complexity: O(n)
|
|
44
|
+
* Space Complexity: O(n)
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Time Complexity: O(n)
|
|
48
|
+
* Space Complexity: O(n)
|
|
49
49
|
*
|
|
50
50
|
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
51
51
|
* @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
|
|
@@ -63,12 +63,12 @@ class Stack extends base_1.IterableElementBase {
|
|
|
63
63
|
return this.elements.length === 0;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Time Complexity: O(1)
|
|
67
|
-
* Space Complexity: O(1)
|
|
66
|
+
* Time Complexity: O(1)
|
|
67
|
+
* Space Complexity: O(1)
|
|
68
68
|
*/
|
|
69
69
|
/**
|
|
70
|
-
* Time Complexity: O(1)
|
|
71
|
-
* Space Complexity: O(1)
|
|
70
|
+
* Time Complexity: O(1)
|
|
71
|
+
* Space Complexity: O(1)
|
|
72
72
|
*
|
|
73
73
|
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
74
74
|
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
@@ -79,12 +79,12 @@ class Stack extends base_1.IterableElementBase {
|
|
|
79
79
|
return this.elements[this.elements.length - 1];
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Time Complexity: O(1)
|
|
83
|
-
* Space Complexity: O(1)
|
|
82
|
+
* Time Complexity: O(1)
|
|
83
|
+
* Space Complexity: O(1)
|
|
84
84
|
*/
|
|
85
85
|
/**
|
|
86
|
-
* Time Complexity: O(1)
|
|
87
|
-
* Space Complexity: O(1)
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
88
88
|
*
|
|
89
89
|
* The push function adds an element to the stack and returns the updated stack.
|
|
90
90
|
* @param {E} element - The parameter "element" is of type E, which means it can be any data type.
|
|
@@ -95,12 +95,12 @@ class Stack extends base_1.IterableElementBase {
|
|
|
95
95
|
return true;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
* Time Complexity: O(1)
|
|
99
|
-
* Space Complexity: O(1)
|
|
98
|
+
* Time Complexity: O(1)
|
|
99
|
+
* Space Complexity: O(1)
|
|
100
100
|
*/
|
|
101
101
|
/**
|
|
102
|
-
* Time Complexity: O(1)
|
|
103
|
-
* Space Complexity: O(1)
|
|
102
|
+
* Time Complexity: O(1)
|
|
103
|
+
* Space Complexity: O(1)
|
|
104
104
|
*
|
|
105
105
|
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
106
106
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
@@ -144,18 +144,25 @@ class Stack extends base_1.IterableElementBase {
|
|
|
144
144
|
return this.elements.slice();
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
+
* Time Complexity: O(1)
|
|
148
|
+
* Space Complexity: O(1)
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Time Complexity: O(1)
|
|
152
|
+
* Space Complexity: O(1)
|
|
153
|
+
*
|
|
147
154
|
* The clear function clears the elements array.
|
|
148
155
|
*/
|
|
149
156
|
clear() {
|
|
150
157
|
this._elements = [];
|
|
151
158
|
}
|
|
152
159
|
/**
|
|
153
|
-
* Time Complexity: O(n)
|
|
154
|
-
* Space Complexity: O(n)
|
|
160
|
+
* Time Complexity: O(n)
|
|
161
|
+
* Space Complexity: O(n)
|
|
155
162
|
*/
|
|
156
163
|
/**
|
|
157
|
-
* Time Complexity: O(n)
|
|
158
|
-
* Space Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n)
|
|
165
|
+
* Space Complexity: O(n)
|
|
159
166
|
*
|
|
160
167
|
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
161
168
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
@@ -221,6 +228,13 @@ class Stack extends base_1.IterableElementBase {
|
|
|
221
228
|
return newStack;
|
|
222
229
|
}
|
|
223
230
|
/**
|
|
231
|
+
* Time Complexity: O(n)
|
|
232
|
+
* Space Complexity: O(n)
|
|
233
|
+
*/
|
|
234
|
+
/**
|
|
235
|
+
* Time Complexity: O(n)
|
|
236
|
+
* Space Complexity: O(n)
|
|
237
|
+
*
|
|
224
238
|
* Custom iterator for the Stack class.
|
|
225
239
|
* @returns An iterator object.
|
|
226
240
|
*/
|
|
@@ -1,8 +1,62 @@
|
|
|
1
1
|
export declare class TreeNode<V = any> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
4
|
+
* children.
|
|
5
|
+
* @param {string} key - A string representing the key of the tree node.
|
|
6
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
7
|
+
* value associated with the node. If no value is provided, it defaults to `undefined`.
|
|
8
|
+
* @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
|
|
9
|
+
* objects. It represents the child nodes of the current node. If no children are provided, the
|
|
10
|
+
* default value is an empty array.
|
|
11
|
+
*/
|
|
5
12
|
constructor(key: string, value?: V, children?: TreeNode<V>[]);
|
|
13
|
+
protected _key: string;
|
|
14
|
+
/**
|
|
15
|
+
* The function returns the value of the protected variable _key.
|
|
16
|
+
* @returns The value of the `_key` property, which is a string.
|
|
17
|
+
*/
|
|
18
|
+
get key(): string;
|
|
19
|
+
/**
|
|
20
|
+
* The above function sets the value of a protected variable called "key".
|
|
21
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
22
|
+
* to the key.
|
|
23
|
+
*/
|
|
24
|
+
set key(value: string);
|
|
25
|
+
protected _value?: V | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
28
|
+
* @returns The value of the variable `_value` is being returned.
|
|
29
|
+
*/
|
|
30
|
+
get value(): V | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The function sets the value of a variable.
|
|
33
|
+
* @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
|
|
34
|
+
* can accept a value of type "V" or it can be undefined.
|
|
35
|
+
*/
|
|
36
|
+
set value(value: V | undefined);
|
|
37
|
+
protected _children?: TreeNode<V>[] | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The function returns an array of TreeNode objects or undefined.
|
|
40
|
+
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
41
|
+
* which means it can either be an array of `TreeNode<V>` objects or `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
get children(): TreeNode<V>[] | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The function sets the value of the children property of a TreeNode object.
|
|
46
|
+
* @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
|
|
47
|
+
* undefined. This means that it can accept an array of TreeNode objects or undefined.
|
|
48
|
+
*/
|
|
49
|
+
set children(value: TreeNode<V>[] | undefined);
|
|
50
|
+
/**
|
|
51
|
+
* The function `addChildren` adds one or more child nodes to the current node.
|
|
52
|
+
* @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
|
|
53
|
+
* `TreeNode<V>` object or an array of `TreeNode<V>` objects.
|
|
54
|
+
*/
|
|
6
55
|
addChildren(children: TreeNode<V> | TreeNode<V>[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* The function `getHeight()` calculates the maximum depth of a tree structure by performing a
|
|
58
|
+
* breadth-first search.
|
|
59
|
+
* @returns the maximum depth or height of the tree.
|
|
60
|
+
*/
|
|
7
61
|
getHeight(): number;
|
|
8
62
|
}
|
|
@@ -2,22 +2,88 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeNode = void 0;
|
|
4
4
|
class TreeNode {
|
|
5
|
+
/**
|
|
6
|
+
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
7
|
+
* children.
|
|
8
|
+
* @param {string} key - A string representing the key of the tree node.
|
|
9
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
10
|
+
* value associated with the node. If no value is provided, it defaults to `undefined`.
|
|
11
|
+
* @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
|
|
12
|
+
* objects. It represents the child nodes of the current node. If no children are provided, the
|
|
13
|
+
* default value is an empty array.
|
|
14
|
+
*/
|
|
5
15
|
constructor(key, value, children) {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
16
|
+
this._key = key;
|
|
17
|
+
this._value = value || undefined;
|
|
18
|
+
this._children = children || [];
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The function returns the value of the protected variable _key.
|
|
22
|
+
* @returns The value of the `_key` property, which is a string.
|
|
23
|
+
*/
|
|
24
|
+
get key() {
|
|
25
|
+
return this._key;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The above function sets the value of a protected variable called "key".
|
|
29
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
30
|
+
* to the key.
|
|
31
|
+
*/
|
|
32
|
+
set key(value) {
|
|
33
|
+
this._key = value;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
37
|
+
* @returns The value of the variable `_value` is being returned.
|
|
38
|
+
*/
|
|
39
|
+
get value() {
|
|
40
|
+
return this._value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The function sets the value of a variable.
|
|
44
|
+
* @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
|
|
45
|
+
* can accept a value of type "V" or it can be undefined.
|
|
46
|
+
*/
|
|
47
|
+
set value(value) {
|
|
48
|
+
this._value = value;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The function returns an array of TreeNode objects or undefined.
|
|
52
|
+
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
53
|
+
* which means it can either be an array of `TreeNode<V>` objects or `undefined`.
|
|
54
|
+
*/
|
|
55
|
+
get children() {
|
|
56
|
+
return this._children;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The function sets the value of the children property of a TreeNode object.
|
|
60
|
+
* @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
|
|
61
|
+
* undefined. This means that it can accept an array of TreeNode objects or undefined.
|
|
62
|
+
*/
|
|
63
|
+
set children(value) {
|
|
64
|
+
this._children = value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The function `addChildren` adds one or more child nodes to the current node.
|
|
68
|
+
* @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
|
|
69
|
+
* `TreeNode<V>` object or an array of `TreeNode<V>` objects.
|
|
70
|
+
*/
|
|
10
71
|
addChildren(children) {
|
|
11
|
-
if (!this.
|
|
12
|
-
this.
|
|
72
|
+
if (!this._children) {
|
|
73
|
+
this._children = [];
|
|
13
74
|
}
|
|
14
75
|
if (children instanceof TreeNode) {
|
|
15
|
-
this.
|
|
76
|
+
this._children.push(children);
|
|
16
77
|
}
|
|
17
78
|
else {
|
|
18
|
-
this.
|
|
79
|
+
this._children = this._children.concat(children);
|
|
19
80
|
}
|
|
20
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The function `getHeight()` calculates the maximum depth of a tree structure by performing a
|
|
84
|
+
* breadth-first search.
|
|
85
|
+
* @returns the maximum depth or height of the tree.
|
|
86
|
+
*/
|
|
21
87
|
getHeight() {
|
|
22
88
|
let maxDepth = 0;
|
|
23
89
|
if (this) {
|
|
@@ -25,10 +91,10 @@ class TreeNode {
|
|
|
25
91
|
if (level > maxDepth) {
|
|
26
92
|
maxDepth = level;
|
|
27
93
|
}
|
|
28
|
-
const {
|
|
29
|
-
if (
|
|
30
|
-
for (let i = 0, len =
|
|
31
|
-
bfs(
|
|
94
|
+
const { _children } = node;
|
|
95
|
+
if (_children) {
|
|
96
|
+
for (let i = 0, len = _children.length; i < len; i++) {
|
|
97
|
+
bfs(_children[i], level + 1);
|
|
32
98
|
}
|
|
33
99
|
}
|
|
34
100
|
};
|
|
@@ -12,10 +12,46 @@ import { IterableElementBase } from '../base';
|
|
|
12
12
|
* and a flag indicating whether it's the end of a word.
|
|
13
13
|
*/
|
|
14
14
|
export declare class TrieNode {
|
|
15
|
-
key: string;
|
|
16
|
-
children: Map<string, TrieNode>;
|
|
17
|
-
isEnd: boolean;
|
|
18
15
|
constructor(key: string);
|
|
16
|
+
protected _key: string;
|
|
17
|
+
/**
|
|
18
|
+
* The function returns the value of the protected variable _key.
|
|
19
|
+
* @returns The value of the `_key` property, which is a string.
|
|
20
|
+
*/
|
|
21
|
+
get key(): string;
|
|
22
|
+
/**
|
|
23
|
+
* The above function sets the value of a protected variable called "key".
|
|
24
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
25
|
+
* to the key.
|
|
26
|
+
*/
|
|
27
|
+
set key(value: string);
|
|
28
|
+
protected _children: Map<string, TrieNode>;
|
|
29
|
+
/**
|
|
30
|
+
* The function returns the children of a TrieNode as a Map.
|
|
31
|
+
* @returns The `children` property of the TrieNode object, which is a Map containing string keys and
|
|
32
|
+
* TrieNode values.
|
|
33
|
+
*/
|
|
34
|
+
get children(): Map<string, TrieNode>;
|
|
35
|
+
/**
|
|
36
|
+
* The function sets the value of the `_children` property of a TrieNode object.
|
|
37
|
+
* @param value - The value parameter is a Map object that represents the children of a TrieNode. The
|
|
38
|
+
* keys of the map are strings, which represent the characters that are associated with each child
|
|
39
|
+
* TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
|
|
40
|
+
* current TrieNode.
|
|
41
|
+
*/
|
|
42
|
+
set children(value: Map<string, TrieNode>);
|
|
43
|
+
protected _isEnd: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The function returns a boolean value indicating whether a certain condition is met.
|
|
46
|
+
* @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
|
|
47
|
+
*/
|
|
48
|
+
get isEnd(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The function sets the value of the "_isEnd" property.
|
|
51
|
+
* @param {boolean} value - The value parameter is a boolean value that indicates whether the current
|
|
52
|
+
* state is the end state or not.
|
|
53
|
+
*/
|
|
54
|
+
set isEnd(value: boolean);
|
|
19
55
|
}
|
|
20
56
|
/**
|
|
21
57
|
* 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
|
|
@@ -46,9 +82,8 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
46
82
|
get size(): number;
|
|
47
83
|
protected _caseSensitive: boolean;
|
|
48
84
|
/**
|
|
49
|
-
* The caseSensitive function is a getter that returns the value of the
|
|
50
|
-
*
|
|
51
|
-
* @return The value of the _casesensitive private variable
|
|
85
|
+
* The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
|
|
86
|
+
* @return The value of the _caseSensitive protected variable
|
|
52
87
|
*/
|
|
53
88
|
get caseSensitive(): boolean;
|
|
54
89
|
protected _root: TrieNode;
|
|
@@ -58,12 +93,12 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
58
93
|
*/
|
|
59
94
|
get root(): TrieNode;
|
|
60
95
|
/**
|
|
61
|
-
* Time Complexity: O(
|
|
62
|
-
* Space Complexity: O(
|
|
96
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
97
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
63
98
|
*/
|
|
64
99
|
/**
|
|
65
|
-
* Time Complexity: O(
|
|
66
|
-
* Space Complexity: O(
|
|
100
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
101
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
67
102
|
*
|
|
68
103
|
* Add a word to the Trie structure.
|
|
69
104
|
* @param {string} word - The word to add.
|
|
@@ -71,11 +106,11 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
71
106
|
*/
|
|
72
107
|
add(word: string): boolean;
|
|
73
108
|
/**
|
|
74
|
-
* Time Complexity: O(
|
|
109
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
75
110
|
* Space Complexity: O(1) - Constant space.
|
|
76
111
|
*/
|
|
77
112
|
/**
|
|
78
|
-
* Time Complexity: O(
|
|
113
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
79
114
|
* Space Complexity: O(1) - Constant space.
|
|
80
115
|
*
|
|
81
116
|
* Check if the Trie contains a given word.
|
|
@@ -84,17 +119,35 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
84
119
|
*/
|
|
85
120
|
has(word: string): boolean;
|
|
86
121
|
/**
|
|
122
|
+
* Time Complexity: O(1)
|
|
123
|
+
* Space Complexity: O(1)
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Time Complexity: O(1)
|
|
127
|
+
* Space Complexity: O(1)
|
|
128
|
+
*
|
|
87
129
|
* The isEmpty function checks if the size of the queue is 0.
|
|
88
130
|
* @return True if the size of the queue is 0
|
|
89
131
|
*/
|
|
90
132
|
isEmpty(): boolean;
|
|
91
133
|
/**
|
|
92
|
-
* Time Complexity: O(
|
|
93
|
-
* Space Complexity: O(
|
|
134
|
+
* Time Complexity: O(1)
|
|
135
|
+
* Space Complexity: O(1)
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Time Complexity: O(1)
|
|
139
|
+
* Space Complexity: O(1)
|
|
140
|
+
*
|
|
141
|
+
* The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
|
|
142
|
+
*/
|
|
143
|
+
clear(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
146
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
94
147
|
*/
|
|
95
148
|
/**
|
|
96
|
-
* Time Complexity: O(
|
|
97
|
-
* Space Complexity: O(
|
|
149
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
150
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
98
151
|
*
|
|
99
152
|
* Remove a word from the Trie structure.
|
|
100
153
|
* @param{string} word - The word to delete.
|
|
@@ -102,21 +155,21 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
102
155
|
*/
|
|
103
156
|
delete(word: string): boolean;
|
|
104
157
|
/**
|
|
105
|
-
* Time Complexity: O(
|
|
158
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
106
159
|
* Space Complexity: O(1) - Constant space.
|
|
107
160
|
*/
|
|
108
161
|
/**
|
|
109
|
-
* Time Complexity: O(
|
|
162
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
110
163
|
* Space Complexity: O(1) - Constant space.
|
|
111
164
|
*
|
|
112
165
|
*/
|
|
113
166
|
getHeight(): number;
|
|
114
167
|
/**
|
|
115
|
-
* Time Complexity: O(
|
|
168
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
116
169
|
* Space Complexity: O(1) - Constant space.
|
|
117
170
|
*/
|
|
118
171
|
/**
|
|
119
|
-
* Time Complexity: O(
|
|
172
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
120
173
|
* Space Complexity: O(1) - Constant space.
|
|
121
174
|
*
|
|
122
175
|
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
@@ -125,11 +178,11 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
125
178
|
*/
|
|
126
179
|
hasPurePrefix(input: string): boolean;
|
|
127
180
|
/**
|
|
128
|
-
* Time Complexity: O(
|
|
181
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
129
182
|
* Space Complexity: O(1) - Constant space.
|
|
130
183
|
*/
|
|
131
184
|
/**
|
|
132
|
-
* Time Complexity: O(
|
|
185
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
133
186
|
* Space Complexity: O(1) - Constant space.
|
|
134
187
|
*
|
|
135
188
|
* Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
|
|
@@ -138,12 +191,12 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
138
191
|
*/
|
|
139
192
|
hasPrefix(input: string): boolean;
|
|
140
193
|
/**
|
|
141
|
-
* Time Complexity: O(
|
|
142
|
-
* Space Complexity: O(
|
|
194
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
195
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
143
196
|
*/
|
|
144
197
|
/**
|
|
145
|
-
* Time Complexity: O(
|
|
146
|
-
* Space Complexity: O(
|
|
198
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
199
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
147
200
|
*
|
|
148
201
|
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
149
202
|
* @param {string} input - The input string representing the common prefix to check for.
|
|
@@ -151,24 +204,24 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
151
204
|
*/
|
|
152
205
|
hasCommonPrefix(input: string): boolean;
|
|
153
206
|
/**
|
|
154
|
-
* Time Complexity: O(
|
|
155
|
-
* Space Complexity: O(
|
|
207
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
208
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
156
209
|
*/
|
|
157
210
|
/**
|
|
158
|
-
* Time Complexity: O(
|
|
159
|
-
* Space Complexity: O(
|
|
211
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
212
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
160
213
|
*
|
|
161
214
|
* Get the longest common prefix among all the words stored in the Trie.
|
|
162
215
|
* @returns {string} The longest common prefix found in the Trie.
|
|
163
216
|
*/
|
|
164
217
|
getLongestCommonPrefix(): string;
|
|
165
218
|
/**
|
|
166
|
-
* Time Complexity: O(
|
|
167
|
-
* Space Complexity: O(
|
|
219
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
220
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
168
221
|
*/
|
|
169
222
|
/**
|
|
170
|
-
* Time Complexity: O(
|
|
171
|
-
* Space Complexity: O(
|
|
223
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
224
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
172
225
|
*
|
|
173
226
|
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
174
227
|
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
@@ -228,13 +281,24 @@ export declare class Trie extends IterableElementBase<string, Trie> {
|
|
|
228
281
|
* @returns The `map` function is returning a new Trie object.
|
|
229
282
|
*/
|
|
230
283
|
map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
|
|
284
|
+
/**
|
|
285
|
+
* Time Complexity: O(n)
|
|
286
|
+
* Space Complexity: O(n)
|
|
287
|
+
*/
|
|
288
|
+
/**
|
|
289
|
+
* Time Complexity: O(n)
|
|
290
|
+
* Space Complexity: O(n)
|
|
291
|
+
*
|
|
292
|
+
* The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
|
|
293
|
+
* trie data structure and yields all the paths to the end nodes.
|
|
294
|
+
*/
|
|
231
295
|
protected _getIterator(): IterableIterator<string>;
|
|
232
296
|
/**
|
|
233
|
-
* Time Complexity: O(
|
|
297
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
234
298
|
* Space Complexity: O(1) - Constant space.
|
|
235
299
|
*/
|
|
236
300
|
/**
|
|
237
|
-
* Time Complexity: O(
|
|
301
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
238
302
|
* Space Complexity: O(1) - Constant space.
|
|
239
303
|
*
|
|
240
304
|
* @param str
|