min-heap-typed 1.42.8 → 1.43.0

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.
Files changed (49) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +88 -23
  2. package/dist/data-structures/binary-tree/avl-tree.js +88 -23
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +180 -74
  4. package/dist/data-structures/binary-tree/binary-tree.js +415 -236
  5. package/dist/data-structures/binary-tree/bst.d.ts +121 -66
  6. package/dist/data-structures/binary-tree/bst.js +121 -67
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +72 -5
  8. package/dist/data-structures/binary-tree/rb-tree.js +95 -18
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +82 -43
  10. package/dist/data-structures/binary-tree/tree-multimap.js +82 -43
  11. package/dist/data-structures/graph/abstract-graph.d.ts +139 -36
  12. package/dist/data-structures/graph/abstract-graph.js +147 -36
  13. package/dist/data-structures/graph/directed-graph.d.ts +126 -0
  14. package/dist/data-structures/graph/directed-graph.js +126 -0
  15. package/dist/data-structures/graph/undirected-graph.d.ts +63 -0
  16. package/dist/data-structures/graph/undirected-graph.js +63 -0
  17. package/dist/data-structures/heap/heap.d.ts +175 -12
  18. package/dist/data-structures/heap/heap.js +175 -12
  19. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
  20. package/dist/data-structures/linked-list/doubly-linked-list.js +203 -0
  21. package/dist/data-structures/linked-list/singly-linked-list.d.ts +182 -0
  22. package/dist/data-structures/linked-list/singly-linked-list.js +182 -0
  23. package/dist/data-structures/linked-list/skip-linked-list.d.ts +64 -0
  24. package/dist/data-structures/linked-list/skip-linked-list.js +64 -0
  25. package/dist/data-structures/queue/deque.d.ts +113 -3
  26. package/dist/data-structures/queue/deque.js +113 -3
  27. package/dist/data-structures/queue/queue.d.ts +87 -0
  28. package/dist/data-structures/queue/queue.js +87 -0
  29. package/dist/data-structures/stack/stack.d.ts +42 -0
  30. package/dist/data-structures/stack/stack.js +42 -0
  31. package/dist/data-structures/trie/trie.d.ts +76 -0
  32. package/dist/data-structures/trie/trie.js +76 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/avl-tree.ts +97 -23
  35. package/src/data-structures/binary-tree/binary-tree.ts +465 -256
  36. package/src/data-structures/binary-tree/bst.ts +130 -68
  37. package/src/data-structures/binary-tree/rb-tree.ts +106 -19
  38. package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
  39. package/src/data-structures/graph/abstract-graph.ts +133 -7
  40. package/src/data-structures/graph/directed-graph.ts +145 -1
  41. package/src/data-structures/graph/undirected-graph.ts +72 -0
  42. package/src/data-structures/heap/heap.ts +201 -12
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
  44. package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
  45. package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
  46. package/src/data-structures/queue/deque.ts +127 -3
  47. package/src/data-structures/queue/queue.ts +99 -0
  48. package/src/data-structures/stack/stack.ts +48 -0
  49. package/src/data-structures/trie/trie.ts +87 -4
@@ -75,6 +75,13 @@ class Queue {
75
75
  return new Queue(elements);
76
76
  }
