SlideShare una empresa de Scribd logo
1 de 16
Presentation On :




                    AVL TREES


Group Member:
Chhatra Thapa (Sid:10935)
Susat Maharjan (Sid:10954)
                                1
AVL TREE IS…



• named after Adelson-Velskii and Landis
• the first dynamically balanced trees to be propose
• Binary search tree with balance condition in which the sub-trees of
  each node can differ by at most 1 in their height




                                                         2
DEFINITION OF A BALANCED TREE



•   Ensure the depth = O(log N)
•   Take O(log N) time for searching, insertion, and deletion
•   Every node must have left & right sub-trees of the same height
•   Goal: keep the height of a binary search tree O(log N).




                                                           3
AN AVL TREE HAS THE FOLLOWING PROPERTIES:



• Sub-trees of each node can differ by at most 1 in their height
• Every sub-trees is an AVL tree




                                                           4
AVL TREE?




   YES                      NO
   Each left sub-tree has   Left sub-tree has height 3,
   height 1 greater than    but right sub-tree has
   each right sub-tree      height 1
                                            5
INSERTION AND DELETIONS



• It is performed as in binary search trees
• If the balance is destroyed, rotation(s) is performed to correct
  balance
• For insertions, one rotation is sufficient
• For deletions, O(log n) rotations at most are needed




                                                           6
Single Rotation




 left sub-tree is one level       move ① up a level and
 deeper than the right sub-tree   ② down a level
                                                  7
Single rotation : Rotate right




                                 8
Single rotation : Rotate left




                                9
Double Rotation




Left sub-tree is two level       Move ② up two levels and
deeper than the right sub-tree   ③ down a level
                                                 10
Insertion



            Insert 6



                       Imbalance at 8
                       Perform rotation with 7




                                      11
12
Deletion



                          Delete 4


                                     Imbalance at 3
                                     Perform rotation with 2




Imbalance at 5
Perform rotation with 8                             13
14
KEY POINTS



• AVL tree remain balanced by applying rotations, therefore it
  guarantees O(log N) search time in a dynamic environment
• Tree can be re-balanced in at most O(log N) time




                                                         15
THANK YOU
    

            16

Más contenido relacionado

La actualidad más candente

Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operationsKamran Zafar
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureYaksh Jethva
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAbhishek L.R
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structureghhgj jhgh
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxAlbin562191
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureTushar Gonawala
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionHAMID-50
 
Avl trees
Avl treesAvl trees
Avl treesppreeta
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeShivam Singh
 

La actualidad más candente (20)

Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data Structure
 
Binary tree
Binary  treeBinary  tree
Binary tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Avl tree
Avl treeAvl tree
Avl tree
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Trees
TreesTrees
Trees
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Different Sorting tecniques in Data Structure
Different Sorting tecniques in Data StructureDifferent Sorting tecniques in Data Structure
Different Sorting tecniques in Data Structure
 
Expression trees
Expression treesExpression trees
Expression trees
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary tree
Binary tree Binary tree
Binary tree
 
B+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletionB+ tree intro,uses,insertion and deletion
B+ tree intro,uses,insertion and deletion
 
Avl trees
Avl treesAvl trees
Avl trees
 
4. avl
4. avl4. avl
4. avl
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 

Destacado (8)

Natural Vegetation
Natural VegetationNatural Vegetation
Natural Vegetation
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Avl tree
Avl treeAvl tree
Avl tree
 
Avl trees 2
Avl trees 2Avl trees 2
Avl trees 2
 
10 de-thi-hsg-toan-10-co-dap-an
10 de-thi-hsg-toan-10-co-dap-an10 de-thi-hsg-toan-10-co-dap-an
10 de-thi-hsg-toan-10-co-dap-an
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Wild life
Wild lifeWild life
Wild life
 
Tree plantation
Tree plantationTree plantation
Tree plantation
 

AVL Tree

  • 1. Presentation On : AVL TREES Group Member: Chhatra Thapa (Sid:10935) Susat Maharjan (Sid:10954) 1
  • 2. AVL TREE IS… • named after Adelson-Velskii and Landis • the first dynamically balanced trees to be propose • Binary search tree with balance condition in which the sub-trees of each node can differ by at most 1 in their height 2
  • 3. DEFINITION OF A BALANCED TREE • Ensure the depth = O(log N) • Take O(log N) time for searching, insertion, and deletion • Every node must have left & right sub-trees of the same height • Goal: keep the height of a binary search tree O(log N). 3
  • 4. AN AVL TREE HAS THE FOLLOWING PROPERTIES: • Sub-trees of each node can differ by at most 1 in their height • Every sub-trees is an AVL tree 4
  • 5. AVL TREE? YES NO Each left sub-tree has Left sub-tree has height 3, height 1 greater than but right sub-tree has each right sub-tree height 1 5
  • 6. INSERTION AND DELETIONS • It is performed as in binary search trees • If the balance is destroyed, rotation(s) is performed to correct balance • For insertions, one rotation is sufficient • For deletions, O(log n) rotations at most are needed 6
  • 7. Single Rotation left sub-tree is one level move ① up a level and deeper than the right sub-tree ② down a level 7
  • 8. Single rotation : Rotate right 8
  • 9. Single rotation : Rotate left 9
  • 10. Double Rotation Left sub-tree is two level Move ② up two levels and deeper than the right sub-tree ③ down a level 10
  • 11. Insertion Insert 6 Imbalance at 8 Perform rotation with 7 11
  • 12. 12
  • 13. Deletion Delete 4 Imbalance at 3 Perform rotation with 2 Imbalance at 5 Perform rotation with 8 13
  • 14. 14
  • 15. KEY POINTS • AVL tree remain balanced by applying rotations, therefore it guarantees O(log N) search time in a dynamic environment • Tree can be re-balanced in at most O(log N) time 15
  • 16. THANK YOU  16

Notas del editor

  1. The AVL tree is named after its two Soviet inventors, G. M. Adelson-Velskii and E. M. Landis, who published it in their 1962 paper "An algorithm for the organization of information.AVL trees are binary search trees that balances itself every time an element is inserted or deleted.
  2. Balanced Tree -Suggestion 1: the left and right subtrees of root have the same height -Suggestion 2: every node must have left and right subtrees of the same heightEach node of an AVL tree has the property that the heights of the sub-tree rooted at its children differ by at most one.We want a tree with small height.Height of a binary tree with N node is at least(log N) .Goal: keep the height of a binary search tree O(log N).Balanced binary search trees
  3. AVL tree approximates the ideal tree (completely balanced tree).AVL Tree maintains a height close to the minimum. Suppose h = 5 Then , left sub-tree height should be 4 right sub-tree height should be 3
  4. An update (insert or remove) in an AVL tree could destroy the balance. It must then be rebalanced before the operation can be considered complete.