Programming Fundamentals · Recursion and Divide-and-Conquer

Recursion: Break a Big Job into the Same Smaller Job

“Build a website” sounds scary; “write three lines of home-page copy” anyone can do. In the Engineering Advanced Part you saw a Coding Agent take a big ask and list small tasks on its own—that idea has a name: recursion. This lesson writes zero lines of code. Click a task tree, drag a slider, and you’ll own the word programmers make sound mystical.

Play a round · Help the Agent break down tasks

The boss drops one line: “Build a site for the bubble-tea shop.” You can’t start hands-on—but you can split. Click the cards below and peel the big job layer by layer until you hit ✋ “ready to do” leaf tasks, then hit “Start work.” Watch two things: splitting unfolds top-down; when work finishes, green “bubbles up” bottom-up back to the root.

Click the top big task first and split it open
See it? “Build a site” and “build the home page” are the same kind of problem—just smaller. The method for splitting “build a site” (cut into chunks, keep splitting each) lands unchanged on “design pages.” Using the same method on the same class of problem as it gets smaller—that’s recursion. Agent task breakdown, walking folders (folders inside folders), cascading KPIs at a company—same playbook.
Look again · one rule draws a tree

Recursion’s magic: one rule, unboundedly complex results. This tree’s entire manual is one sentence (under the figure). Drag the slider to deepen “split levels,” and watch: every new branch is a shrink of the last—the rule never changes, only the scale.

🌱 The whole rule: draw a branch, fork two at the tip, each fork is a “smaller you”—return to the start of this rule.
2 levels 3 branches total
“Calling yourself” means exactly this.The last step of “draw a branch” is to run “draw a branch” again. A recursive function in code looks the same: the last line of the body calls itself, with a smaller problem. Depth 8 is 255 branches—one rule, one big tree.
Concept card · Recursion trio

Those two demos hide all three requirements of recursion. From now on, check any recursion against these three:

1

Same kind of work

“Build a site” and “build the home page” are the same class of problem, so the same split method works. If the subproblems are a totally different kind of thing, recursion doesn’t apply.

2

Smaller scale

Each split must make the problem a notch smaller: whole site → three sections → one page. Every fractal fork is shorter than its parent. If it doesn’t shrink, you’ll never finish splitting.

3

Base case

When you hit a ✋ “ready to do” leaf, you must stop. This is the deadly one—you saw it in the sister chapter on stacks: each deeper recursive call stacks another frame; no base case means Stack Overflow.

One more layer on the AI connection: Ask an Agent to “refactor the whole project,” and it lists subtasks; if “refactor the login module” is still too big, it keeps splitting—until every item is an actionable “edit one file.” The moment it decides “small enough to do” is its base case. Next lesson you’ll see that merging the split results back together is exactly the idea behind context Compaction.

What this lesson wants to share