Trees & Binary Search Tree
Think of it like this
A tree is like a company org chart: the CEO is at the top (root), each manager has direct reports (children), and everyone has exactly one boss (parent). There are no loops, you can't be your own manager's manager.
A binary tree means each node has at most two children: left and right.
A binary search tree (BST) adds an ordering rule: everything to the left is smaller, everything to the right is larger. This one rule is what gives you fast search, insert, and sorted traversal.
Vocabulary
50 โ Root (no parent)
/ \
30 70 โ Internal nodes (have children)
/ \ / \
20 40 60 80 โ Leaf nodes (no children)
Terms:
Height of tree = 2 (longest root-to-leaf path, counting edges)
Depth of node 60 = 2 (root-to-60 edges)
Subtree rooted at 30 = {20, 30, 40}