Skip to content

Instantly share code, notes, and snippets.

View sarahzhao25's full-sized avatar

Sarah Zhao sarahzhao25

  • Brooklyn, NY
View GitHub Profile
checkAndRotateRoots(root) {
if (root) {
let x = root.balanceFactor();
if (x > 1 || x < -1) rotate(root);
checkAndRotateRoots(root.parent.node);
}
}
@sarahzhao25
sarahzhao25 / Height.js
Last active January 6, 2018 21:44
Height function of a BST
BinarySearchTree.prototype.height = function(treeNode) {
return (treeNode === null) ? -1 : Math.max(this.height(treeNode.left), this.height(treeNode.right)) + 1;
};