A skewed BST is a binary search tree where nodes are inserted in such a way that all nodes go only to one side—either all left or all right. This makes the tree behave like a linked list.
Left-skewed:
50
/
40
/
30
Right-skewed:
10
\\
20
\\
30
Since the tree becomes like a list, the height of the tree becomes n
. So operations like insertion, deletion, and search take O(n) time.
An AVL Tree is a self-balancing BST where after each insertion or deletion, the balance factor is checked and rotations are performed if needed.
Balance Factor = height of left subtree - height of right subtree
It must be -1, 0, or 1 for every node.
Example:
Inserting 30, 20, 10
Before:
30
/
20
/
10
After right rotate:
20
/ \\
10 30