The Odin Project - Balanced Binary Search Tree Assignment
All the magic is in the console.
The console will initially show the "pretty printed" results of:
window.tree = new Tree(randArrBelow100(23)); // randArrBelow100(count) returns `count` numbers below 100
The provided array of numbers will have duplicate numbers removed (as per the assignment spec).
Create a new Balanced Binary Search Tree with:
new Tree([number, number, .... ]);
And see the results "pretty printed" in the console by calling
Tree.prettyPrint();
Other available functions for the `Tree` class
- insert(num) - inserts the given value (may unbalance tree)
- deleteItem(num) - delete the given value from the tree, rearranging any children as needed
- find(num) - returns the node with the given `num`, or null if not found
- levelOrder(callbackFunc) - runs `callbackFunc(node)` on every node in "level order", or breadth-first
- inOrder(callbackFunc) - runs `callbackFunc(node)` on every node via depth-first "in order" sequence (left, root, right)
- preOrder(callbackFunc) - runs `callbackFunc(node)` on every node via depth-first "pre order" sequence (root, left, right)
- postnOrder(callbackFunc) - runs `callbackFunc(node)` on every node via depth-first "post order" sequence (left, right, root)
- height(node) - returns the height of a given node (furthest distance to a descendant "leaf" node)
- depth(node) - returns the depth of a given node (distance from the tree's "root" node)
- isBalanced() - returns true if the tree is balanced, false if not
- rebalance() - rebalances the tree, returns true if the tree was rebalanced, returns false if it was already balanced
- values() - returns all values in the tree, in breadth-first "level order"