@@ -32,6 +32,8 @@ Binary Search Tree & AVL Tree (Self Balancing Tree) implementation in javascript
32
32
* [ .find(key)] ( #findkey )
33
33
* [ .min()] ( #min )
34
34
* [ .max()] ( #max )
35
+ * [ .lowerBound(k)] ( #lowerboundk )
36
+ * [ .upperBound(k)] ( #upperboundk )
35
37
* [ .root()] ( #root )
36
38
* [ .count()] ( #count )
37
39
* [ .traverseInOrder(cb)] ( #traverseinordercb )
@@ -202,6 +204,49 @@ const max = bst.max();
202
204
console .log (max .getKey ()); // 90
203
205
console .log (max .getValue ()); // v4
204
206
```
207
+
208
+ ### .lowerBound(k)
209
+ finds the node with the biggest key less or equal a given value k.
210
+
211
+ <table >
212
+ <tr >
213
+ <th align="center">params</th>
214
+ <th align="center">return</th>
215
+ <th align="center">runtime</th>
216
+ </tr >
217
+ <tr >
218
+ <td>k: number | string</td>
219
+ <td align="center"><a href="#binarysearchtreenode">BinarySearchTreeNode</a> | <a href="#avltreenode">AvlTreeNode</a></td>
220
+ <td align="center">O(log(n))</td>
221
+ </tr >
222
+ </table >
223
+
224
+ ``` js
225
+ console .log (bst .lowerBound (60 ).getKey ()); // 50
226
+ console .log (bst .lowerBound (10 )); // null
227
+ ```
228
+
229
+ ### .upperBound(k)
230
+ finds the node with the smallest key bigger than a given value k.
231
+
232
+ <table >
233
+ <tr >
234
+ <th align="center">params</th>
235
+ <th align="center">return</th>
236
+ <th align="center">runtime</th>
237
+ </tr >
238
+ <tr >
239
+ <td>k: number | string</td>
240
+ <td align="center"><a href="#binarysearchtreenode">BinarySearchTreeNode</a> | <a href="#avltreenode">AvlTreeNode</a></td>
241
+ <td align="center">O(log(n))</td>
242
+ </tr >
243
+ </table >
244
+
245
+ ``` js
246
+ console .log (bst .upperBound (75 ).getKey ()); // 80
247
+ console .log (bst .upperBound (110 )); // null
248
+ ```
249
+
205
250
### .root()
206
251
returns the root node of the tree.
207
252
0 commit comments