77
77
  /**
78
+ * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
79
+ * Space Complexity: O(1) - no additional space is used.
80
+ */
81
+ /**
82
+ * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
83
+ * Space Complexity: O(1) - no additional space is used.
84
+ *
78
85
  * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
79
86
  * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
80
87
  * @returns The `add` method is returning a `Queue<E>` object.
@@ -84,6 +91,13 @@ class Queue {
84
91
  return this;
85
92
  }
86
93
  /**
94
+ * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
95
+ * Space Complexity: O(1) - no additional space is used.
96
+ */
97
+ /**
98
+ * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
99
+ * Space Complexity: O(1) - no additional space is used.
100
+ *
87
101
  * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
88
102
  * necessary to optimize performance.
89
103
  * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
@@ -102,6 +116,13 @@ class Queue {
102
116
  return first;
103
117
  }
104
118
  /**
119
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
120
+ * Space Complexity: O(1) - no additional space is used.
121
+ */
122
+ /**
123
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
124
+ * Space Complexity: O(1) - no additional space is used.
125
+ *
105
126
  * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
106
127
  * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
107
128
  * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
@@ -110,6 +131,13 @@ class Queue {
110
131
  return this.size > 0 ? this.nodes[this.offset] : undefined;
111
132
  }
112
133
  /**
134
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
135
+ * Space Complexity: O(1) - no additional space is used.
136
+ */
137
+ /**
138
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
139
+ * Space Complexity: O(1) - no additional space is used.
140
+ *
113
141
  * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
114
142
  * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
115
143
  * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
@@ -118,6 +146,13 @@ class Queue {
118
146
  return this.getFirst();
119
147
  }
120
148
  /**
149
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
150
+ * Space Complexity: O(1) - no additional space is used.
151
+ */
152
+ /**
153
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
154
+ * Space Complexity: O(1) - no additional space is used.
155
+ *
121
156
  * The `getLast` function returns the last element in an array-like data structure, or null if the structure is empty.
122
157
  * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
123
158
  * array is empty, it returns `null`.
@@ -126,6 +161,13 @@ class Queue {
126
161
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
127
162
  }
128
163
  /**
164
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
165
+ * Space Complexity: O(1) - no additional space is used.
166
+ */
167
+ /**
168
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
169
+ * Space Complexity: O(1) - no additional space is used.
170
+ *
129
171
  * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
130
172
  * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
131
173
  * array is empty, it returns `null`.
@@ -134,6 +176,13 @@ class Queue {
134
176
  return this.getLast();
135
177
  }
136
178
  /**
179
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
180
+ * Space Complexity: O(1) - no additional space is used.
181
+ */
182
+ /**
183
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
184
+ * Space Complexity: O(1) - no additional space is used.
185
+ *
137
186
  * The enqueue function adds a value to the end of a queue.
138
187
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
139
188
  */
@@ -141,16 +190,40 @@ class Queue {
141
190
  this.push(value);
142
191
  }
143
192
  /**
193
+ * Time Complexity: O(n) - same as shift().
194
+ * Space Complexity: O(1) - same as shift().
195
+ */
196
+ /**
197
+ * Time Complexity: O(n) - same as shift().
198
+ * Space Complexity: O(1) - same as shift().
199
+ *
144
200
  * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
145
201
  * @returns The method is returning a value of type E or null.
146
202
  */
147
203
  dequeue() {
148
204
  return this.shift();
149
205
  }
206
+ /**
207
+ * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
208
+ * Space Complexity: O(1) - no additional space is used.
209
+ */
210
+ /**
211
+ * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
212
+ * Space Complexity: O(1) - no additional space is used.
213
+ *
214
+ * @param index
215
+ */
150
216
  getAt(index) {
151
217
  return this.nodes[index];
152
218
  }
153
219
  /**
220
+ * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
221
+ * Space Complexity: O(1) - no additional space is used.
222
+ */
223
+ /**
224
+ * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
225
+ * Space Complexity: O(1) - no additional space is used.
226
+ *
154
227
  * The function checks if a data structure is empty by comparing its size to zero.
155
228
  * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
156
229
  */
@@ -158,6 +231,13 @@ class Queue {
158
231
  return this.size === 0;
159
232
  }
160
233
  /**
234
+ * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
235
+ * Space Complexity: O(n) - where n is the number of elements in the queue.
236
+ */
237
+ /**
238
+ * Time Complexity: O(1) - constant time as it returns a shallow copy of the internal array.
239
+ * Space Complexity: O(n) - where n is the number of elements in the queue.
240
+ *
161
241
  * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
162
242
  * @returns An array of type E is being returned.
163
243
  */
@@ -172,6 +252,13 @@ class Queue {
172
252
  this._offset = 0;
173
253
  }
174
254
  /**
255
+ * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
256
+ * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
257
+ */
258
+ /**
259
+ * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
260
+ * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
261
+ *
175
262
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
176
263
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
177
264
  */
