{"id":26711650,"url":"https://github.com/rfieve/binary-search-tree","last_synced_at":"2025-03-27T10:29:59.230Z","repository":{"id":190002360,"uuid":"681580798","full_name":"rfieve/binary-search-tree","owner":"rfieve","description":"A zero-dependency TypeScript library to work with binary search trees and arrays of any types, with a functional-programming and immutable approach.","archived":false,"fork":false,"pushed_at":"2024-07-24T10:03:07.000Z","size":652,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T06:09:19.401Z","etag":null,"topics":["array","binary-search-tree","data-structures","typescript","utility-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rfieve.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-08-22T10:14:09.000Z","updated_at":"2024-11-06T08:35:59.000Z","dependencies_parsed_at":"2023-09-22T18:29:06.087Z","dependency_job_id":"d69c820d-a5c3-4583-8abc-6a66056c40d1","html_url":"https://github.com/rfieve/binary-search-tree","commit_stats":null,"previous_names":["rfieve/binary-tree","rfieve/binary-search-tree"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfieve%2Fbinary-search-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfieve%2Fbinary-search-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfieve%2Fbinary-search-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfieve%2Fbinary-search-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rfieve","download_url":"https://codeload.github.com/rfieve/binary-search-tree/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245826522,"owners_count":20678806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","binary-search-tree","data-structures","typescript","utility-library"],"created_at":"2025-03-27T10:29:58.760Z","updated_at":"2025-03-27T10:29:59.224Z","avatar_url":"https://github.com/rfieve.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ✌️🔍🌳 binary-search-tree\n\nA zero-dependency TypeScript library to work with binary search trees and arrays of any types, with a functional-programming and immutable approach.\n\n## Table of Content\n\n-   [✌️🔍🌳 binary-search-tree](#️-binary-search-tree)\n    -   [Table of Content](#table-of-content)\n    -   [Installation](#installation)\n    -   [Usage](#usage)\n    -   [Documentation](#documentation)\n        -   [`toBST`](#tobst)\n        -   [`balance`, `isBalanced`, `getBalance`](#balance-isbalanced-getbalance)\n        -   [`add`](#add)\n        -   [`remove`](#remove)\n        -   [`find`, `findFromPath`](#find-findfrompath)\n        -   [`findLowestAncestor`](#findlowestancestor)\n        -   [`find(Gt/Gte/Lt/Lte)`](#findgtgteltlte)\n        -   [`find(Min/Max)(Height)`, `count`](#findminmaxheight-count)\n        -   [`getDistanceBetweenNodes`](#getdistancebetweennodes)\n        -   [`traverse`](#traverse)\n        -   [`toArray`](#toarray)\n        -   [`isLeaf`, `isBranch`](#isleaf-isbranch)\n        -   [`hasLeft`, `hasRight`](#hasleft-hasright)\n        -   [`makeCompareUtils`](#makecompareutils)\n        -   [The infamous `BinarySearchTree` class](#the-infamous-binarysearchtree-class)\n\n## Installation\n\n```sh\nyarn add @romainfieve/binary-search-tree\n```\n\nor\n\n```sh\nnpm install @romainfieve/binary-search-tree\n```\n\n## Usage\n\n```typescript\ntype Hero = { name: string };\n\nconst compareAlpha = (a: Hero, b: Hero) =\u003e a.name.localeCompare(b.name);\n\nconst addAlpha = makeAdd(compareAlpha);\nconst removeAlpha = makeRemove(compareAlpha);\nconst findAlpha = makeFind(compareAlpha);\n\nconst heroes: Hero[] = [\n    { name: 'Han' },\n    { name: 'Anakin' },\n    { name: 'Leia' },\n    { name: 'Luke' },\n    { name: 'Padme' },\n    { name: 'Lando' },\n    { name: 'Chewie' },\n];\nconst unbalancedTree = toBST(heroes, compareAlpha, { isBalanced: false });\n\nconst updatedTree = pipe(\n    (t) =\u003e addAlpha(t, { name: 'Yoda' }),\n    (t) =\u003e addAlpha(t, { name: 'Obiwan' }),\n    (t) =\u003e addAlpha(t, [{ name: 'Boba' }, { name: 'Grogu' }]),\n    (t) =\u003e removeAlpha(t, [{ name: 'Han' }, { name: 'Padme' }]),\n    (t) =\u003e removeAlpha(t, { name: 'Luke' })\n)(unbalancedTree);\n\n// unbalancedTree:                             | Schema of \"unbalancedTree\"\n//                                             |\n// {                                           |             Han\n//     data: [{ name: 'Han' }],                |           /     \\\n//     left: {                                 |     Anakin       Leia\n//         data: [{ name: 'Anakin' }],         |           \\     /    \\\n//         right: {                            |       Chewie  Lando   Luke\n//             data : [{ name: 'Chewie' }],    |                         \\\n//         },                                  |                        Padme\n//     },                                      |\n//     right: {                                | Schema of \"updatedTree\"\n//         data: [{ name: 'Leia' }],           |\n//         left: {                             |            Lando\n//             data: [{ name: 'Lando' }],      |           /     \\\n//         },                                  |     Anakin       Leia\n//         right: {                            |         \\            \\\n//             data: [{ name: 'Luke' }],       |       Chewie        Obiwan\n//             right: {                        |        /    \\            \\\n//                 data : [{ name: 'Padme' }], |      Boba  Grogu        Yoda\n//             },                              |\n//         },                                  |\n//     },                                      |\n// };                                          |\n\nconst min = findMin(updatedTree).data[0].name; // Anakin\nconst max = findMax(updatedTree).data[0].name; // Yoda\nconst grogu = findAlpha(updatedTree, { name: 'Grogu' }).node.data[0].name; // Grogu\nconst groguPath = findAlpha(updatedTree, { name: 'Grogu' }).path; // ['left', 'right', 'right']\n// Thanks to the compare function, the search will traverse like this:\n// Lando -\u003e Anakin -\u003e Chewie -\u003e Grogu\n```\n\n## Documentation\n\n### `toBST`\n\nConverts the given array to a balanced binary search tree (`toBST`), depending on a given compare function.\n\n\u003e :warning: For obvious performance reasons, `toBST` will create a BALANCED binary search tree by default. Whilst passing the option `{ isBalanced: false }` will indeed respect the order of the source array for insertion, beware that performace will be greatly impacted.\n\u003e Worst, if you pass an array presorted with the compare function, the BST will be linear, and the Big O notation will be `n!`.\n\n```typescript\nconst arr = [10, 32, 13, 2, 89, 5, 50];\nconst compare = (a: number, b: number) =\u003e a - b;\n\nconst tree = toBST(arr, compare);\n// or\nconst unbalancedTree = toBST(arr, compare, { isBalanced: false });\n\n// Schema of \"tree\"         |    \"unbalancedTree\"\n//                          |\n//           13             |          10\n//        /     \\           |       /     \\\n//       5      50          |      2      32\n//     /  \\    /  \\         |       \\    /  \\\n//    2   10  32   89       |        5  13  89\n//                          |               /\n//                          |             50\n```\n\n---\n\n### `balance`, `isBalanced`, `getBalance`\n\nBalances the given binary search tree with the given compare function and returns a new tree, without modifing the original tree in place.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the tree. A safer approach consists of using `makeBalance`. It curries a `balance` closure function with the given compare function.\n\n```typescript\ngetBalance(unbalancedTree); // 2\nisBalanced(unbalancedTree); // false\n\nconst tree = balance(unbalancedTree, compare);\n// or\nconst safeBalance = makeBalance(compare);\nconst tree = safeBalance(unbalancedTree);\n\ngetBalance(tree); // 0\nisBalanced(tree); // true\n\n// Schema of \"unbalancedTree\"  =\u003e        \"tree\"\n//                             |\n//       10                    |            13\n//    /     \\                  |         /     \\\n//   2      32                 |        5      50\n//    \\    /  \\                |      /  \\    /  \\\n//     5  13  89               |     2   10  32   89\n//            /                |\n//          50                 |\n```\n\n---\n\n### `add`\n\nAdds a (or list of) given node(s) to the given binary search tree with the given compare function and returns a new tree, without modifing the original tree in place.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the tree. A safer approach consists of using `makeAdd`. It curries an `add` closure function with the given compare function.\n\n```typescript\nconst modifiedTree = add(tree, compare, 11);\nconst reModifiedTree = add(modifiedTree, compare, [1, 100]);\n//or\nconst safeAdd = makeAdd(compare);\nconst modifiedTree = safeAdd(tree, 11);\nconst reModifiedTree = safeAdd(modifiedTree, [1, 100]);\n\n// Schema of \"tree\"     =\u003e     \"modifiedTree\"      =\u003e   \"reModifiedTree\"\n//                      |                          |\n//       10             |            10            |            10\n//    /     \\           |         /     \\          |         /     \\\n//   2      32          |        2      32         |        2      32\n//    \\    /  \\         |         \\    /  \\        |      /  \\    /  \\\n//     5  13  89        |          5  13  89       |     1    5  13  89\n//            /         |            /   /         |            /   /  \\\n//          50          |           11  50         |           11  50   100\n```\n\n---\n\n### `remove`\n\nRemoves a (or list of) given node(s) from the given binary search tree with the given compare function and returns a new tree, without modifing the original tree in place.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the tree. A safer approach consists of using `makeRemove`. It curries a `remove` closure function with the given compare function.\n\n```typescript\nconst modifiedTree = remove(tree, compare, 10);\nconst reModifiedTree = remove(modifiedTree, compare, [13, 5]);\n// or\nconst safeRemove = makeRemove(compare);\nconst modifiedTree = safeRemove(tree, 10);\nconst reModifiedTree = safeRemove(modifiedTree, [13, 5]);\n\n// Schema of \"tree\"     =\u003e     \"modifiedTree\"      =\u003e   \"reModifiedTree\"\n//                      |                          |\n//       10             |            13            |             32\n//    /     \\           |         /     \\          |          /     \\\n//   2      32          |        2      32         |         2      89\n//    \\    /  \\         |         \\       \\        |                /\n//     5  13  89        |          5      89       |              50\n//            /         |                /         |\n//          50          |              50          |\n```\n\n---\n\n### `find`, `findFromPath`\n\nFinds a given node into the given binary search tree with the given compare function.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the search. A safer approach consists of using `makeFind`. It curries a `find` closure function with the given compare function.\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst result = find(tree, compare, 13); // { node: { data: [13] }, path: ['right', 'left'] }\nconst resultFromPath = findFromPath(tree, compare, ['right', 'left']); // { node: { data: [13] }, path: ['right', 'left'] }\n// or\nconst safeFind = makeFind(compare);\nconst result = safeFind(tree, 13); // { node: { data: [13] }, path: ['right', 'left'] }\n\nconst safeFindFromPath = makeFindFromPath(compare);\nconst resultFromPath = safeFindFromPath(tree, ['right', 'left']); // { node: { data: [13] }, path: ['right', 'left'] }\n```\n\n---\n\n### `findLowestAncestor`\n\nFinds the lowest common ancestor of two given nodes into the given binary search tree with the given compare function.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the search. A safer approach consists of using `makeFindLowestAncestor`. It curries a `findLowestAncestor` closure function with the given compare function.\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst result = findLowestAncestor(tree, compare, 13, 50); // { node: { data: [32], ... }, path: ['right'] }\n// or\nconst safeFind = makeFindLowestAncestor(compare);\nconst result = safeFind(tree, 13, 50); // { node: { data: [32], ... }, path: ['right'] }\n```\n\n---\n\n### `find(Gt/Gte/Lt/Lte)`\n\nFinds all gt/gte/lt/lte nodes into the given binary search tree with the given compare function.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the search. A safer approach consists of using `makeFind(Gt/Gte/Lt/Lte)`. It curries a `find(Gt/Gte/Lt/Lte)` closure function with the given compare function.\n\n-   `findGt`\n-   `findGte`\n-   `findLt`\n-   `findLte`\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst results = findGte(tree, compare, 4).flatMap(({ node, path: _path }) =\u003e node.data[0]);\n// [10, 5, 32, 13, 89, 50]\n// or\nconst safeFindGte = makeFindGte(compare);\nconst results = safeFindGte(tree, 4).flatMap(({ node, path: _path }) =\u003e node.data[0]);\n// [10, 5, 32, 13, 89, 50]\n```\n\n---\n\n### `find(Min/Max)(Height)`, `count`\n\nFinds the min (`findMin`) or the max (`findMax`) node of the tree.\nFinds the height of the min (`findMinHeight`) or the max (`findMaxHeight`) branch of the tree.\nCounts (`count`) the nodes in the tree\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst min = findMin(tree).data[0]; // 2\nconst max = findMax(tree).data[0]; // 89\nconst minHeight = findMinHeight(tree); // 1\nconst maxHeight = findMaxHeight(tree); // 3\nconst length = count(tree); // 7\n```\n\n---\n\n### `getDistanceBetweenNodes`\n\nGets the distance between two given elements into the given binary search tree with the given compare function.\n\n\u003e :warning: Using another compare function than the one used to create the tree with `toBST` will of course f\\*\\*k up the search. A safer approach consists of using `makeGetDistanceBetweenNodes`. It curries a `getDistanceBetweenNodes` closure function with the given compare function.\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst result = getDistanceBetweenNodes(tree, compare, 13, 50); // 3\n// or\nconst safeFind = makeGetDistanceBetweenNodes(compare);\nconst result = safeFind(tree, 13, 50); // 3\n```\n\n---\n\n### `traverse`\n\nTraverses a tree, invoking the callback function on each visited node.\n\n-   (DFS) `traverseInOrder`\n-   (DFS) `traverseInOrderReverse`\n-   (DFS) `traversePreOrder`\n-   (DFS) `traversePreOrderReverse`\n-   (DFS) `traversePostOrder`\n-   (DFS) `traversePostOrderReverse`\n-   (BSF) `traverseLevelOrder`\n-   (BSF) `traverseLevelOrderReverse`\n\n*   DFS: Depth-First Search traversal\n*   BFS: Breadth-First Search traversal\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst collect = (collection: number[]) =\u003e (node: { data: number[] }) =\u003e {\n    node.data.forEach((e) =\u003e collection.push(e));\n};\n\nconst elements = [];\n\ntraverseInOrder(collect(elements), tree);\n// elements: [2, 5, 10, 13, 32, 50, 89]\ntraverseInOrderReverse(collect(elements), tree);\n// elements: [89, 50, 32, 13, 10, 5, 2]\ntraversePreOrder(collect(elements), tree);\n// elements: [10, 2, 5, 32, 13, 89, 50]\ntraversePreOrderReverse(collect(elements), tree);\n// elements: [10, 32, 89, 50, 13, 2, 5]\ntraversePostOrder(collect(elements), tree);\n// elements: [5, 2, 13, 50, 89, 32, 10]\ntraversePostOrderReverse(collect(elements), tree);\n// elements: [50, 89, 13, 32, 5, 2, 10]\ntraverseLevelOrder(collect(elements), tree);\n// elements: [10, 2, 32, 5, 13, 89, 50]\ntraverseLevelOrderReverse(collect(elements), tree);\n// elements: [10, 32, 2, 89, 13, 5, 50]\n```\n\n---\n\n### `toArray`\n\nConverts the given binary search tree to an array sorted as traversed:\n\n-   (DFS) `toArrayInOrder`\n-   (DFS) `toArrayInOrderReverse`\n-   (DFS) `toArrayPreOrder`\n-   (DFS) `toArrayPreOrderReverse`\n-   (DFS) `toArrayPostOrder`\n-   (DFS) `toArrayPostOrderReverse`\n-   (BFS) `toArrayLevelOrder`\n-   (BFS) `toArrayLevelOrderReverse`\n\n*   DFS: Depth-First Search traversal\n*   BFS: Breadth-First Search traversal\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst a = toArrayInOrder(tree);\n// [2, 5, 10, 13, 32, 50, 89]\nconst b = toArrayInOrderReverse(tree);\n// [89, 50, 32, 13, 10, 5, 2]\nconst c = toArrayPreOrder(tree);\n// [10, 2, 5, 32, 13, 89, 50]\nconst d = toArrayPreOrderReverse(tree);\n// [10, 32, 89, 50, 13, 2, 5]\nconst e = toArrayPostOrder(tree);\n// [5, 2, 13, 50, 89, 32, 10]\nconst f = toArrayPostOrderReverse(tree);\n// [50, 89, 13, 32, 5, 2, 10]\nconst g = toArrayLevelOrder(tree);\n// [10, 2, 32, 5, 13, 89, 50]\nconst h = toArrayLevelOrderReverse(tree);\n// [10, 32, 2, 89, 13, 5, 50]\n```\n\n---\n\n### `isLeaf`, `isBranch`\n\nAssesses if the given tree/node is a leaf (has no left nor right prop) (`isLeaf`) or a branch (has a left or a right prop or both) (`isBranch`).\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst isLeafA = isLeaf(tree.left.left); // true\nconst isLeafB = isLeaf(tree); // false\n\nconst isBranchA = isBranch(tree); // true\nconst isBranchB = isBranch(tree.left.left); // false\n```\n\n---\n\n### `hasLeft`, `hasRight`\n\nAssesses if the given tree/node has a left branch (has a left prop) (`hasLeft`) or a right branch (has a right prop) (`hasRight`).\n\n```typescript\n// Schema of \"tree\"\n//\n//       10\n//    /     \\\n//   2      32\n//    \\    /  \\\n//     5  13  89\n//           /\n//         50\n\nconst hasLeftA = hasLeft(tree); // true\nconst hasLeftB = hasLeft(tree.left); // false\n\nconst hasRightA = hasRight(tree); // true\nconst hasRightB = hasRight(tree.left.left); // false\n```\n\n---\n\n### `makeCompareUtils`\n\nAs the compare function is centric, for both the creation and the traversals of the BTS, a good practice is to create all the necessary utils, along with it. This will be DRY and ensure reusability and consistency.\n\n```typescript\n// compare-alpha.ts\nexport const compareAlpha = (a: Hero, b: Hero) =\u003e a.name.localeCompare(b.name);\nexport const {\n    toBST: toBSTAlpha,\n    add: addAlpha,\n    remove: removeAlpha,\n    find: findAlpha,\n    findLowestAncestor: findLowestAncestorAlpha,\n    findGt: findGtAlpha,\n    findGte: findGteAlpha,\n    findLt: findLtAlpha,\n    findLte: findLteAlpha,\n    balance: balanceAlpha,\n    getDistanceBetweenNodes: getDistanceBetweenNodesAlpha,\n} = makeCompareUtils(compareAlpha);\n\n// other-file.ts\nimport {\n    compareAlpha,\n    toBSTAlpha,\n    addAlpha,\n    removeAlpha,\n    findAlpha,\n    findLowestAncestorAlpha,\n    findGtAlpha,\n    findGteAlpha,\n    findLtAlpha,\n    findLteAlpha,\n    balanceAlpha,\n    getDistanceBetweenNodesAlpha,\n} from './compare-alpha';\n\nconst tree = toBSTAlpha([{ name: 'Anakin' }]);\n\nconst updatedTree = pipe(\n    (t) =\u003e addAlpha(t, { name: 'Yoda' }),\n    (t) =\u003e removeAlpha(t, { name: 'Luke' }),\n    (t) =\u003e balanceAlpha(t),\n    (t) =\u003e findGtAlpha({ name: 'Yoda' })\n)(tree);\n```\n\n---\n\n### The infamous `BinarySearchTree` class\n\nWhile diverging from the functional approach, the `BinarySearchTree` class offers many advantages, depending on the situation:\n\nPros:\n\n-   Natural chaining\n-   Tree state encapsulation\n-   Compare function encapsulation\n-   Has all methods listed as functions before\n\nCons:\n\n-   No tree shaking of unused methods, obviously\n\nLet's rewrite the Star Wars example with this approach:\n\n```typescript\ntype Hero = { name: string };\n\nconst compareAlpha = (a: Hero, b: Hero) =\u003e a.name.localeCompare(b.name);\n\nconst heroes: Hero[] = [\n    { name: 'Han' },\n    { name: 'Anakin' },\n    { name: 'Leia' },\n    { name: 'Luke' },\n    { name: 'Padme' },\n    { name: 'Lando' },\n    { name: 'Chewie' },\n];\n\nconst bst = new BinarySearchTree(heroes, compareAlpha, { isBalanced: false });\n// Schema of bst.tree\n//\n//             Han\n//           /     \\\n//     Anakin       Leia\n//           \\     /    \\\n//       Chewie  Lando   Luke\n//                         \\\n//                        Padme\n\nbst.add({ name: 'Yoda' })\n    .add({ name: 'Obiwan' })\n    .add([{ name: 'Boba' }, { name: 'Grogu' }])\n    .remove([{ name: 'Han' }, { name: 'Padme' }])\n    .remove({ name: 'Luke' });\n\n// Schema of bst.tree, after update\n//\n//            Lando\n//           /     \\\n//     Anakin       Leia\n//         \\            \\\n//       Chewie        Obiwan\n//        /    \\            \\\n//      Boba  Grogu        Yoda\n\nbst.findMin().data[0].name; // Anakin\nbst.findMax().data[0].name; // Yoda\nbst.find({ name: 'Grogu' }).node.data[0].name; // Grogu\nbst.find({ name: 'Grogu' }).path; // ['left', 'right', 'right']\n// Thanks to the compare function, the search will traverse like this:\n// Lando -\u003e Anakin -\u003e Chewie -\u003e Grogu\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfieve%2Fbinary-search-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frfieve%2Fbinary-search-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfieve%2Fbinary-search-tree/lists"}