Recursion · Self-similar structures
Fractal Tree
Apply one branching rule recursively. Self-similar structures, made tangible.
A fractal tree is built by one rule: a branch grows two smaller branches at a fixed angle, each of which grows two smaller branches, forever. Stop after N iterations and you have a tree. Recursion — the function that calls itself — is the natural language for any self-similar structure.
Color
What you just learned: This tree draws itself by repeating one simple rule: “draw a branch, then draw two smaller branches.” This is called recursion — a function that calls itself. Trees, rivers, and snowflakes all follow recursive patterns.
What’s happening under the hood
- ›Recursive function: `drawBranch(length, angle)`. Base case: length below threshold → stop. Recursive case: call `drawBranch(length × 0.7, angle ± 30°)` twice.
- ›Each recursion level doubles the branch count: depth 5 = 32 leaves, depth 10 = 1024, depth 20 = ~1 million. Exponential growth is exactly what recursion expresses.
- ›Recursion appears throughout CS: tree traversals, parsers, search algorithms, divide-and-conquer sorts (merge sort, quick sort), and the call stack itself.
Dig deeper
Phase 1 · FunctionsThe concept you just explored is taught with full depth in the formal DURA curriculum.