← Data Structures & Algorithms learning path
Data Structures & Algorithms · Module 7 of 10

Trees and binary search trees

Store hierarchical and sorted data.

📖 Key ideas

  1. A tree has a root, children and leaves.
  2. Binary tree: each node has at most two children.
  3. BST: left < node < right; search O(log n) if balanced.
  4. Traversals: inorder, preorder, postorder, level order.
  5. 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