Tags

Balanced BST

Balanced BST

1 lesson
1 problem
2 community items

balanced-bst

Data Structures

1 lesson

Balanced BST (AVL / Red-Black)

Advanced

65 min

1 prereq

Insert the keys 1, 2, 3, 4, 5 into a plain BST in that order and you do not get a tree at all; you get a right-leaning chain with `O(n)` search. The fix is to detect imbalance after every insert or delete and rotate the offending subtree back into shape, which is exactly what a **Balanced BST** does. AVL and Red-Black trees are the two most influential designs in this family. This lesson covers the balance factor (height of left subtree minus height of right subtree), AVL's strict `|bf| <= 1` invariant enforced by the four rotation cases (LL, RR, LR, RL), and Red-Black trees' five color and structural invariants enforced by recoloring plus rotations. You will trace insertions through both schemes, see why Red-Black trees do fewer rotations on average and so are preferred by C++ `std::map` and Java `TreeMap`, and analyze the height bound (`<= 2 log n`) that gives both their worst-case `O(log n)` guarantee. In **Binary Search Tree (BST)**, you implemented search, insert, and delete that respected the ordering invariant but said nothing about shape; the resulting `O(n)` worst case is precisely what self-balancing solves by maintaining a height invariant in addition to the ordering invariant. Next, **B-Trees and B+ Trees** generalize the same balanced-tree idea to nodes that hold many keys at once, an essential design choice for disk-resident data.

Not Started

0%

Balanced BST
AVL Tree
Red-Black Tree
Binary Search Tree (BST)
Trees
Data Structures
Advanced
Premium
Comparison

Practice Problems

1 problem

Convert Sorted Array to Binary Search Tree

Free
Not Started
Easy

Given a sorted array, convert it into a height-balanced binary search tree using divide and conquer.

Binary Tree
Binary Search Tree (BST)
Balanced BST
Divide and Conquer
Recursion
Beginner

724

24