We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Self Balancing Tree
Self Balancing Tree
Sort by
recency
|
179 Discussions
|
Please Login in order to post a comment
Js solution
class Node { constructor(value) { this.value = value; this.left = null; this.right = null; this.height = 1; } }
function insert(root, data) { if (!root) return new Node(data);
}
function getHeight(node) { return node ? node.height : 0; }
function getBalance(node) { return node ? getHeight(node.left) - getHeight(node.right) : 0; }
function rightRotate(y) { const x = y.left; const T2 = x.right;
}
function leftRotate(x) { const y = x.right; const T2 = y.left;
}
function sortedArrayToAVL(arr) { if (arr.length === 0) return null;
}
function inOrderTraversal(node, result = []) { if (!node) return result;
}
function preOrderTraversal(node, result = []) { if (!node) return result;
}
function processData(input) { const lines = input.trim().split('\n'); const rootPointer = parseInt(lines[0]); const values = lines[1].split(' ').map(Number); const valueToAdd = parseInt(lines[2]);
}
processData("4\n3 2 4 5\n6");
Fully working python solution
Python template
My Java Solution with code explanation: https://github.com/tuphan22028238/DSA/blob/main/BT10/06_AVLTree/Solution.java
My C++ solution (modified from gfg)