data-structure-typed 1.42.7 → 1.42.9

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