From Binary Treesto AVL Trees
Understanding the Need for Self-
Balancing Trees
Presented by: [Your Name]
Institution: [Your Institution]
2.
Introduction to Trees
•A tree is a non-linear hierarchical data
structure.
• A binary tree has at most two children per
node.
• Terminology: root, node, edge, leaf, depth,
height.
3.
Binary Tree –Structure & Types
• Full Binary Tree: Every node has 0 or 2
children.
• Complete Binary Tree: All levels filled except
possibly the last.
• Perfect Binary Tree: All internal nodes have 2
children & all leaves at same level.
4.
Binary Search Tree(BST)
• Each node’s left child is smaller, right child is
larger.
• Example: Insert 10, 5, 15, 3, 7, 12, 18.
• Diagram: BST representation (to be drawn
manually).
5.
Problem in BST– Skewed Trees
• Worst-case: BST becomes left- or right-
skewed.
• Caused by sorted data input.
• Results in degraded performance: O(n) time
complexity.
• Diagram: Skewed BST [10, 20, 30, 40, 50].
6.
Need for BalancedTrees
• Goal: Maintain height ~ log(n).
• Balanced trees ensure O(log n) time
complexity.
• Solution: Self-balancing BSTs like AVL, Red-
Black, B-Trees.
7.
Introduction to AVLTrees
• Named after Adelson-Velsky and Landis
(1962).
• Self-balancing BST: Balance factor -1, 0, or +1.
• BF = Height(left subtree) - Height(right
subtree).
8.
AVL Tree –Rotations
• Used to restore balance after
insertion/deletion.
• Types of rotations:
• Left Rotation (LL), Right Rotation (RR),
• Left-Right (LR), Right-Left (RL).
• Include diagrams for each.
9.
AVL Tree Example
•Insert values: 30, 20, 10.
• RR Rotation applied to restore balance.
• Step-by-step diagram (to be added manually).
10.
Comparison: BST vs.AVL Tree
• BST: Not guaranteed to be balanced.
• AVL: Always balanced (BF = -1, 0, +1).
• BST Worst-case height: O(n), AVL: O(log n).
• AVL requires rotations on insert/delete.
11.
Why AVL TreesAre Best
• AVL Trees maintain strict balance (BF = -1, 0,
+1):
• → Lower tree height.
• → Faster search time (O(log n)).
• Compared to:
• Red-Black Trees: Loosely balanced, slightly
taller.
• B-Trees: Optimized for disk; height for block-
wise, not RAM.
12.
Applications of AVLTrees
• Used in database indexing.
• Memory management.
• Real-time systems.
• Scenarios with frequent insertions/deletions +
fast lookup.
13.
Conclusion
• Binary Treesare foundational structures.
• BSTs suffer in performance if unbalanced.
• AVL Trees solve this via self-balancing.
• Ensures optimal O(log n) for
search/insert/delete.