当前位置:网站首页>Rotation of AVL tree

Rotation of AVL tree

2022-06-09 22:10:00 sy2453

Catalog

Selection of single rotation and double rotation :

Left spin

Right single spin

Right left double rotation

Double left and right

AVL Verification of trees


Selection of single rotation and double rotation :

 

Left spin

Right single spin

Right left double rotation

Double left and right

AVL Verification of trees

  • AVL The tree is based on the binary search tree and adds the restriction of balance , So verify AVL Trees , There are two steps :
    • 1. Verify that it is a binary search tree
      • If the middle order traversal can get an ordered sequence , It is explained as a binary search tree
    • 2. Verify that it is a balanced tree
      • The absolute value of the height difference of each node subtree shall not exceed 1( Note that if there is no balance factor in the node )
      • Whether the balance factor of the node is calculated correctly
    • Special scenes 2
      • {4, 2, 6, 1, 3, 5, 15, 7, 16, 14}
      • The value found during validation is 6 There is an error in the balance factor of the node , The balance factor should have been -1, But the result is 0;
      • Cause analysis :
        • Right left double rotation :
        • Problem solving :
          • You can rotate it according to SubRL The equilibrium factor of , Modify the rotation after it is completed :
        • Double left and right
        • Problem solving :
          • You can rotate it according to SubLR The equilibrium factor of , Modify the rotation after it is completed :
  • AVL Complex tree implementation :
    • 1. The implementation is more complex , because AVL Maintain the balance factor for nodes in , The balance factor needs to be updated after each insertion , After the double rotation is completed, the balance factor also needs to be updated
    • 2. Delete : The most inserted case should always be updated or rotated to the root position
原网站

版权声明
本文为[sy2453]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206092121205538.html