All lessons

8. Trees

Balanced trees overview

0 of 5 activities0%

Reading 1

Why balance matters

Open

Unbalanced BSTs degrade to O(n). AVL trees rotate to keep height difference ≤1. Red-Black trees keep approximate balance with color rules.

std::map / std::set in C++ are typically Red-Black trees — O(log n) operations.

Know that rotations restore BST order while changing shape.

Check 2

std::map

Open

std::map operations are typically

Fill in 3

Fix shape

Open

The local restructuring operation is a

Try it 4

Height of chain

Open

Skewed height.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Log depth hope

Open

Read n (power of two). Print log2(n) as integer (depth scale of balanced tree).

main.cpp
Loading editor…