Posts

Showing posts from April, 2020

AVL TREES & B-TREES

Image
AVL TREE DEFINITION AVL trees is a self-balancing binary search tree where the difference between heights of left and right subtrees cannot be more than one for all nodes. To ensure that this property is fulfilled, each node will have a variable called the balance factor  which is calculated by (height of left subtree - height of right subtree). The node is said to be balanced  if and only if the balance factor is = {-1,0,1}. With this condition, the property of the AVL tree will be fulfilled. BENEFITS The obvious benefit of an AVL tree when compared with a BST is the worst case time complexity of a search in an AVL tree is O(log n) compared to the O(n) worst case time complexity of a BST. This is simply because an AVL tree will always have the height of O(log n) due to its property. BALANCING What happens if we insert a new node or delete a current node (NOTE: insertion and deletion follows the same algorithm as BST's, but is only added with the balancing a...