AVL Trees


AVL Trees
===============
- Also called height balanced tree
-Height of children present at same level may not have same height. There height can differ at most by 1.
-The height of an AVL tree T storing n keys is O(log n)

Structure of AVL Tree
========================
- Consoder an AVL tree of n nodes
-Cosider a leaf which is closest to the root
- Suppose this leaf is at level k.
-Then height of a tree is at most 2k - 1.




Summary of AVL Tree
==========================
- If height is h , then leaf closest to root is at level  at least (h+1)/2
-On the first (h-1)/2 levels the AVL tree is a complete binary tree
- After (h-1)/2 level the AVL tree may start "thinning out"
-Number of nodes in AVL tree is at least 2 to raise (h-1)/2 and at most 2 raise to h

Insertion in AVL Tree
==========================
Insertion of node make tree changes height and hence height balance property voilated.

If Insertion causes T to become unbalanced , we travel up the tree from the newly created node until we find first node x such that its grandparent z is unbalanced node.(IMP)

-Rotation if performed to make balanced
even after rotation height of tree remains same
-Middle node becomes root after rotation



Deletion
=============================
-Let w be a node to be deleted
-Let z be the firt unbalanced node encountered while travelling up the  tree from w . Also let x be the child of y with a larger height .
-We perform rotation to restore balance at subtree rooted at z
-As this restructring may upset the balance of another node heigher in the tree , we must continue checking for balance until the root of T is reached.



Comments

Popular posts from this blog

JDBC Hive Connection fails : Unable to read HiveServer2 uri from ZooKeeper

Access Kubernetes ConfigMap in Spring Boot Application

Developing Custom Processor in Apache Nifi