namastey-b-tree
A JavaScript package implementing the B-Tree data structure.
Description
namastey-b-tree
is a simple and efficient implementation of the B-Tree data structure, supporting various key operations. B-Trees are self-balancing trees that maintain sorted data and allow searches, sequential access, insertions, and deletions in logarithmic time.
Features
- traverse(): Traverse the B-Tree and print all keys in sorted order.
- search(key): Search for a key in the B-Tree. Returns the node containing the key or
null
if not found. - insert(key): Insert a new key into the B-Tree. Handles splitting nodes if necessary.
Installation
To install the package globally, use the following command:
npm install -g namastey-b-tree
Examples
const BTree = require('namastey-b-tree');
const tree = new BTree(3);
tree.insert(10);
tree.insert(20);
tree.insert(5);
tree.insert(6);
tree.insert(12);
tree.insert(30);
tree.insert(7);
tree.insert(17);
console.log('Traversal of the constructed B-Tree:');
tree.traverse();
console.log('Search result for key 6:', tree.search(6));
console.log('Search result for key 15:', tree.search(15));