@@ -14,6 +14,13 @@ export declare class Stack<E = any> {
14
14
  protected _elements: E[];
15
15
  get elements(): E[];
16
16
  /**
17
+ * 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.
18
+ * Space Complexity: O(n), as it creates a new stack with the elements from the input array.
19
+ */
20
+ /**
21
+ * 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.
22
+ * Space Complexity: O(n), as it creates a new stack with the elements from the input array.
23
+ *
17
24
  * The function "fromArray" creates a new Stack object from an array of elements.
18
25
  * @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
19
26
  * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
@@ -31,23 +38,51 @@ export declare class Stack<E = any> {
31
38
  */
32
39
  size(): number;
33
40
  /**
41
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
42
+ * Space Complexity: O(1), as it does not use any additional space.
43
+ */
44
+ /**
45
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
46
+ * Space Complexity: O(1), as it does not use any additional space.
47
+ *
34
48
  * The `peek` function returns the last element of an array, or null if the array is empty.
35
49
  * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
36
50
  */
37
51
  peek(): E | null;
38
52
  /**
53
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
54
+ * Space Complexity: O(1), as it does not use any additional space.
55
+ */
56
+ /**
57
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
58
+ * Space Complexity: O(1), as it does not use any additional space.
59
+ *
39
60
  * The push function adds an element to the stack and returns the updated stack.
40
61
  * @param {E} element - The parameter "element" is of type E, which means it can be any data type.
41
62
  * @returns The `push` method is returning the updated `Stack<E>` object.
42
63
  */
43
64
  push(element: E): Stack<E>;
44
65
  /**
66
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
67
+ * Space Complexity: O(1), as it does not use any additional space.
68
+ */
69
+ /**
70
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
71
+ * Space Complexity: O(1), as it does not use any additional space.
72
+ *
45
73
  * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
46
74
  * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
47
75
  * array is empty, it returns `null`.
48
76
  */
49
77
  pop(): E | null;
50
78
  /**
79
+ * Time Complexity: O(n)
80
+ * Space Complexity: O(n)
81
+ */
82
+ /**
83
+ * Time Complexity: O(n)
84
+ * Space Complexity: O(n)
85
+ *
51
86
  * The toArray function returns a copy of the elements in an array.
52
87
  * @returns An array of type E.
53
88
  */
@@ -57,6 +92,13 @@ export declare class Stack<E = any> {
57
92
  */
58
93
  clear(): void;
59
94
  /**
95
+ * Time Complexity: O(n), where n is the number of elements in the stack, as it creates a new stack and copies all elements into it.
96
+ * Space Complexity: O(n), as it creates a new stack.
97
+ */
98
+ /**
99
+ * Time Complexity: O(n), where n is the number of elements in the stack, as it creates a new stack and copies all elements into it.
100
+ * Space Complexity: O(n), as it creates a new stack.
101
+ *
60
102
  * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
61
103
  * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
62
104
  */
@@ -20,6 +20,13 @@ class Stack {
20
20
  return this._elements;
21
21
  }
22
22
  /**
23
+ * 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.
24
+ * Space Complexity: O(n), as it creates a new stack with the elements from the input array.
25
+ */
26
+ /**
27
+ * 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.
28
+ * Space Complexity: O(n), as it creates a new stack with the elements from the input array.
29
+ *
23
30
  * The function "fromArray" creates a new Stack object from an array of elements.
24
31
  * @param {E[]} elements - The `elements` parameter is an array of elements of type `E`.
25
32
  * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
@@ -43,6 +50,13 @@ class Stack {
43
50
  return this.elements.length;
44
51
  }
45
52
  /**
53
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
54
+ * Space Complexity: O(1), as it does not use any additional space.
55
+ */
56
+ /**
57
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
58
+ * Space Complexity: O(1), as it does not use any additional space.
59
+ *
46
60
  * The `peek` function returns the last element of an array, or null if the array is empty.
47
61
  * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
48
62
  */
@@ -52,6 +66,13 @@ class Stack {
52
66
  return this.elements[this.elements.length - 1];
53
67
  }
54
68
  /**
69
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
70
+ * Space Complexity: O(1), as it does not use any additional space.
71
+ */
72
+ /**
73
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
74
+ * Space Complexity: O(1), as it does not use any additional space.
75
+ *
55
76
  * The push function adds an element to the stack and returns the updated stack.
56
77
  * @param {E} element - The parameter "element" is of type E, which means it can be any data type.
57
78
  * @returns The `push` method is returning the updated `Stack<E>` object.
@@ -61,6 +82,13 @@ class Stack {
61
82
  return this;
62
83
  }
63
84
  /**
85
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
86
+ * Space Complexity: O(1), as it does not use any additional space.
87
+ */
88
+ /**
89
+ * Time Complexity: O(1), as it only involves accessing the last element of the array.
90
+ * Space Complexity: O(1), as it does not use any additional space.
91
+ *
64
92
  * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
65
93
  * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
66
94
  * array is empty, it returns `null`.
@@ -71,6 +99,13 @@ class Stack {
71
99
  return this.elements.pop() || null;
72
100
  }
73
101
  /**
102
+ * Time Complexity: O(n)
103
+ * Space Complexity: O(n)
104
+ */
105
+ /**
106
+ * Time Complexity: O(n)
107
+ * Space Complexity: O(n)
108
+ *
74
109
  * The toArray function returns a copy of the elements in an array.
75
110
  * @returns An array of type E.
76
111
  */
@@ -84,6 +119,13 @@ class Stack {
84
119
  this._elements = [];
85
120
  }
86
121
  /**
122
+ * Time Complexity: O(n), where n is the number of elements in the stack, as it creates a new stack and copies all elements into it.
123
+ * Space Complexity: O(n), as it creates a new stack.
124
+ */
125
+ /**
126
+ * Time Complexity: O(n), where n is the number of elements in the stack, as it creates a new stack and copies all elements into it.
127
+ * Space Complexity: O(n), as it creates a new stack.
128
+ *
87
129
  * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
88
130
  * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
89
131
  */
@@ -25,48 +25,113 @@ export declare class Trie {
25
25
  protected _root: TrieNode;
26
26
  get root(): TrieNode;
27
27
  /**
28
+ * Time Complexity: O(M), where M is the length of the word being added.
29
+ * Space Complexity: O(M) - Each character in the word adds a TrieNode.
30
+ */
31
+ /**
32
+ * Time Complexity: O(M), where M is the length of the word being added.
33
+ * Space Complexity: O(M) - Each character in the word adds a TrieNode.
34
+ *
28
35
  * Add a word to the Trie structure.
29
36
  * @param {string} word - The word to add.
30
37
  * @returns {boolean} True if the word was successfully added.
31
38
  */
32
39
  add(word: string): boolean;
33
40
  /**
41
+ * Time Complexity: O(M), where M is the length of the input word.
42
+ * Space Complexity: O(1) - Constant space.
43
+ */
44
+ /**
45
+ * Time Complexity: O(M), where M is the length of the input word.
46
+ * Space Complexity: O(1) - Constant space.
47
+ *
34
48
  * Check if the Trie contains a given word.
35
49
  * @param {string} word - The word to check for.
36
50
  * @returns {boolean} True if the word is present in the Trie.
37
51
  */
38
52
  has(word: string): boolean;
39
53
  /**
54
+ * Time Complexity: O(M), where M is the length of the word being deleted.
55
+ * Space Complexity: O(M) - Due to the recursive DFS approach.
56
+ */
57
+ /**
58
+ * Time Complexity: O(M), where M is the length of the word being deleted.
59
+ * Space Complexity: O(M) - Due to the recursive DFS approach.
60
+ *
40
61
  * Remove a word from the Trie structure.
41
62
  * @param{string} word - The word to delete.
42
63
  * @returns {boolean} True if the word was successfully removed.
43
64
  */
44
65
  delete(word: string): boolean;
66
+ /**
67
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
68
+ * Space Complexity: O(1) - Constant space.
69
+ */
70
+ /**
71
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
72
+ * Space Complexity: O(1) - Constant space.
73
+ *
74
+ */
45
75
  getHeight(): number;
46
76
  /**
77
+ * Time Complexity: O(M), where M is the length of the input prefix.
78
+ * Space Complexity: O(1) - Constant space.
79
+ */
80
+ /**
81
+ * Time Complexity: O(M), where M is the length of the input prefix.
82
+ * Space Complexity: O(1) - Constant space.
83
+ *
47
84
  * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
48
85
  * @param {string} input - The input string to check.
49
86
  * @returns {boolean} True if it's an absolute prefix in the Trie.
50
87
  */
51
88
  hasPurePrefix(input: string): boolean;
52
89
  /**
90
+ * Time Complexity: O(M), where M is the length of the input prefix.
91
+ * Space Complexity: O(1) - Constant space.
92
+ */
93
+ /**
94
+ * Time Complexity: O(M), where M is the length of the input prefix.
95
+ * Space Complexity: O(1) - Constant space.
96
+ *
53
97
  * 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.
54
98
  * @param {string} input - The input string representing the prefix to check.
55
99
  * @returns {boolean} True if it's a prefix in the Trie.
56
100
  */
57
101
  hasPrefix(input: string): boolean;
58
102
  /**
103
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
104
+ * Space Complexity: O(M), where M is the length of the input prefix.
105
+ */
106
+ /**
107
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
108
+ * Space Complexity: O(M), where M is the length of the input prefix.
109
+ *
59
110
  * Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
60
111
  * @param {string} input - The input string representing the common prefix to check for.
61
112
  * @returns {boolean} True if it's a common prefix in the Trie.
62
113
  */
63
114
  hasCommonPrefix(input: string): boolean;
64
115
  /**
116
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
117
+ * Space Complexity: O(M), where M is the length of the longest common prefix.
118
+ */
119
+ /**
120
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
121
+ * Space Complexity: O(M), where M is the length of the longest common prefix.
122
+ *
65
123
  * Get the longest common prefix among all the words stored in the Trie.
66
124
  * @returns {string} The longest common prefix found in the Trie.
67
125
  */
68
126
  getLongestCommonPrefix(): string;
69
127
  /**
128
+ * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
129
+ * Space Complexity: O(K * L) - The space required for the output array.
130
+ */
131
+ /**
132
+ * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
133
+ * Space Complexity: O(K * L) - The space required for the output array.
134
+ *
70
135
  * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
71
136
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
72
137
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
@@ -75,5 +140,16 @@ export declare class Trie {
75
140
  * @returns {string[]} an array of strings.
76
141
  */
77
142
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
143
+ /**
144
+ * Time Complexity: O(M), where M is the length of the input string.
145
+ * Space Complexity: O(1) - Constant space.
146
+ */
147
+ /**
148
+ * Time Complexity: O(M), where M is the length of the input string.
149
+ * Space Complexity: O(1) - Constant space.
150
+ *
151
+ * @param str
152
+ * @protected
153
+ */
78
154
  protected _caseProcess(str: string): string;
79
155
  }
@@ -40,6 +40,13 @@ class Trie {
40
40
  return this._root;
41
41
  }
42
42
  /**
43
+ * Time Complexity: O(M), where M is the length of the word being added.
44
+ * Space Complexity: O(M) - Each character in the word adds a TrieNode.
45
+ */
46
+ /**
47
+ * Time Complexity: O(M), where M is the length of the word being added.
48
+ * Space Complexity: O(M) - Each character in the word adds a TrieNode.
49
+ *
43
50
  * Add a word to the Trie structure.
44
51
  * @param {string} word - The word to add.
45
52
  * @returns {boolean} True if the word was successfully added.
@@ -59,6 +66,13 @@ class Trie {
59
66
  return true;
60
67
  }
61
68
  /**
69
+ * Time Complexity: O(M), where M is the length of the input word.
70
+ * Space Complexity: O(1) - Constant space.
71
+ */
72
+ /**
73
+ * Time Complexity: O(M), where M is the length of the input word.
74
+ * Space Complexity: O(1) - Constant space.
75
+ *
62
76
  * Check if the Trie contains a given word.
63
77
  * @param {string} word - The word to check for.
64
78
  * @returns {boolean} True if the word is present in the Trie.
@@ -75,6 +89,13 @@ class Trie {
75
89
  return cur.isEnd;
76
90
  }
77
91
  /**
92
+ * Time Complexity: O(M), where M is the length of the word being deleted.
93
+ * Space Complexity: O(M) - Due to the recursive DFS approach.
94
+ */
95
+ /**
96
+ * Time Complexity: O(M), where M is the length of the word being deleted.
97
+ * Space Complexity: O(M) - Due to the recursive DFS approach.
98
+ *
78
99
  * Remove a word from the Trie structure.
79
100
  * @param{string} word - The word to delete.
80
101
  * @returns {boolean} True if the word was successfully removed.
@@ -111,6 +132,15 @@ class Trie {
111
132
  dfs(this.root, 0);
112
133
  return isDeleted;
113
134
  }
135
+ /**
136
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
137
+ * Space Complexity: O(1) - Constant space.
138
+ */
139
+ /**
140
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
141
+ * Space Complexity: O(1) - Constant space.
142
+ *
143
+ */
114
144
  getHeight() {
115
145
  const beginRoot = this.root;
116
146
  let maxDepth = 0;
@@ -130,8 +160,14 @@ class Trie {
130
160
  }
131
161
  return maxDepth;
132
162
  }
133
- // --- start additional methods ---
134
163
  /**
164
+ * Time Complexity: O(M), where M is the length of the input prefix.
165
+ * Space Complexity: O(1) - Constant space.
166
+ */
167
+ /**
168
+ * Time Complexity: O(M), where M is the length of the input prefix.
169
+ * Space Complexity: O(1) - Constant space.
170
+ *
135
171
  * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
136
172
  * @param {string} input - The input string to check.
137
173
  * @returns {boolean} True if it's an absolute prefix in the Trie.
@@ -148,6 +184,13 @@ class Trie {
148
184
  return !cur.isEnd;
149
185
  }
150
186
  /**
187
+ * Time Complexity: O(M), where M is the length of the input prefix.
188
+ * Space Complexity: O(1) - Constant space.
189
+ */
190
+ /**
191
+ * Time Complexity: O(M), where M is the length of the input prefix.
192
+ * Space Complexity: O(1) - Constant space.
193
+ *
151
194
  * 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.
152
195
  * @param {string} input - The input string representing the prefix to check.
153
196
  * @returns {boolean} True if it's a prefix in the Trie.
@@ -164,6 +207,13 @@ class Trie {
164
207
  return true;
165
208
  }
166
209
  /**
210
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
211
+ * Space Complexity: O(M), where M is the length of the input prefix.
212
+ */
213
+ /**
214
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
215
+ * Space Complexity: O(M), where M is the length of the input prefix.
216
+ *
167
217
  * Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
168
218
  * @param {string} input - The input string representing the common prefix to check for.
169
219
  * @returns {boolean} True if it's a common prefix in the Trie.
@@ -186,6 +236,13 @@ class Trie {
186
236
  return commonPre === input;
187
237
  }
188
238
  /**
239
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
240
+ * Space Complexity: O(M), where M is the length of the longest common prefix.
241
+ */
242
+ /**
243
+ * Time Complexity: O(N), where N is the total number of nodes in the trie.
244
+ * Space Complexity: O(M), where M is the length of the longest common prefix.
245
+ *
189
246
  * Get the longest common prefix among all the words stored in the Trie.
190
247
  * @returns {string} The longest common prefix found in the Trie.
191
248
  */
@@ -204,6 +261,13 @@ class Trie {
204
261
  return commonPre;
205
262
  }
206
263
  /**
264
+ * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
265
+ * Space Complexity: O(K * L) - The space required for the output array.
266
+ */
267
+ /**
268
+ * Time Complexity: O(K * L), where K is the number of words retrieved, and L is the average length of the words.
269
+ * Space Complexity: O(K * L) - The space required for the output array.
270
+ *
207
271
  * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
208
272
  * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
209
273
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
@@ -241,6 +305,17 @@ class Trie {
241
305
  dfs(startNode, prefix);
242
306
  return words;
243
307
  }
308
+ /**
309
+ * Time Complexity: O(M), where M is the length of the input string.
310
+ * Space Complexity: O(1) - Constant space.
311
+ */
312
+ /**
313
+ * Time Complexity: O(M), where M is the length of the input string.
314
+ * Space Complexity: O(1) - Constant space.
315
+ *
316
+ * @param str
317
+ * @protected
318
+ */
244
319
  _caseProcess(str) {
245
320
  if (!this._caseSensitive) {
246
321
  str = str.toLowerCase(); // Convert str to lowercase if case-insensitive
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.42.8",
3
+ "version": "1.43.0",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -132,6 +132,6 @@
132
132
  "typescript": "^4.9.5"
133
133
  },
134
134
  "dependencies": {
135
- "data-structure-typed": "^1.42.8"
135
+ "data-structure-typed": "^1.43.0"
136
136
  }
137
137
  }