AiTechWorlds
AiTechWorlds
Insert and delete in a self-balancing AVL tree with live balance factors and LL/LR/RL/RR rotation animations.
def insert(root, val):
if root is None:
return Node(val)
if val < root.val:
root.left = insert(root.left, val)
elif val > root.val:
root.right = insert(root.right, val)
return rootAn AVL tree is a self-balancing binary search tree where the heights of the two child subtrees of any node differ by at most one. After every insert or delete it rebalances using rotations, keeping search, insert, and delete at O(log n).
| Search / Insert / Delete (avg) | O(log n) |
| Worst case | O(log n) |
| Space | O(n) |
The AVL Tree Visualizer lets you insert and delete values in a self-balancing binary search tree and watch it rebalance with rotations. An AVL tree keeps the height difference between any node's two subtrees to at most one, performing LL, LR, RL, or RR rotations after each operation. This guarantees O(log n) search, insert, and delete in all cases. Balance factors are shown next to each node.
Insert values
Type a number and click Insert, or click Random to build a sample AVL tree.
Watch rotations
When a node's balance factor exceeds ±1, the tree rotates automatically; the log explains which rotation ran.
Delete and re-balance
Delete a value and watch the tree rebalance if needed.
Run a traversal
Animate inorder, preorder, postorder, or level-order order.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.