This project is an implementation of a Balanced Binary Search Tree (BST) in JavaScript. It provides efficient insert
, delete
, find
, and traversal operations with self-balancing capabilities.
- Node and Tree class-based architecture
- Balanced tree construction from an array
- Efficient insertion and deletion (O(log n))
- Tree traversal methods:
levelOrder
,inOrder
,preOrder
,postOrder
- Utility methods:
height
,depth
,isBalanced
,rebalance
- Tree visualizer:
prettyPrint
- Unit tests with Jest
const { Tree, prettyPrint } = require('member-isaiah-binary-search-trees');
const tree = new Tree([1, 7, 4, 23, 8, 9]);
console.log('Is balanced?', tree.isBalanced());
prettyPrint(tree.root);
tree.insert(99);
tree.rebalance();
new Tree(array)
— builds a balanced BST from a sorted, deduplicated arrayinsert(value)
— inserts a new valuedeleteItem(value)
— removes a valuefind(value)
— finds and returns the node with the given valuerebalance()
— rebuilds the tree into a balanced formisBalanced()
— checks if the tree is balancedheight(node)
— returns the height of a nodedepth(value)
— returns the depth of a node with that value- Traversals:
inOrder(cb)
,preOrder(cb)
,postOrder(cb)
,levelOrder(cb)
— all require a callback