Loading section...
Common Bugs
Concepts: pyTreeBugs, pyBaseCase, pyRecursionLimit
Tree traversal bugs are subtle because the code often runs without throwing an error — it just produces the wrong output silently. The five bugs below account for the vast majority of wrong submissions and lost interview points. Know them by name so you can diagnose fast. Bug 1: Missing the Base Case Bug 2: Mixing Traversal Orders Bug 3: Modifying the Tree During Traversal Bug 4: Infinite Loops in Cyclic Graphs Bug 5: Python's Recursion Limit Python's default recursion limit is 1000 frames. A balanced binary tree of depth 1000 has roughly 2^1000 nodes — not a practical concern. But a completely unbalanced tree (linked list) of 10,000 nodes will hit the limit and crash. In a production context, always mention this risk and prefer iterative DFS for deep trees.