data-structure-typed 1.42.8 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +18 -18
- 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 +415 -236
- 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 +415 -236
- 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 +465 -256
- 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/avl-tree.test.ts +2 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +73 -5
- 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
|
@@ -32,38 +32,61 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
32
32
|
*/
|
|
33
33
|
createNode(key: BTNKey, value?: V): N;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
35
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
36
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
40
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
41
|
+
*
|
|
42
|
+
* The function overrides the add method of a class, adds a key-value pair to a data structure, and
|
|
43
|
+
* balances the structure if necessary.
|
|
44
|
+
* @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
|
|
45
|
+
* `BTNKey`, `N`, `null`, or `undefined`.
|
|
46
|
+
* @param {V} [value] - The `value` parameter is the value associated with the key that is being
|
|
47
|
+
* added to the binary search tree.
|
|
48
|
+
* @returns The method is returning either a node (N) or undefined.
|
|
42
49
|
*/
|
|
43
50
|
add(keyOrNode: BTNKey | N | null | undefined, value?: V): N | undefined;
|
|
44
51
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
52
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
53
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
57
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
58
|
+
*
|
|
59
|
+
* The function overrides the delete method of a binary tree, performs the deletion, and then
|
|
60
|
+
* balances the tree if necessary.
|
|
61
|
+
* @param identifier - The `identifier` parameter is the value or condition used to identify the
|
|
62
|
+
* node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
|
|
63
|
+
* `callback` function.
|
|
64
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
65
|
+
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
66
|
+
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
67
|
+
* parameter of type `N
|
|
68
|
+
* @returns The method is returning an array of `BiTreeDeleteResult<N>`.
|
|
55
69
|
*/
|
|
56
70
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
|
|
57
71
|
/**
|
|
58
|
-
* The function swaps the key, value, and height properties between two nodes in a binary
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
72
|
+
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
73
|
+
* tree.
|
|
74
|
+
* @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
75
|
+
* needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
|
|
76
|
+
* @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
77
|
+
* node where the values from the source node will be swapped to.
|
|
78
|
+
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
79
|
+
* if either `srcNode` or `destNode` is undefined.
|
|
64
80
|
*/
|
|
65
81
|
protected _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined;
|
|
66
82
|
/**
|
|
83
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
84
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
88
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
89
|
+
*
|
|
67
90
|
* The function calculates the balance factor of a node in a binary tree.
|
|
68
91
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
69
92
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
@@ -71,12 +94,26 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
71
94
|
*/
|
|
72
95
|
protected _balanceFactor(node: N): number;
|
|
73
96
|
/**
|
|
97
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
98
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
102
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
103
|
+
*
|
|
74
104
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
75
105
|
* right children.
|
|
76
106
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
77
107
|
*/
|
|
78
108
|
protected _updateHeight(node: N): void;
|
|
79
109
|
/**
|
|
110
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
111
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
115
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
116
|
+
*
|
|
80
117
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
81
118
|
* to restore balance in an AVL tree after inserting a node.
|
|
82
119
|
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
@@ -84,21 +121,49 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
84
121
|
*/
|
|
85
122
|
protected _balancePath(node: N): void;
|
|
86
123
|
/**
|
|
124
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
125
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
129
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
130
|
+
*
|
|
87
131
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
88
132
|
* @param {N} A - A is a node in a binary tree.
|
|
89
133
|
*/
|
|
90
134
|
protected _balanceLL(A: N): void;
|
|
91
135
|
/**
|
|
136
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
137
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
141
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
142
|
+
*
|
|
92
143
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
93
144
|
* @param {N} A - A is a node in a binary tree.
|
|
94
145
|
*/
|
|
95
146
|
protected _balanceLR(A: N): void;
|
|
96
147
|
/**
|
|
148
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
149
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
153
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
154
|
+
*
|
|
97
155
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
98
156
|
* @param {N} A - A is a node in a binary tree.
|
|
99
157
|
*/
|
|
100
158
|
protected _balanceRR(A: N): void;
|
|
101
159
|
/**
|
|
160
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
161
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
165
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
166
|
+
*
|
|
102
167
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
103
168
|
* @param {N} A - A is a node in a binary tree.
|
|
104
169
|
*/
|
|
@@ -40,13 +40,20 @@ class AVLTree extends bst_1.BST {
|
|
|
40
40
|
return new AVLTreeNode(key, value);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
43
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
44
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
48
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
49
|
+
*
|
|
50
|
+
* The function overrides the add method of a class, adds a key-value pair to a data structure, and
|
|
51
|
+
* balances the structure if necessary.
|
|
52
|
+
* @param {BTNKey | N | null | undefined} keyOrNode - The `keyOrNode` parameter can be of type
|
|
53
|
+
* `BTNKey`, `N`, `null`, or `undefined`.
|
|
54
|
+
* @param {V} [value] - The `value` parameter is the value associated with the key that is being
|
|
55
|
+
* added to the binary search tree.
|
|
56
|
+
* @returns The method is returning either a node (N) or undefined.
|
|
50
57
|
*/
|
|
51
58
|
add(keyOrNode, value) {
|
|
52
59
|
if (keyOrNode === null)
|
|
@@ -57,16 +64,23 @@ class AVLTree extends bst_1.BST {
|
|
|
57
64
|
return inserted;
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
67
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
68
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
|
|
72
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
73
|
+
*
|
|
74
|
+
* The function overrides the delete method of a binary tree, performs the deletion, and then
|
|
75
|
+
* balances the tree if necessary.
|
|
76
|
+
* @param identifier - The `identifier` parameter is the value or condition used to identify the
|
|
77
|
+
* node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
|
|
78
|
+
* `callback` function.
|
|
79
|
+
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
80
|
+
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
81
|
+
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
82
|
+
* parameter of type `N
|
|
83
|
+
* @returns The method is returning an array of `BiTreeDeleteResult<N>`.
|
|
70
84
|
*/
|
|
71
85
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
72
86
|
if (identifier instanceof AVLTreeNode)
|
|
@@ -80,12 +94,14 @@ class AVLTree extends bst_1.BST {
|
|
|
80
94
|
return deletedResults;
|
|
81
95
|
}
|
|
82
96
|
/**
|
|
83
|
-
* The function swaps the key, value, and height properties between two nodes in a binary
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
97
|
+
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
98
|
+
* tree.
|
|
99
|
+
* @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
100
|
+
* needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
|
|
101
|
+
* @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
102
|
+
* node where the values from the source node will be swapped to.
|
|
103
|
+
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
104
|
+
* if either `srcNode` or `destNode` is undefined.
|
|
89
105
|
*/
|
|
90
106
|
_swap(srcNode, destNode) {
|
|
91
107
|
srcNode = this.ensureNotKey(srcNode);
|
|
@@ -107,6 +123,13 @@ class AVLTree extends bst_1.BST {
|
|
|
107
123
|
return undefined;
|
|
108
124
|
}
|
|
109
125
|
/**
|
|
126
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
127
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
131
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
132
|
+
*
|
|
110
133
|
* The function calculates the balance factor of a node in a binary tree.
|
|
111
134
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
112
135
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
@@ -123,6 +146,13 @@ class AVLTree extends bst_1.BST {
|
|
|
123
146
|
return node.right.height - node.left.height;
|
|
124
147
|
}
|
|
125
148
|
/**
|
|
149
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
150
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
154
|
+
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
155
|
+
*
|
|
126
156
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
127
157
|
* right children.
|
|
128
158
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
@@ -140,6 +170,13 @@ class AVLTree extends bst_1.BST {
|
|
|
140
170
|
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
141
171
|
}
|
|
142
172
|
/**
|
|
173
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
174
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
|
|
178
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
179
|
+
*
|
|
143
180
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
144
181
|
* to restore balance in an AVL tree after inserting a node.
|
|
145
182
|
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
@@ -185,6 +222,13 @@ class AVLTree extends bst_1.BST {
|
|
|
185
222
|
}
|
|
186
223
|
}
|
|
187
224
|
/**
|
|
225
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
226
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
227
|
+
*/
|
|
228
|
+
/**
|
|
229
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
230
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
231
|
+
*
|
|
188
232
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
189
233
|
* @param {N} A - A is a node in a binary tree.
|
|
190
234
|
*/
|
|
@@ -219,6 +263,13 @@ class AVLTree extends bst_1.BST {
|
|
|
219
263
|
this._updateHeight(B);
|
|
220
264
|
}
|
|
221
265
|
/**
|
|
266
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
267
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
268
|
+
*/
|
|
269
|
+
/**
|
|
270
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
271
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
272
|
+
*
|
|
222
273
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
223
274
|
* @param {N} A - A is a node in a binary tree.
|
|
224
275
|
*/
|
|
@@ -268,6 +319,13 @@ class AVLTree extends bst_1.BST {
|
|
|
268
319
|
C && this._updateHeight(C);
|
|
269
320
|
}
|
|
270
321
|
/**
|
|
322
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
323
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
327
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
328
|
+
*
|
|
271
329
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
272
330
|
* @param {N} A - A is a node in a binary tree.
|
|
273
331
|
*/
|
|
@@ -303,6 +361,13 @@ class AVLTree extends bst_1.BST {
|
|
|
303
361
|
B && this._updateHeight(B);
|
|
304
362
|
}
|
|
305
363
|
/**
|
|
364
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
365
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
366
|
+
*/
|
|
367
|
+
/**
|
|
368
|
+
* Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
|
|
369
|
+
* Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
|
|
370
|
+
*
|
|
306
371
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
307
372
|
* @param {N} A - A is a node in a binary tree.
|
|
308
373
|
*/
|