Binary Trees
Step 1 of 11
A binary node has exactly two child slots: left and right. Never three.
The Idea
A binary tree gives every node exactly two child slots: left and right. Either slot may sit empty, and the two are not interchangeable, so swapping them produces a different tree. That fixed shape is what lets an algorithm say "go left" and mean something precise.
Real-World Example
A TV aerial splitter. One cable feeds in and two run out, and each output can feed another splitter or go straight to a set. Nothing ever merges back together, and the two sockets are physically distinct, not a pair you can swap.
The Code
Your turn
Put the steps in the right order.
- Recursively count the left subtree
- Return 0 when the node is empty
- Add one for this node and return the total
- Recursively count the right subtree
Mini quiz
1 / 3