Programming Fundamentals · Algorithms Behind AI

Divide and Conquer: The Algorithm Behind Context Compression

Compaction in the AI Practicum is really divide and conquer: split a long chat, summarize each chunk, then merge. Run recursive summarization yourself and watch information compress layer by layer

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “Divide and Conquer: The Algorithm Behind Context Compression”?

Compaction in the AI Practicum is really divide and conquer: split a long chat, summarize each chunk, then merge. Run recursive summarization yourself and watch information compress layer by layer

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

Compress it yourself · a 3600-token renovation chat

Below is a full chat where you and an AI discuss a renovation plan—12 messages, about 3600 tokens, about to blow the context window. Hit “Start compressing,” and watch the three acts: first split (into three segments), then conquer (each segment becomes one summary), finally merge (three summaries into one)—the token counter up top shows how much you saved.

Current context3600token
Split → summarize each → merge, three acts in a row
Try turning on “Keep the latest 4” and compress again. That’s what real Agents do: the latest turns are usually what you’re doing right now—too precious to touch—so only the older parts get summarized. You’ll see tokens don’t drop all the way to 200—fidelity and space are always a trade.
Concept card · the same playbook as merge sort

Those three acts have a formal name: divide and conquer (Divide and Conquer). Its textbook celebrity is merge sort—split a list into small pieces, sort each, then merge pairwise. Merge sort sorts numbers; Compaction compresses talk—same skeleton:

Split

✂️ Cut into pieces

If the big problem won’t solve directly, cut it into smaller pieces. Merge sort: halve a list until you have singles. Compaction: split a long chat by topic or turn into segments.

Conquer

🔧 Solve each piece

Small pieces are easy. Merge sort: sort each short run. Compaction: summarize each segment—short enough for the AI to read and summarize accurately in one go. This step can even run in parallel, so it’s faster.

Merge

🧩 Merge the results

Assemble the piece results into a full answer. Merge sort: fuse two sorted runs into one. Compaction: merge several summaries into one master summary. Still too many segments? Recurse for another round—last lesson’s flavor is back.

Why not ask the AI to summarize the whole thing in one shot? Because “summarize ten thousand words” would itself blow the context—exactly the problem we’re solving. Divide and conquer’s cleverness: turn an “unsolvable big problem” into a pile of “definitely solvable small ones”, then spend a little effort assembling. In the Engineering Advanced Part, Coding Agents read large codebases the same way: file by file, note the key points, then roll up.
Honest card · the cost of compression

⚠️ Summaries are lossy compression—details get lost

Original: “budget under 80k” “I really hate red—no red anywhere in the house
After: “discussed budget and color preferences”← the exact number and the red ban are gone
After compression the AI still knows you “talked about budget,” but ask “what’s my budget?” and it can only guess; next time it picks a red sofa and you’ve got no ground to stand on. That’s why the AI Practicum keeps stressing: critical facts (numbers, hard constraints, decisions) must live in long-term memory or a doc—don’t trust the summary to keep them. Summaries cover “what we roughly talked about”; the archive holds what’s set in stone.

The algorithmic cost curve in “Compress it yourself · a 3600-token renovation chat”

“Below is a full chat where you and an AI discuss a renovation plan—12 messages, about 3600 tokens, about to blow the context window.” is not asking you to memorize steps. It trains you to spot repeated work: as the input grows, how many comparisons, moves, or recursive calls does the program perform?

Find repeated work before declaring something fast

Break “Those three acts have a formal name: divide and conquer (Divide and Conquer).” into three questions: how input size changes, what each round does, and whether the next round can shrink its search space. Big-O describes growth, not an exact time on every machine; constants, memory, and data distribution still matter.

  • Divide and conquer = split small, solve each, then merge : an unsolvable big problem becomes a pile of solvable small ones
  • Compaction is divide and conquer’s real face in AI : segment → summarize each → merge—same skeleton as merge sort
  • Recent turns are the most precious : real Agents only compress the old and keep the new—fidelity and space are always trading

Theoretical optimum is not always practical optimum

When AI writes an algorithm, trace a small input by hand and benchmark progressively larger inputs. That turns “Assemble the piece results into a full answer.” from a slogan into a performance claim you can check.

From “Compress it yourself · a 3600-token renovation chat” to “Concept card · the same playbook as merge sort”

“Compress it yourself · a 3600-token renovation chat” grounds the problem in “Below is a full chat where you and an AI discuss a renovation plan—12 messages, about 3600 tokens, about to blow the context window. Hit “Start compressing,” and watch the three acts : first split (into three s…”. “Concept card · the same playbook as merge sort” then moves it toward “Those three acts have a formal name: divide and conquer (Divide and Conquer). Its textbook celebrity is merge sort—split a list into small pieces, sort each, then merge pairwise. Merge sort sorts numbers; Compa…”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

For a real task, find the repeated work first, ask how input size changes, and use a small benchmark to verify the theoretical judgment. Complexity should not become a label detached from the situation.

  • “Compress it yourself · a 3600-token renovation chat”: Below is a full chat where you and an AI discuss a renovation plan—12 messages, about 3600 tokens, about to blow the context window. Hit “Start compressing,” and watch the three acts : first split (into three s…
  • “Concept card · the same playbook as merge sort”: Those three acts have a formal name: divide and conquer (Divide and Conquer). Its textbook celebrity is merge sort—split a list into small pieces, sort each, then merge pairwise. Merge sort sorts numbers; Compa…
  • “The closing point”: Too many segments? Recurse and compress again : last lesson’s recursion + this lesson’s merge = full divide and conquer

The final “The closing point” brings the discussion to “Too many segments? Recurse and compress again : last lesson’s recursion + this lesson’s merge = full divide and conquer”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

What this lesson wants to share

  • Divide and conquer = split small, solve each, then merge: an unsolvable big problem becomes a pile of solvable small ones
  • Compaction is divide and conquer’s real face in AI: segment → summarize each → merge—same skeleton as merge sort
  • Recent turns are the most precious: real Agents only compress the old and keep the new—fidelity and space are always trading
  • Compression is lossy: facts like “under 80k” and “no red” need a separate store—don’t count on the summary
  • Too many segments? Recurse and compress again: last lesson’s recursion + this lesson’s merge = full divide and conquer
Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing Divide and Conquer: The Algorithm Behind Context Compression Algorithms Behind AI
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful