Common mistakes when working with trees include confusing binary trees with BSTs, assuming traversal is O(log n), forgetting that skewed trees degrade to O(n), and misunderstanding height vs depth. These pitfalls lead to incorrect complexity analysis and algorithm design.
Trap: 'BST search is always O(log n)' — Wrong! If elements are inserted in sorted order, the BST becomes skewed (linked list), and search becomes O(n). Truth: BST search is O(log n) only when balanced. This is why self-balancing BSTs exist.
1. Remember: Binary Tree ≠ BST (ordering matters!)
2. Traversal = O(n) always (visits all nodes)
3. BST performance depends on balance
4. Height ≠ Depth (direction matters)
5. Inorder sorted only for BSTs
The Traps That Trip Students
Trap 1: All Binary Trees are BSTs
❌ Wrong: "A binary tree with numbers is a BST"
✔ Truth: A BST requires the ordering property: Left < Root < Right for every node. A binary tree is just "at most 2 children" — no ordering required.
Trap 2: Traversal is O(log n)
❌ Wrong: "Traversing a tree takes O(log n) time"
✔ Truth: Traversal visits every node exactly once, so it's O(n). The height O(log n) only affects operations that depend on path length (search, insert, delete).
Trap 3: BST Operations are Always O(log n)
❌ Wrong: "BST search is always O(log n)"
✔ Truth: Only when balanced! Skewed BSTs (elements inserted in sorted order) degrade to O(n). This is why AVL and Red-Black trees exist.
Trap 4: Height and Depth are the Same
❌ Wrong: "Height and depth are interchangeable"
✔ Truth: Height is measured downward (from node to deepest leaf). Depth is measured upward (from root to node). For root: height = tree height, depth = 0.
Trap 5: Inorder Always Gives Sorted Order
❌ Wrong: "Inorder traversal gives sorted order"
✔ Truth: Only for BSTs! Inorder of a regular binary tree doesn't guarantee sorted order — only BSTs have the ordering property.
Trap 6: Trees Can Have Cycles
❌ Wrong: "A tree can loop back to previous nodes"
✔ Truth: Trees are acyclic by definition. If there's a cycle, it's a graph, not a tree. Trees have exactly one path between any two nodes.
Trap 7: All Nodes Have Two Children
❌ Wrong: "Binary tree means every node has 2 children"
✔ Truth: Binary tree means "at most 2 children". Nodes can have 0, 1, or 2 children. Only Full Binary Trees require 0 or 2 (never 1).
Trap 8: Space Complexity is Always O(n)
❌ Wrong: "Tree operations use O(n) space"
✔ Truth: Storage is O(n), but recursion stack is O(h). For balanced trees, stack is O(log n). For skewed trees, stack is O(n) — can cause overflow!
How to Avoid These Traps
1. Remember: Binary Tree ≠ BST (ordering matters!)
2. Traversal = O(n) always (visits all nodes)
3. BST performance depends on balance
4. Height ≠ Depth (direction matters)
5. Inorder sorted only for BSTs
6. Trees are acyclic (no cycles)
7. Binary = "at most 2", not "exactly 2"
8. Consider recursion stack space
Understanding common pitfalls prevents errors in exams and interviews. Many students confuse tree types, misapply complexity analysis, or forget edge cases. Recognizing these traps helps you write correct code and give accurate answers.
"What is a common mistake students make about tree traversal time complexity?"
Students often think traversal is O(log n) because they confuse it with search operations. However, traversal visits every node exactly once, making it O(n) regardless of tree shape. Only operations that depend on path length (like search) have O(log n) complexity for balanced trees.