[Verse 1] My tree's unbalanced, left side heavy as a brick Height difference of three, that's when the structure gets sick Binary search performance crashes when nodes lean too far AVL rotation magic keeps everything on par Check the balance factor, subtract the heights clean Left minus right, keep it negative one to positive three When violation strikes, four cases to decode Single or double spins to fix the tilted code [Chorus] Left-left case, rotate right once and done Right-right case, spin left until it's won Left-right twist, left first then right around Right-left flip, right first then left-ward bound Balance factor math, heights minus heights AVL rotations keep your search tree tight Remember the cases, four patterns to know Single and double spins make balanced trees grow [Verse 2] Insertion breaks the balance, deletion does it too Trace back up the path, check each ancestor through Left-left means grandparent tilts left, left child heavy left Single right rotation puts the middle node blessed Right-right mirror image, grandparent leans right side Right child weighted right, single left rotation's the guide Promote the middle value, demote the old root down Subtrees follow physics, balanced heights all around [Chorus] Left-left case, rotate right once and done Right-right case, spin left until it's won Left-right twist, left first then right around Right-left flip, right first then left-ward bound Balance factor math, heights minus heights AVL rotations keep your search tree tight Remember the cases, four patterns to know Single and double spins make balanced trees grow [Bridge] Double rotations when the zigzag appears Left-right and right-left, two spins calm your fears First rotation straightens out the inner bend Second rotation finishes what the first began Logarithmic search time, height stays controlled AVL guarantees performance, worth more than gold Update balance factors as you rotate the nodes Self-balancing tree magic in algorithmic codes [Outro] Four rotation cases burned into your brain Left-left, right-right, simple and plain Left-right, right-left, double the work AVL rotations keep your data structures perked Balance restored, search efficiency high AVL tree rotations, now you know why
← Binary search tree operations | Red-black tree balancing →