Back to tree

📋 算法:解决问题的“菜谱”📋 Algorithm: the Recipe for Solving Problems

上一片里,💻小电脑把东西分门别类装进格子(数据结构)。格子有了,下一步呢?学“做事的先后步骤”——这就叫算法。 Last leaf, 💻 Little Computer sorted everything into tidy boxes (data structures). Boxes ready — what's next? Learning the exact steps to get things done — that's called an algorithm.

第 1 步:菜谱就是算法Step 1: A recipe is an algorithm

先看算法长什么样——和小电脑的菜谱一模一样。First, what does an algorithm look like — exactly like the little computer's recipe.

算法=菜谱:输入、第1/2/3步、输出
小电脑想做蛋炒饭:菜谱写清第 1 步淘米,第 2 步打蛋,第 3 步下锅。左边是生的输入,右边是熟的输出。算法也一样:输入 → 一步步做 → 输出,步步清楚,绝无歧义。 Little Computer wants fried rice: the recipe says step 1 rinse the rice, step 2 beat the eggs, step 3 fire the wok. Raw stuff goes in on the left, dinner comes out on the right. An algorithm is the same: input → step-by-step work → output, every step crystal clear.

你可能会问:步骤清楚不就行了,还分好坏吗?You might ask: if the steps are clear, can one recipe still beat another?

第 2 步:好坏差百倍Step 2: Good ones run 100× faster

二分法猜数字:太大、太小、猜中
玩个猜数字:1~100 里藏了一个数。从 1 一个个试,最惨猜 100 次。每次猜中间呢?50 太大砍一半,25 太小砍一半,最多 7 次必中。排序也一样:冒泡排序慢吞吞,快速排序嗖嗖的,同样干活差百倍。 Try a guessing game: a number hides between 1 and 100. Counting up from 1 takes up to 100 tries. But always guess the middle? 50 is too big — halve it; 25 too small — halve again; 7 tries always win. Sorting is the same: bubble sort crawls, quick sort flies — same job, 100× apart.

这样的“聪明步骤”,只活在课本和游戏里吗?Do such clever steps only live in textbooks and games?

第 3 步:算法无处不在Step 3: Algorithms are everywhere

导航路线规划:慢路线20步、快路线8步、同样到达
导航帮你挑快的路,搜索秒出答案,推荐猜你喜欢——背后全是算法。记住这对兄弟:数据结构是装东西的格子,算法是做事的菜谱。格子加菜谱,计算机才跑得飞快。 Navigation picks the fast road, search answers in a blink, recommendations read your mind — algorithms behind them all. Remember the two brothers: data structures are the boxes that hold things, algorithms are the recipes that do things. Boxes plus recipes — that's why computers fly.

🎮 你来当小电脑(30 秒)🎮 Your turn: be the little computer (30 seconds)

道理讲完了。直接和小电脑对战猜数字:4 关全用“取中间”拿下,再看自动演示秀一把 7 次必中。Theory done. Battle the little computer at guessing: clear 4 rounds with “take the middle”, then watch auto-play win in 7.

一句话记住它:算法 = 解决问题的明确步骤;步骤有好坏,好算法快百倍。 Remember it in one line: an algorithm is a clear recipe for solving a problem — and a good recipe runs 100× faster.
算法 = 输入 → 一步步做 → 输出,步步清楚没歧义Algorithm = input → step-by-step work → output, no ambiguity 二分每次砍掉一半:100 个数最多 7 次,比一个个试快得多Binary search halves the range each time: 100 numbers in at most 7 tries 导航、搜索、推荐背后全是算法;格子加菜谱缺一不可Navigation, search, recommendations all run on algorithms — boxes plus recipes
内容参考 OpenStax 等公开教材,多来源核对 · AI 生成、人工审核 · 发现错误欢迎指正,帮这片叶子长得更好。 Based on OpenStax and other open textbooks, cross-checked across sources · AI-generated, human-reviewed · Spotted a mistake? Tell us — help this leaf grow.