min-heap-typed 1.50.2 → 1.50.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +51 -20
- package/dist/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/data-structures/binary-tree/index.js +2 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/index.js +2 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -43,7 +43,6 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
43
43
|
for (const el of elements) {
|
|
44
44
|
this.add(el);
|
|
45
45
|
}
|
|
46
|
-
// this.fix();
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -140,6 +139,11 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
140
139
|
return value;
|
|
141
140
|
}
|
|
142
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Time Complexity: O(1)
|
|
144
|
+
* Space Complexity: O(1)
|
|
145
|
+
*/
|
|
146
|
+
|
|
143
147
|
/**
|
|
144
148
|
* Time Complexity: O(1)
|
|
145
149
|
* Space Complexity: O(1)
|
|
@@ -167,12 +171,12 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
/**
|
|
170
|
-
* Time Complexity: O(n)
|
|
174
|
+
* Time Complexity: O(n)
|
|
171
175
|
* Space Complexity: O(n)
|
|
172
176
|
*/
|
|
173
177
|
|
|
174
178
|
/**
|
|
175
|
-
* Time Complexity: O(n)
|
|
179
|
+
* Time Complexity: O(n)
|
|
176
180
|
* Space Complexity: O(n)
|
|
177
181
|
*
|
|
178
182
|
* Clear and add elements of the heap
|
|
@@ -184,12 +188,12 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
/**
|
|
187
|
-
* Time Complexity: O(n)
|
|
191
|
+
* Time Complexity: O(n)
|
|
188
192
|
* Space Complexity: O(1)
|
|
189
193
|
*/
|
|
190
194
|
|
|
191
195
|
/**
|
|
192
|
-
* Time Complexity: O(n)
|
|
196
|
+
* Time Complexity: O(n)
|
|
193
197
|
* Space Complexity: O(1)
|
|
194
198
|
*
|
|
195
199
|
* Use a comparison function to check whether a binary heap contains a specific element.
|
|
@@ -201,12 +205,13 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
/**
|
|
204
|
-
* Time Complexity: O(n)
|
|
208
|
+
* Time Complexity: O(n)
|
|
205
209
|
* Space Complexity: O(1)
|
|
210
|
+
* The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
|
|
206
211
|
*/
|
|
207
212
|
|
|
208
213
|
/**
|
|
209
|
-
* Time Complexity: O(n)
|
|
214
|
+
* Time Complexity: O(n)
|
|
210
215
|
* Space Complexity: O(1)
|
|
211
216
|
*
|
|
212
217
|
* The `delete` function removes an element from an array-like data structure, maintaining the order
|
|
@@ -232,13 +237,14 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
232
237
|
}
|
|
233
238
|
|
|
234
239
|
/**
|
|
235
|
-
* Time Complexity: O(n)
|
|
236
|
-
* Space Complexity: O(
|
|
240
|
+
* Time Complexity: O(n)
|
|
241
|
+
* Space Complexity: O(log n)
|
|
242
|
+
* where log n is the height of the heap.
|
|
237
243
|
*/
|
|
238
244
|
|
|
239
245
|
/**
|
|
240
|
-
* Time Complexity: O(n)
|
|
241
|
-
* Space Complexity: O(
|
|
246
|
+
* Time Complexity: O(n)
|
|
247
|
+
* Space Complexity: O(log n)
|
|
242
248
|
*
|
|
243
249
|
* Depth-first search (DFS) method, different traversal orders can be selected。
|
|
244
250
|
* @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
|
|
@@ -330,13 +336,13 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
330
336
|
}
|
|
331
337
|
|
|
332
338
|
/**
|
|
333
|
-
* Time Complexity: O(log n)
|
|
334
|
-
* Space Complexity: O(
|
|
339
|
+
* Time Complexity: O(n log n)
|
|
340
|
+
* Space Complexity: O(n)
|
|
335
341
|
*/
|
|
336
342
|
|
|
337
343
|
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
339
|
-
* Space Complexity: O(
|
|
344
|
+
* Time Complexity: O(n log n)
|
|
345
|
+
* Space Complexity: O(n)
|
|
340
346
|
*
|
|
341
347
|
* Fix the entire heap to maintain heap properties.
|
|
342
348
|
*/
|
|
@@ -424,7 +430,7 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
424
430
|
}
|
|
425
431
|
|
|
426
432
|
/**
|
|
427
|
-
* Time Complexity: O(n)
|
|
433
|
+
* Time Complexity: O(log n)
|
|
428
434
|
* Space Complexity: O(1)
|
|
429
435
|
*/
|
|
430
436
|
|
|
@@ -448,6 +454,11 @@ export class Heap<E = any> extends IterableElementBase<E> {
|
|
|
448
454
|
return true;
|
|
449
455
|
}
|
|
450
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Time Complexity: O(log n)
|
|
459
|
+
* Space Complexity: O(1)
|
|
460
|
+
*/
|
|
461
|
+
|
|
451
462
|
/**
|
|
452
463
|
* Time Complexity: O(log n)
|
|
453
464
|
* Space Complexity: O(1)
|
|
@@ -683,12 +694,12 @@ export class FibonacciHeap<E> {
|
|
|
683
694
|
}
|
|
684
695
|
|
|
685
696
|
/**
|
|
686
|
-
* Time Complexity: O(log n)
|
|
697
|
+
* Time Complexity: O(log n)
|
|
687
698
|
* Space Complexity: O(1)
|
|
688
699
|
*/
|
|
689
700
|
|
|
690
701
|
/**
|
|
691
|
-
* Time Complexity: O(log n)
|
|
702
|
+
* Time Complexity: O(log n)
|
|
692
703
|
* Space Complexity: O(1)
|
|
693
704
|
*
|
|
694
705
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -699,12 +710,12 @@ export class FibonacciHeap<E> {
|
|
|
699
710
|
}
|
|
700
711
|
|
|
701
712
|
/**
|
|
702
|
-
* Time Complexity: O(log n)
|
|
713
|
+
* Time Complexity: O(log n)
|
|
703
714
|
* Space Complexity: O(1)
|
|
704
715
|
*/
|
|
705
716
|
|
|
706
717
|
/**
|
|
707
|
-
* Time Complexity: O(log n)
|
|
718
|
+
* Time Complexity: O(log n)
|
|
708
719
|
* Space Complexity: O(1)
|
|
709
720
|
*
|
|
710
721
|
* Remove and return the top element (smallest or largest element) from the heap.
|
|
@@ -9,19 +9,75 @@ import type { ElementCallback } from '../../types';
|
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
|
|
11
11
|
export class DoublyLinkedListNode<E = any> {
|
|
12
|
-
value: E;
|
|
13
|
-
next: DoublyLinkedListNode<E> | undefined;
|
|
14
|
-
prev: DoublyLinkedListNode<E> | undefined;
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* The constructor function initializes the value, next, and previous properties of an object.
|
|
18
14
|
* @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
|
|
19
15
|
* is defined as a generic type "E".
|
|
20
16
|
*/
|
|
21
17
|
constructor(value: E) {
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
18
|
+
this._value = value;
|
|
19
|
+
this._next = undefined;
|
|
20
|
+
this._prev = undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
protected _value: E;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The function returns the value of a protected variable.
|
|
27
|
+
* @returns The value of the variable `_value` is being returned.
|
|
28
|
+
*/
|
|
29
|
+
get value(): E {
|
|
30
|
+
return this._value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The above function sets the value of a variable.
|
|
35
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
36
|
+
*/
|
|
37
|
+
set value(value: E) {
|
|
38
|
+
this._value = value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected _next: DoublyLinkedListNode<E> | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The "next" function returns the next node in a doubly linked list.
|
|
45
|
+
* @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
|
|
46
|
+
* object or `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
get next(): DoublyLinkedListNode<E> | undefined {
|
|
49
|
+
return this._next;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The "next" property of a DoublyLinkedListNode is set to the provided value.
|
|
54
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
55
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
56
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
57
|
+
*/
|
|
58
|
+
set next(value: DoublyLinkedListNode<E> | undefined) {
|
|
59
|
+
this._next = value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected _prev: DoublyLinkedListNode<E> | undefined;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The `prev` function returns the previous node in a doubly linked list.
|
|
66
|
+
* @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
|
|
67
|
+
* be a `DoublyLinkedListNode` object or `undefined`.
|
|
68
|
+
*/
|
|
69
|
+
get prev(): DoublyLinkedListNode<E> | undefined {
|
|
70
|
+
return this._prev;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The function sets the previous node of a doubly linked list node.
|
|
75
|
+
* @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
76
|
+
* `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
77
|
+
* `DoublyLinkedListNode` object or `undefined` as its value.
|
|
78
|
+
*/
|
|
79
|
+
set prev(value: DoublyLinkedListNode<E> | undefined) {
|
|
80
|
+
this._prev = value;
|
|
25
81
|
}
|
|
26
82
|
}
|
|
27
83
|
|
|
@@ -82,13 +138,13 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
82
138
|
}
|
|
83
139
|
|
|
84
140
|
/**
|
|
85
|
-
* Time Complexity: O(
|
|
86
|
-
* Space Complexity: O(
|
|
141
|
+
* Time Complexity: O(1)
|
|
142
|
+
* Space Complexity: O(1)
|
|
87
143
|
* where n is the number of elements in the linked list.
|
|
88
144
|
*/
|
|
89
145
|
|
|
90
146
|
/**
|
|
91
|
-
* Time Complexity: O(
|
|
147
|
+
* Time Complexity: O(1)
|
|
92
148
|
* Space Complexity: O(1)
|
|
93
149
|
*
|
|
94
150
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -104,7 +160,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
104
160
|
*/
|
|
105
161
|
|
|
106
162
|
/**
|
|
107
|
-
* Time Complexity: O(
|
|
163
|
+
* Time Complexity: O(1)
|
|
108
164
|
* Space Complexity: O(1)
|
|
109
165
|
*
|
|
110
166
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -115,12 +171,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
115
171
|
}
|
|
116
172
|
|
|
117
173
|
/**
|
|
118
|
-
* Time Complexity: O(
|
|
119
|
-
* Space Complexity: O(
|
|
174
|
+
* Time Complexity: O(n)
|
|
175
|
+
* Space Complexity: O(n)
|
|
120
176
|
*/
|
|
121
177
|
|
|
122
178
|
/**
|
|
123
|
-
* Time Complexity: O(n)
|
|
179
|
+
* Time Complexity: O(n)
|
|
124
180
|
* Space Complexity: O(n)
|
|
125
181
|
*
|
|
126
182
|
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
@@ -186,7 +242,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
186
242
|
}
|
|
187
243
|
|
|
188
244
|
/**
|
|
189
|
-
* Time Complexity: O(
|
|
245
|
+
* Time Complexity: O(1)
|
|
190
246
|
* Space Complexity: O(1)
|
|
191
247
|
*/
|
|
192
248
|
|
|
@@ -213,7 +269,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
213
269
|
}
|
|
214
270
|
|
|
215
271
|
/**
|
|
216
|
-
* Time Complexity: O(
|
|
272
|
+
* Time Complexity: O(1)
|
|
217
273
|
* Space Complexity: O(1)
|
|
218
274
|
*/
|
|
219
275
|
|
|
@@ -356,13 +412,13 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
356
412
|
}
|
|
357
413
|
|
|
358
414
|
/**
|
|
359
|
-
* Time Complexity: O(n)
|
|
415
|
+
* Time Complexity: O(1) or O(n)
|
|
360
416
|
* Space Complexity: O(1)
|
|
361
417
|
* where n is the number of elements in the linked list.
|
|
362
418
|
*/
|
|
363
419
|
|
|
364
420
|
/**
|
|
365
|
-
* Time Complexity: O(n)
|
|
421
|
+
* Time Complexity: O(1) or O(n)
|
|
366
422
|
* Space Complexity: O(1)
|
|
367
423
|
*
|
|
368
424
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -402,12 +458,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
402
458
|
}
|
|
403
459
|
|
|
404
460
|
/**
|
|
405
|
-
* Time Complexity: O(n)
|
|
461
|
+
* Time Complexity: O(1) or O(n)
|
|
406
462
|
* Space Complexity: O(1)
|
|
407
463
|
*/
|
|
408
464
|
|
|
409
465
|
/**
|
|
410
|
-
* Time Complexity: O(n)
|
|
466
|
+
* Time Complexity: O(1) or O(n)
|
|
411
467
|
* Space Complexity: O(1)
|
|
412
468
|
*
|
|
413
469
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -476,7 +532,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
476
532
|
}
|
|
477
533
|
|
|
478
534
|
/**
|
|
479
|
-
* Time Complexity: O(n)
|
|
535
|
+
* Time Complexity: O(1) or O(n)
|
|
536
|
+
* Space Complexity: O(1)
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Time Complexity: O(1) or O(n)
|
|
480
541
|
* Space Complexity: O(1)
|
|
481
542
|
*
|
|
482
543
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -517,6 +578,9 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
517
578
|
*/
|
|
518
579
|
|
|
519
580
|
/**
|
|
581
|
+
* Time Complexity: O(1)
|
|
582
|
+
* Space Complexity: O(1)
|
|
583
|
+
*
|
|
520
584
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
521
585
|
* @returns A boolean value is being returned.
|
|
522
586
|
*/
|
|
@@ -530,6 +594,9 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
530
594
|
*/
|
|
531
595
|
|
|
532
596
|
/**
|
|
597
|
+
* Time Complexity: O(1)
|
|
598
|
+
* Space Complexity: O(1)
|
|
599
|
+
*
|
|
533
600
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
534
601
|
*/
|
|
535
602
|
clear(): void {
|
|
@@ -568,7 +635,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
568
635
|
|
|
569
636
|
/**
|
|
570
637
|
* Time Complexity: O(n)
|
|
571
|
-
* Space Complexity: O(
|
|
638
|
+
* Space Complexity: O(1)
|
|
572
639
|
*/
|
|
573
640
|
|
|
574
641
|
/**
|
|
@@ -595,7 +662,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
595
662
|
|
|
596
663
|
/**
|
|
597
664
|
* Time Complexity: O(n)
|
|
598
|
-
* Space Complexity: O(
|
|
665
|
+
* Space Complexity: O(1)
|
|
599
666
|
*/
|
|
600
667
|
|
|
601
668
|
/**
|
|
@@ -678,8 +745,8 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
678
745
|
}
|
|
679
746
|
|
|
680
747
|
/**
|
|
681
|
-
* Time Complexity: O(
|
|
682
|
-
* Space Complexity: O(
|
|
748
|
+
* Time Complexity: O(n)
|
|
749
|
+
* Space Complexity: O(n)
|
|
683
750
|
*/
|
|
684
751
|
|
|
685
752
|
/**
|
|
@@ -712,8 +779,8 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
712
779
|
}
|
|
713
780
|
|
|
714
781
|
/**
|
|
715
|
-
* Time Complexity: O(
|
|
716
|
-
* Space Complexity: O(
|
|
782
|
+
* Time Complexity: O(n)
|
|
783
|
+
* Space Complexity: O(n)
|
|
717
784
|
*/
|
|
718
785
|
|
|
719
786
|
/**
|
|
@@ -778,7 +845,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
778
845
|
}
|
|
779
846
|
|
|
780
847
|
/**
|
|
781
|
-
* Time Complexity: O(
|
|
848
|
+
* Time Complexity: O(1)
|
|
782
849
|
* Space Complexity: O(1)
|
|
783
850
|
*/
|
|
784
851
|
|
|
@@ -795,7 +862,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
795
862
|
}
|
|
796
863
|
|
|
797
864
|
/**
|
|
798
|
-
* Time Complexity: O(
|
|
865
|
+
* Time Complexity: O(1)
|
|
799
866
|
* Space Complexity: O(1)
|
|
800
867
|
*/
|
|
801
868
|
|
|
@@ -9,17 +9,53 @@ import type { ElementCallback } from '../../types';
|
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
|
|
11
11
|
export class SinglyLinkedListNode<E = any> {
|
|
12
|
-
value: E;
|
|
13
|
-
next: SinglyLinkedListNode<E> | undefined;
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
17
14
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
18
15
|
* will be stored in the node of a linked list.
|
|
19
16
|
*/
|
|
20
17
|
constructor(value: E) {
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
18
|
+
this._value = value;
|
|
19
|
+
this._next = undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected _value: E;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The function returns the value of a protected variable.
|
|
26
|
+
* @returns The value of the variable `_value` is being returned.
|
|
27
|
+
*/
|
|
28
|
+
get value(): E {
|
|
29
|
+
return this._value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The above function sets the value of a variable.
|
|
34
|
+
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
35
|
+
*/
|
|
36
|
+
set value(value: E) {
|
|
37
|
+
this._value = value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected _next: SinglyLinkedListNode<E> | undefined;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The `next` function returns the next node in a singly linked list.
|
|
44
|
+
* @returns The `next` property is being returned. It can be either a `SinglyLinkedListNode<E>`
|
|
45
|
+
* object or `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
get next(): SinglyLinkedListNode<E> | undefined {
|
|
48
|
+
return this._next;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The "next" property of a SinglyLinkedListNode is set to the provided value.
|
|
53
|
+
* @param {SinglyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
54
|
+
* `SinglyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
55
|
+
* `SinglyLinkedListNode` object or `undefined` as its value.
|
|
56
|
+
*/
|
|
57
|
+
set next(value: SinglyLinkedListNode<E> | undefined) {
|
|
58
|
+
this._next = value;
|
|
23
59
|
}
|
|
24
60
|
}
|
|
25
61
|
|
|
@@ -728,7 +764,7 @@ export class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
728
764
|
}
|
|
729
765
|
|
|
730
766
|
/**
|
|
731
|
-
* Time Complexity: O(n)
|
|
767
|
+
* Time Complexity: O(n)
|
|
732
768
|
* Space Complexity: O(n)
|
|
733
769
|
*/
|
|
734
770
|
/**
|
|
@@ -53,7 +53,7 @@ export class SkipList<K, V> {
|
|
|
53
53
|
protected _level: number = 0;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* The function returns the value of the
|
|
56
|
+
* The function returns the value of the protected variable _level.
|
|
57
57
|
* @returns The level property of the object.
|
|
58
58
|
*/
|
|
59
59
|
get level(): number {
|
|
@@ -74,7 +74,7 @@ export class SkipList<K, V> {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* The function returns the probability value.
|
|
77
|
-
* @returns The probability value stored in the
|
|
77
|
+
* @returns The probability value stored in the protected variable `_probability` is being returned.
|
|
78
78
|
*/
|
|
79
79
|
get probability(): number {
|
|
80
80
|
return this._probability;
|
|
@@ -53,7 +53,7 @@ export class Matrix {
|
|
|
53
53
|
protected _cols: number = 0;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* The function returns the value of the
|
|
56
|
+
* The function returns the value of the protected variable _cols.
|
|
57
57
|
* @returns The number of columns.
|
|
58
58
|
*/
|
|
59
59
|
get cols(): number {
|
|
@@ -9,6 +9,16 @@ import type { PriorityQueueOptions } from '../../types';
|
|
|
9
9
|
import { PriorityQueue } from './priority-queue';
|
|
10
10
|
|
|
11
11
|
export class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor initializes a PriorityQueue with optional elements and options, including a
|
|
14
|
+
* comparator function.
|
|
15
|
+
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
16
|
+
* elements to be added to the priority queue. It is optional and defaults to an empty array if not
|
|
17
|
+
* provided.
|
|
18
|
+
* @param options - The `options` parameter is an object that contains additional configuration
|
|
19
|
+
* options for the priority queue. In this case, it has a property called `comparator` which is a
|
|
20
|
+
* function used to compare elements in the priority queue.
|
|
21
|
+
*/
|
|
12
22
|
constructor(
|
|
13
23
|
elements: Iterable<E> = [],
|
|
14
24
|
options: PriorityQueueOptions<E> = {
|
|
@@ -9,6 +9,17 @@ import type { PriorityQueueOptions } from '../../types';
|
|
|
9
9
|
import { PriorityQueue } from './priority-queue';
|
|
10
10
|
|
|
11
11
|
export class MinPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor initializes a PriorityQueue with optional elements and options, including a
|
|
14
|
+
* comparator function.
|
|
15
|
+
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
16
|
+
* elements to be added to the priority queue. It is optional and defaults to an empty array if not
|
|
17
|
+
* provided.
|
|
18
|
+
* @param options - The `options` parameter is an object that contains additional configuration
|
|
19
|
+
* options for the priority queue. In this case, it has a property called `comparator` which is a
|
|
20
|
+
* function used to compare elements in the priority queue. The `comparator` function takes two
|
|
21
|
+
* parameters `a` and `b`,
|
|
22
|
+
*/
|
|
12
23
|
constructor(
|
|
13
24
|
elements: Iterable<E> = [],
|
|
14
25
|
options: PriorityQueueOptions<E> = {
|
|
@@ -17,6 +17,14 @@ import { Heap } from '../heap';
|
|
|
17
17
|
* 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
|
|
18
18
|
*/
|
|
19
19
|
export class PriorityQueue<E = any> extends Heap<E> {
|
|
20
|
+
/**
|
|
21
|
+
* The constructor initializes a priority queue with optional elements and options.
|
|
22
|
+
* @param elements - The `elements` parameter is an iterable object that contains the initial
|
|
23
|
+
* elements to be added to the priority queue. It is an optional parameter and if not provided, the
|
|
24
|
+
* priority queue will be initialized as empty.
|
|
25
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
26
|
+
* behavior of the priority queue. It can contain the following properties:
|
|
27
|
+
*/
|
|
20
28
|
constructor(elements: Iterable<E> = [], options?: PriorityQueueOptions<E>) {
|
|
21
29
|
super(elements, options);
|
|
22
30
|
}
|