← Data Structures & Algorithms learning pathData Structures & Algorithms · Module 7 of 10
Trees and binary search trees
Store hierarchical and sorted data.
📖 Key ideas
- A tree has a root, children and leaves.
- Binary tree: each node has at most two children.
- BST: left < node < right; search O(log n) if balanced.
- Traversals: inorder, preorder, postorder, level order.
- Balanced trees (AVL, Red-Black) keep height O(log n).
💡 Real-life example: A BST is a guessing game: "higher or lower?" halves the possibilities each step.
RootTop node
LeafNode with no children
BSTBinary search tree
Inorder traversalLeft, node, right