data-structure-typed 1.42.8 → 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.
- package/CHANGELOG.md +1 -1
- package/README.md +12 -12
- package/benchmark/report.html +12 -12
- package/benchmark/report.json +106 -106
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/cjs/src/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/cjs/src/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/cjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/cjs/src/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/cjs/src/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/cjs/src/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/cjs/src/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/cjs/src/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js +175 -12
- package/dist/cjs/src/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/cjs/src/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/cjs/src/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/cjs/src/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js +113 -3
- package/dist/cjs/src/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js +87 -0
- package/dist/cjs/src/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js +42 -0
- package/dist/cjs/src/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/cjs/src/data-structures/trie/trie.js +76 -1
- package/dist/cjs/src/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.d.ts +88 -23
- package/dist/mjs/src/data-structures/binary-tree/avl-tree.js +88 -23
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.d.ts +180 -74
- package/dist/mjs/src/data-structures/binary-tree/binary-tree.js +388 -201
- package/dist/mjs/src/data-structures/binary-tree/bst.d.ts +121 -66
- package/dist/mjs/src/data-structures/binary-tree/bst.js +121 -67
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.d.ts +72 -5
- package/dist/mjs/src/data-structures/binary-tree/rb-tree.js +95 -18
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.d.ts +82 -43
- package/dist/mjs/src/data-structures/binary-tree/tree-multimap.js +82 -43
- package/dist/mjs/src/data-structures/graph/abstract-graph.d.ts +139 -36
- package/dist/mjs/src/data-structures/graph/abstract-graph.js +147 -36
- package/dist/mjs/src/data-structures/graph/directed-graph.d.ts +126 -0
- package/dist/mjs/src/data-structures/graph/directed-graph.js +126 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/mjs/src/data-structures/graph/undirected-graph.js +63 -0
- package/dist/mjs/src/data-structures/heap/heap.d.ts +175 -12
- package/dist/mjs/src/data-structures/heap/heap.js +175 -12
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.d.ts +203 -0
- package/dist/mjs/src/data-structures/linked-list/doubly-linked-list.js +203 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.d.ts +182 -0
- package/dist/mjs/src/data-structures/linked-list/singly-linked-list.js +182 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.d.ts +64 -0
- package/dist/mjs/src/data-structures/linked-list/skip-linked-list.js +64 -0
- package/dist/mjs/src/data-structures/queue/deque.d.ts +113 -3
- package/dist/mjs/src/data-structures/queue/deque.js +113 -3
- package/dist/mjs/src/data-structures/queue/queue.d.ts +87 -0
- package/dist/mjs/src/data-structures/queue/queue.js +87 -0
- package/dist/mjs/src/data-structures/stack/stack.d.ts +42 -0
- package/dist/mjs/src/data-structures/stack/stack.js +42 -0
- package/dist/mjs/src/data-structures/trie/trie.d.ts +76 -0
- package/dist/mjs/src/data-structures/trie/trie.js +76 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +97 -23
- package/src/data-structures/binary-tree/binary-tree.ts +419 -204
- package/src/data-structures/binary-tree/bst.ts +130 -68
- package/src/data-structures/binary-tree/rb-tree.ts +106 -19
- package/src/data-structures/binary-tree/tree-multimap.ts +88 -44
- package/src/data-structures/graph/abstract-graph.ts +133 -7
- package/src/data-structures/graph/directed-graph.ts +145 -1
- package/src/data-structures/graph/undirected-graph.ts +72 -0
- package/src/data-structures/heap/heap.ts +201 -12
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +208 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +74 -0
- package/src/data-structures/queue/deque.ts +127 -3
- package/src/data-structures/queue/queue.ts +99 -0
- package/src/data-structures/stack/stack.ts +48 -0
- package/src/data-structures/trie/trie.ts +87 -4
- package/test/integration/index.html +24 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +19 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -1
|
@@ -44,6 +44,13 @@ class SinglyLinkedList {
|
|
|
44
44
|
return this._length;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
48
|
+
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
52
|
+
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
|
|
53
|
+
*
|
|
47
54
|
* The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
|
|
48
55
|
* array.
|
|
49
56
|
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
@@ -57,6 +64,13 @@ class SinglyLinkedList {
|
|
|
57
64
|
return singlyLinkedList;
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
67
|
+
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
68
|
+
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
72
|
+
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
73
|
+
*
|
|
60
74
|
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
61
75
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
62
76
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
@@ -74,6 +88,13 @@ class SinglyLinkedList {
|
|
|
74
88
|
this._length++;
|
|
75
89
|
}
|
|
76
90
|
/**
|
|
91
|
+
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
92
|
+
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
96
|
+
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
97
|
+
*
|
|
77
98
|
* The `push` function adds a new node with the given value to the end of a singly linked list.
|
|
78
99
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
79
100
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
@@ -82,6 +103,13 @@ class SinglyLinkedList {
|
|
|
82
103
|
this.push(value);
|
|
83
104
|
}
|
|
84
105
|
/**
|
|
106
|
+
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
107
|
+
* Space Complexity: O(1) - Constant space.
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
111
|
+
* Space Complexity: O(1) - Constant space.
|
|
112
|
+
*
|
|
85
113
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
86
114
|
* pointers accordingly.
|
|
87
115
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
@@ -108,6 +136,13 @@ class SinglyLinkedList {
|
|
|
108
136
|
return value;
|
|
109
137
|
}
|
|
110
138
|
/**
|
|
139
|
+
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
140
|
+
* Space Complexity: O(1) - Constant space.
|
|
141
|
+
*/
|
|
142
|
+
/**
|
|
143
|
+
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
144
|
+
* Space Complexity: O(1) - Constant space.
|
|
145
|
+
*
|
|
111
146
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
112
147
|
* pointers accordingly.
|
|
113
148
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
@@ -117,6 +152,13 @@ class SinglyLinkedList {
|
|
|
117
152
|
return this.pop();
|
|
118
153
|
}
|
|
119
154
|
/**
|
|
155
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
156
|
+
* Space Complexity: O(1) - Constant space.
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
160
|
+
* Space Complexity: O(1) - Constant space.
|
|
161
|
+
*
|
|
120
162
|
* The `shift()` function removes and returns the value of the first node in a linked list.
|
|
121
163
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
122
164
|
*/
|
|
@@ -129,6 +171,13 @@ class SinglyLinkedList {
|
|
|
129
171
|
return removedNode.value;
|
|
130
172
|
}
|
|
131
173
|
/**
|
|
174
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
175
|
+
* Space Complexity: O(1) - Constant space.
|
|
176
|
+
*/
|
|
177
|
+
/**
|
|
178
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
179
|
+
* Space Complexity: O(1) - Constant space.
|
|
180
|
+
*
|
|
132
181
|
* The `popFirst()` function removes and returns the value of the first node in a linked list.
|
|
133
182
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
134
183
|
*/
|
|
@@ -136,6 +185,13 @@ class SinglyLinkedList {
|
|
|
136
185
|
return this.shift();
|
|
137
186
|
}
|
|
138
187
|
/**
|
|
188
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
189
|
+
* Space Complexity: O(1) - Constant space.
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
193
|
+
* Space Complexity: O(1) - Constant space.
|
|
194
|
+
*
|
|
139
195
|
* The unshift function adds a new node with the given value to the beginning of a singly linked list.
|
|
140
196
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
141
197
|
* linked list.
|
|
@@ -153,6 +209,13 @@ class SinglyLinkedList {
|
|
|
153
209
|
this._length++;
|
|
154
210
|
}
|
|
155
211
|
/**
|
|
212
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
213
|
+
* Space Complexity: O(1) - Constant space.
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
217
|
+
* Space Complexity: O(1) - Constant space.
|
|
218
|
+
*
|
|
156
219
|
* The addFirst function adds a new node with the given value to the beginning of a singly linked list.
|
|
157
220
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
158
221
|
* linked list.
|
|
@@ -161,6 +224,13 @@ class SinglyLinkedList {
|
|
|
161
224
|
this.unshift(value);
|
|
162
225
|
}
|
|
163
226
|
/**
|
|
227
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
228
|
+
* Space Complexity: O(1) - Constant space.
|
|
229
|
+
*/
|
|
230
|
+
/**
|
|
231
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
232
|
+
* Space Complexity: O(1) - Constant space.
|
|
233
|
+
*
|
|
164
234
|
* The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
|
|
165
235
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
166
236
|
* retrieve from the list.
|
|
@@ -177,6 +247,13 @@ class SinglyLinkedList {
|
|
|
177
247
|
return current.value;
|
|
178
248
|
}
|
|
179
249
|
/**
|
|
250
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
251
|
+
* Space Complexity: O(1) - Constant space.
|
|
252
|
+
*/
|
|
253
|
+
/**
|
|
254
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
255
|
+
* Space Complexity: O(1) - Constant space.
|
|
256
|
+
*
|
|
180
257
|
* The function `getNodeAt` returns the node at a given index in a singly linked list.
|
|
181
258
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
182
259
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
@@ -191,6 +268,13 @@ class SinglyLinkedList {
|
|
|
191
268
|
return current;
|
|
192
269
|
}
|
|
193
270
|
/**
|
|
271
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
272
|
+
* Space Complexity: O(1) - Constant space.
|
|
273
|
+
*/
|
|
274
|
+
/**
|
|
275
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
276
|
+
* Space Complexity: O(1) - Constant space.
|
|
277
|
+
*
|
|
194
278
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
195
279
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
196
280
|
* data structure. It is of type number.
|
|
@@ -211,6 +295,13 @@ class SinglyLinkedList {
|
|
|
211
295
|
return removedNode.value;
|
|
212
296
|
}
|
|
213
297
|
/**
|
|
298
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
299
|
+
* Space Complexity: O(1) - Constant space.
|
|
300
|
+
*/
|
|
301
|
+
/**
|
|
302
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
303
|
+
* Space Complexity: O(1) - Constant space.
|
|
304
|
+
*
|
|
214
305
|
* The delete function removes a node with a specific value from a singly linked list.
|
|
215
306
|
* @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
|
|
216
307
|
* or a `SinglyLinkedListNode<E>` object.
|
|
@@ -251,6 +342,13 @@ class SinglyLinkedList {
|
|
|
251
342
|
return false;
|
|
252
343
|
}
|
|
253
344
|
/**
|
|
345
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
346
|
+
* Space Complexity: O(1) - Constant space.
|
|
347
|
+
*/
|
|
348
|
+
/**
|
|
349
|
+
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
350
|
+
* Space Complexity: O(1) - Constant space.
|
|
351
|
+
*
|
|
254
352
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
255
353
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
256
354
|
* linked list. It is of type number.
|
|
@@ -294,6 +392,13 @@ class SinglyLinkedList {
|
|
|
294
392
|
this._length = 0;
|
|
295
393
|
}
|
|
296
394
|
/**
|
|
395
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
396
|
+
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
|
|
397
|
+
*/
|
|
398
|
+
/**
|
|
399
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
400
|
+
* Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
|
|
401
|
+
*
|
|
297
402
|
* The `toArray` function converts a linked list into an array.
|
|
298
403
|
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
299
404
|
*/
|
|
@@ -307,6 +412,13 @@ class SinglyLinkedList {
|
|
|
307
412
|
return array;
|
|
308
413
|
}
|
|
309
414
|
/**
|
|
415
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
416
|
+
* Space Complexity: O(1) - Constant space.
|
|
417
|
+
*/
|
|
418
|
+
/**
|
|
419
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
420
|
+
* Space Complexity: O(1) - Constant space.
|
|
421
|
+
*
|
|
310
422
|
* The `reverse` function reverses the order of the nodes in a singly linked list.
|
|
311
423
|
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
312
424
|
*/
|
|
@@ -325,6 +437,13 @@ class SinglyLinkedList {
|
|
|
325
437
|
[this._head, this._tail] = [this.tail, this.head];
|
|
326
438
|
}
|
|
327
439
|
/**
|
|
440
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
441
|
+
* Space Complexity: O(1) - Constant space.
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
445
|
+
* Space Complexity: O(1) - Constant space.
|
|
446
|
+
*
|
|
328
447
|
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
329
448
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
330
449
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
@@ -342,6 +461,13 @@ class SinglyLinkedList {
|
|
|
342
461
|
return null;
|
|
343
462
|
}
|
|
344
463
|
/**
|
|
464
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
465
|
+
* Space Complexity: O(1) - Constant space.
|
|
466
|
+
*/
|
|
467
|
+
/**
|
|
468
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
469
|
+
* Space Complexity: O(1) - Constant space.
|
|
470
|
+
*
|
|
345
471
|
* The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
|
|
346
472
|
* @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
|
|
347
473
|
* @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
|
|
@@ -360,6 +486,13 @@ class SinglyLinkedList {
|
|
|
360
486
|
return -1;
|
|
361
487
|
}
|
|
362
488
|
/**
|
|
489
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
490
|
+
* Space Complexity: O(1) - Constant space.
|
|
491
|
+
*/
|
|
492
|
+
/**
|
|
493
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
494
|
+
* Space Complexity: O(1) - Constant space.
|
|
495
|
+
*
|
|
363
496
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
364
497
|
* null.
|
|
365
498
|
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
@@ -377,6 +510,13 @@ class SinglyLinkedList {
|
|
|
377
510
|
return null;
|
|
378
511
|
}
|
|
379
512
|
/**
|
|
513
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
514
|
+
* Space Complexity: O(1) - Constant space.
|
|
515
|
+
*/
|
|
516
|
+
/**
|
|
517
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
518
|
+
* Space Complexity: O(1) - Constant space.
|
|
519
|
+
*
|
|
380
520
|
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
|
|
381
521
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
382
522
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
@@ -412,6 +552,13 @@ class SinglyLinkedList {
|
|
|
412
552
|
return false;
|
|
413
553
|
}
|
|
414
554
|
/**
|
|
555
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
556
|
+
* Space Complexity: O(1) - Constant space.
|
|
557
|
+
*/
|
|
558
|
+
/**
|
|
559
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
560
|
+
* Space Complexity: O(1) - Constant space.
|
|
561
|
+
*
|
|
415
562
|
* The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
416
563
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
417
564
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
@@ -440,6 +587,13 @@ class SinglyLinkedList {
|
|
|
440
587
|
return false;
|
|
441
588
|
}
|
|
442
589
|
/**
|
|
590
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
591
|
+
* Space Complexity: O(1) - Constant space.
|
|
592
|
+
*/
|
|
593
|
+
/**
|
|
594
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
595
|
+
* Space Complexity: O(1) - Constant space.
|
|
596
|
+
*
|
|
443
597
|
* The function counts the number of occurrences of a given value in a linked list.
|
|
444
598
|
* @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
|
|
445
599
|
* @returns The count of occurrences of the given value in the linked list.
|
|
@@ -456,6 +610,13 @@ class SinglyLinkedList {
|
|
|
456
610
|
return count;
|
|
457
611
|
}
|
|
458
612
|
/**
|
|
613
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
614
|
+
* Space Complexity: O(1) - Constant space.
|
|
615
|
+
*/
|
|
616
|
+
/**
|
|
617
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
618
|
+
* Space Complexity: O(1) - Constant space.
|
|
619
|
+
*
|
|
459
620
|
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
460
621
|
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
461
622
|
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
@@ -471,6 +632,13 @@ class SinglyLinkedList {
|
|
|
471
632
|
}
|
|
472
633
|
}
|
|
473
634
|
/**
|
|
635
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
636
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
637
|
+
*/
|
|
638
|
+
/**
|
|
639
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
640
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
641
|
+
*
|
|
474
642
|
* The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
|
|
475
643
|
* SinglyLinkedList with the transformed values.
|
|
476
644
|
* @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
|
|
@@ -488,6 +656,13 @@ class SinglyLinkedList {
|
|
|
488
656
|
return mappedList;
|
|
489
657
|
}
|
|
490
658
|
/**
|
|
659
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
660
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
661
|
+
*/
|
|
662
|
+
/**
|
|
663
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
664
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
665
|
+
*
|
|
491
666
|
* The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
|
|
492
667
|
* elements that satisfy the given callback function.
|
|
493
668
|
* @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
|
|
@@ -506,6 +681,13 @@ class SinglyLinkedList {
|
|
|
506
681
|
return filteredList;
|
|
507
682
|
}
|
|
508
683
|
/**
|
|
684
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
685
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
686
|
+
*/
|
|
687
|
+
/**
|
|
688
|
+
* Time Complexity: O(n) - Linear time, where n is the length of the list, as they need to traverse the entire list to apply the callback or reduce the list.
|
|
689
|
+
* Space Complexity: O(n) - Linear space, as they create new nodes or arrays.
|
|
690
|
+
*
|
|
509
691
|
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
510
692
|
* single value.
|
|
511
693
|
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
@@ -29,6 +29,13 @@ export declare class SkipList<K, V> {
|
|
|
29
29
|
protected _probability: number;
|
|
30
30
|
get probability(): number;
|
|
31
31
|
/**
|
|
32
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
33
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
37
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
38
|
+
*
|
|
32
39
|
* The add function adds a new node with a given key and value to a Skip List data structure.
|
|
33
40
|
* @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
|
|
34
41
|
* @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
|
|
@@ -36,14 +43,36 @@ export declare class SkipList<K, V> {
|
|
|
36
43
|
*/
|
|
37
44
|
add(key: K, value: V): void;
|
|
38
45
|
/**
|
|
46
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
47
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
51
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
52
|
+
*
|
|
39
53
|
* The function `get` retrieves the value associated with a given key from a skip list data structure.
|
|
40
54
|
* @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
|
|
41
55
|
* @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
|
|
42
56
|
* otherwise it returns `undefined`.
|
|
43
57
|
*/
|
|
44
58
|
get(key: K): V | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
61
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
65
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
66
|
+
*/
|
|
45
67
|
has(key: K): boolean;
|
|
46
68
|
/**
|
|
69
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
70
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
74
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
75
|
+
*
|
|
47
76
|
* The `delete` function removes a node with a specific key from a Skip List data structure.
|
|
48
77
|
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
|
|
49
78
|
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
|
|
@@ -51,28 +80,63 @@ export declare class SkipList<K, V> {
|
|
|
51
80
|
*/
|
|
52
81
|
delete(key: K): boolean;
|
|
53
82
|
/**
|
|
83
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
84
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
88
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
89
|
+
*
|
|
54
90
|
* Get the value of the first element (the smallest element) in the Skip List.
|
|
55
91
|
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
56
92
|
*/
|
|
57
93
|
getFirst(): V | undefined;
|
|
58
94
|
/**
|
|
95
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
96
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
100
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
101
|
+
*
|
|
59
102
|
* Get the value of the last element (the largest element) in the Skip List.
|
|
60
103
|
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
61
104
|
*/
|
|
62
105
|
getLast(): V | undefined;
|
|
63
106
|
/**
|
|
107
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
108
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
112
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
113
|
+
*
|
|
64
114
|
* Get the value of the first element in the Skip List that is greater than the given key.
|
|
65
115
|
* @param key - the given key.
|
|
66
116
|
* @returns The value of the first element greater than the given key, or undefined if there is no such element.
|
|
67
117
|
*/
|
|
68
118
|
higher(key: K): V | undefined;
|
|
69
119
|
/**
|
|
120
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
121
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
125
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
126
|
+
*
|
|
70
127
|
* Get the value of the last element in the Skip List that is less than the given key.
|
|
71
128
|
* @param key - the given key.
|
|
72
129
|
* @returns The value of the last element less than the given key, or undefined if there is no such element.
|
|
73
130
|
*/
|
|
74
131
|
lower(key: K): V | undefined;
|
|
75
132
|
/**
|
|
133
|
+
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
|
|
134
|
+
* Space Complexity: O(1) - constant space.
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
|
|
138
|
+
* Space Complexity: O(1) - constant space.
|
|
139
|
+
*
|
|
76
140
|
* The function "_randomLevel" generates a random level based on a given probability and maximum level.
|
|
77
141
|
* @returns the level, which is a number.
|
|
78
142
|
*/
|
|
@@ -50,6 +50,13 @@ class SkipList {
|
|
|
50
50
|
return this._probability;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
54
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
58
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
59
|
+
*
|
|
53
60
|
* The add function adds a new node with a given key and value to a Skip List data structure.
|
|
54
61
|
* @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
|
|
55
62
|
* @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
|
|
@@ -74,6 +81,13 @@ class SkipList {
|
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
/**
|
|
84
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
85
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
89
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
90
|
+
*
|
|
77
91
|
* The function `get` retrieves the value associated with a given key from a skip list data structure.
|
|
78
92
|
* @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
|
|
79
93
|
* @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
|
|
@@ -92,10 +106,25 @@ class SkipList {
|
|
|
92
106
|
}
|
|
93
107
|
return undefined;
|
|
94
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
111
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
115
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
116
|
+
*/
|
|
95
117
|
has(key) {
|
|
96
118
|
return this.get(key) !== undefined;
|
|
97
119
|
}
|
|
98
120
|
/**
|
|
121
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
122
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
126
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
127
|
+
*
|
|
99
128
|
* The `delete` function removes a node with a specific key from a Skip List data structure.
|
|
100
129
|
* @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
|
|
101
130
|
* @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
|
|
@@ -126,6 +155,13 @@ class SkipList {
|
|
|
126
155
|
return false;
|
|
127
156
|
}
|
|
128
157
|
/**
|
|
158
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
159
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
160
|
+
*/
|
|
161
|
+
/**
|
|
162
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
163
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
164
|
+
*
|
|
129
165
|
* Get the value of the first element (the smallest element) in the Skip List.
|
|
130
166
|
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
131
167
|
*/
|
|
@@ -134,6 +170,13 @@ class SkipList {
|
|
|
134
170
|
return firstNode ? firstNode.value : undefined;
|
|
135
171
|
}
|
|
136
172
|
/**
|
|
173
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
174
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
178
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
179
|
+
*
|
|
137
180
|
* Get the value of the last element (the largest element) in the Skip List.
|
|
138
181
|
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
139
182
|
*/
|
|
@@ -147,6 +190,13 @@ class SkipList {
|
|
|
147
190
|
return current.value;
|
|
148
191
|
}
|
|
149
192
|
/**
|
|
193
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
194
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
195
|
+
*/
|
|
196
|
+
/**
|
|
197
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
198
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
199
|
+
*
|
|
150
200
|
* Get the value of the first element in the Skip List that is greater than the given key.
|
|
151
201
|
* @param key - the given key.
|
|
152
202
|
* @returns The value of the first element greater than the given key, or undefined if there is no such element.
|
|
@@ -162,6 +212,13 @@ class SkipList {
|
|
|
162
212
|
return nextNode ? nextNode.value : undefined;
|
|
163
213
|
}
|
|
164
214
|
/**
|
|
215
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
216
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
220
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
221
|
+
*
|
|
165
222
|
* Get the value of the last element in the Skip List that is less than the given key.
|
|
166
223
|
* @param key - the given key.
|
|
167
224
|
* @returns The value of the last element less than the given key, or undefined if there is no such element.
|
|
@@ -180,6 +237,13 @@ class SkipList {
|
|
|
180
237
|
return lastLess ? lastLess.value : undefined;
|
|
181
238
|
}
|
|
182
239
|
/**
|
|
240
|
+
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
|
|
241
|
+
* Space Complexity: O(1) - constant space.
|
|
242
|
+
*/
|
|
243
|
+
/**
|
|
244
|
+
* Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
|
|
245
|
+
* Space Complexity: O(1) - constant space.
|
|
246
|
+
*
|
|
183
247
|
* The function "_randomLevel" generates a random level based on a given probability and maximum level.
|
|
184
248
|
* @returns the level, which is a number.
|
|
185
249
|
*/
|