Hidden in the last box藏在最後一個
The worst case for opening one by one. Count the dark boxes in the front row: how many were never opened?
這是「一個一個找」最慘的情況。數一數前面那排暗掉的箱子:有幾個根本沒被打開?
How Computers Work · Unit 3 · Lesson 10 · 電腦概論 單元三 第十課
Two rows of closed boxes, one number to find, and two ways to look: open the boxes one by one, or open the middle one and throw away half. Watch both at once and count. Then double the boxes, mix them up, play a number-guessing game, and see what happens with a million boxes.
兩排蓋著的箱子、一個要找的數、兩種找法:一個一個打開,或是打開中間那個、把一半丟掉。兩種同時進行,數數看各開了幾個。接著把箱子加倍、把箱子弄亂、玩猜數字,再看看一百萬個箱子會怎樣。
An algorithm is a clear, step-by-step method for solving a problem. The same problem can have more than one algorithm, and some take far fewer steps than others. The more things there are to deal with, the bigger the difference becomes.
演算法是解決問題的一套清楚的、一步一步的方法。同一個問題可以有不只一種演算法,有的要做的步數比別的少得多。要處理的東西越多,差別就越大。
3D Model · 3D 模型
Both rows hold the same numbers, in order from small to large, and both are looking for the same one. The back row opens its boxes one by one. The front row opens the middle box, sees whether the number there is too small or too big, and rules out half of the boxes at once. Press Search and watch the two counters. Then change how many boxes there are and where the number hides, and at the end mix the boxes up.
兩排箱子裡是一樣的數,由小到大排好,兩排要找的也是同一個數。後面那一排一個一個打開。前面那一排先打開中間那個,看裡面的數是太小還是太大,然後一口氣排除一半的箱子。按「開始找」,注意看兩個計數。接著改一改箱子的數目、那個數藏的地方,最後把箱子弄亂試試。
Drag to turn · 拖曳旋轉
This 3D model needs WebGL, which this browser does not support. The buttons and the two counters below still work, and so do the reading and the games.
這個瀏覽器不支援 WebGL,無法顯示 3D 模型;下面的按鈕和兩個計數照樣能用,課文和小遊戲也都能用。
A teaching model. A real computer does not open boxes: it compares numbers kept in memory, and it does so extremely quickly. That is why the counters here show how many boxes were opened, not seconds. With 16 or 32 things, any method is quick on a real computer. The difference matters when there are millions, and you can see that in “More and More Boxes” below. The two methods have names: sequential search and binary search.
這是教學用的示意模型。真的電腦不是打開箱子,而是比較記憶體裡的數,而且比得非常快。所以這裡的計數是「打開了幾個」,不是秒數。只有 16 或 32 樣東西時,真的電腦用哪一種方法都很快;東西多到幾百萬時,差別才要緊——下面的「箱子越來越多」可以看到。這兩種方法有正式的名字:循序搜尋(sequential search)和二元搜尋(binary search)。
Model and code are drawn and programmed by My Culture Connect. Every count on this page is checked in tools/computers/test/search.test.mjs.
模型與程式由人師教育協會自行繪製、撰寫;這一頁出現的每一個步數都有自動測試(tools/computers/test/search.test.mjs)。
Reading · 英文閱讀
In Lesson 9 you saw that a program is a list of exact instructions. But before anyone can write the instructions, they need a method. A clear, step-by-step method that reaches the answer in a limited number of steps is called an algorithm. You already know some. The long division you learned at school is an algorithm.
Here is a problem. A row of closed boxes each holds a number, and you want to find the box that holds 48. One algorithm is very simple: open the first box, then the second, then the third, and go on until you find it. This always works. But with 16 boxes you may have to open all 16.
Now suppose the numbers are in order, from small to large. Then there is another algorithm. Open the box in the middle. If its number is too small, the one you want must be to the right, so you can forget the whole left half without opening it. Do the same again with the boxes that are left. With 16 boxes, you never need to open more than 5.
The real surprise comes when the boxes increase. Double them, and the first method may need twice as many tries. The second method needs only one more. With a million boxes, opening them one by one could take a million tries. Halving never takes more than 20.
There is a catch. Halving works only when the boxes are in order. Mix them up, and it throws away the half where your number is hiding. That is why a dictionary is kept in alphabetical order. Putting things in order is called sorting, and it takes work too. Also, the simple method sometimes wins by luck, when the number happens to be in the first box. So we compare methods by the most steps they could ever need.
This is why programmers care so much about algorithms. A computer that is twice as fast can only cut the time in half. A better method can turn a million steps into twenty. The method comes first. Then a program is written to tell the computer how to carry it out.
Questions · 閱讀理解
What is an algorithm? Give one example that has nothing to do with computers.
Describe the two ways of finding a number in a row of boxes. Which one needs the boxes to be in order?
Why does the difference between the two methods grow when there are more boxes?
Words & Phrases · 生字及片語
Quick Check · 小測驗
1. What is an algorithm?
2. With 16 boxes in order, how many does the halving method need to open at most?
3. When does the halving method work?
4. The boxes are doubled from 16 to 32. What happens to the most tries each method could need?
5. According to the reading, why do programmers care about algorithms?
Try It in the Model · 在模型裡試試
Use “One box each” to go slowly, and try “Somewhere” a few times to see ordinary cases, not only the best and the worst.
想慢慢看就用「各開一個」;多按幾次「隨便一個」,看看不是最好也不是最壞的普通情況。
The worst case for opening one by one. Count the dark boxes in the front row: how many were never opened?
這是「一個一個找」最慘的情況。數一數前面那排暗掉的箱子:有幾個根本沒被打開?
The boxes have doubled. How many more tries does each row need than before?
箱子變成兩倍。和剛才比,兩排各多開了幾個?
This time the simple method wins. Is it a better method, or was it lucky?
這一次簡單的方法贏了。是它比較好,還是它運氣好?
The numbers are no longer in order. Watch which half the front row throws away, and where the number really was.
裡面的數不再照順序了。看前面那一排把哪一半丟掉,而那個數其實在哪裡。
Game · 小遊戲
The computer picks a whole number from 1 to 100. After each guess it tells you only one thing: too big or too small. How few guesses can you manage? The green bar shows what is still possible.
電腦挑一個 1 到 100 的整數。你每猜一次,它只告訴你一件事:太大,還是太小。你最少幾次猜得到?綠色的長條是還有可能的範圍。
What is still possible · 還有可能的範圍:1 – 100
This is the halving method again. Every guess in the middle of what is left cuts the possibilities in half, so 100 numbers never need more than 7 guesses.這就是「每次砍一半」的方法。每次都猜剩下範圍的中間,可能性就少一半,所以 100 個數最多只要猜 7 次。
See Why · 看看為什麼
The model has room for 32 boxes. Here you can go up to a million. Choose a number of boxes and compare the most tries each method could need.
模型裡最多放 32 個箱子。這裡可以一路加到一百萬個。選一個箱子的數目,比一比兩種方法最多各要開幾個。
How many boxes · 幾個箱子
One by one, at most · 一個一個找,最多要開
0Halving, at most · 每次砍一半,最多要開
0These are worst cases: the most boxes each method could ever have to open. The green bar is drawn to the same scale as the orange one. From 1,000 boxes on, it is too short to see.這裡比的是最壞的情況:每一種方法「最多」要開幾個箱子。綠色的長條和橘色的是同一個比例尺;從 1,000 個箱子開始,它短到幾乎看不見。
Game · 小遊戲
Eight situations. For each one, decide which method fits: going through things one by one, or halving. Remember what halving needs.
一共八個情況。每一個都想一想,該用哪一種方法:一個一個找,還是每次砍一半。別忘了砍一半的方法需要什麼條件。
Right on the first try · 第一次就答對 0 / 0
These everyday examples are our own comparisons. People do not halve as exactly as a computer does, but the idea is the same.這些生活裡的例子是我們自己的比方。人不會像電腦那樣精確地對半切,但道理是一樣的。
Stories Behind Algorithms · 演算法的故事
Four short stories about step-by-step methods.
關於「一步一步的方法」的四個小故事。
al-Khwārizmī · 花拉子米
According to Britannica, the mathematician al-Khwārizmī was born about 780 and died about 850. He worked in Baghdad at the House of Wisdom. One of his books introduced Hindu-Arabic numerals and their arithmetic to the West. It survives only in a Latin translation, Algoritmi de numero Indorum, and from the Latin form of his name, Algoritmi, came the word algorithm. The title of another of his books gave us the word algebra.
根據大英百科,數學家花拉子米(al-Khwārizmī)大約生於 780 年、卒於 850 年,在巴格達的「智慧宮」工作。他有一本書把印度-阿拉伯數字和它的算術介紹到西方,現在只留下拉丁文譯本《Algoritmi de numero Indorum》。他的名字在拉丁文裡寫成 Algoritmi,algorithm(演算法)這個字就是這樣來的。他另一本書的書名,則給了我們 algebra(代數)這個字。
About 300 BCE · 約西元前 300 年
Britannica notes that Euclid’s Elements, published about 300 BCE, contained an algorithm for finding the greatest common divisor of two whole numbers. It also points out that every elementary-school student is drilled in long division, which is an algorithm too: a fixed set of steps that, followed carefully, always gives the quotient and the remainder.
大英百科指出,歐幾里得的《幾何原本》大約在西元前 300 年問世,裡面就有一個演算法:求兩個自然數的最大公因數。它還提到,每個小學生都反覆練習的直式除法也是一個演算法:一套固定的步驟,只要仔細照做,一定得到商和餘數。
Alan Turing · 圖靈
For centuries people used algorithms without saying precisely what one was. Britannica explains that the English mathematician Alan Turing rigorously defined the loosely understood concept of an algorithm, and that his description of a general-purpose algorithm machine, the Turing machine, became the foundation of computer science. Britannica calls a computer program “a special type of algorithm.”
好幾百年來,大家都在用演算法,卻沒有人精確地說出它到底是什麼。大英百科說,英國數學家圖靈(Alan Turing)替這個原本只是大略理解的概念下了嚴格的定義;他所描述的通用演算法機器,也就是圖靈機,成了電腦科學的基礎。大英百科把電腦程式稱為「一種特別的演算法」。
2 × 2 × 2 …
This one is our own arithmetic. Each time you halve, you answer one yes-or-no question: is it in this half? One question separates 2 things, two questions 4, three questions 8. Twenty questions separate 1,048,576 things, which is why a million boxes need at most 20 tries. It is the doubling from Lesson 1 run backward: every extra bit doubles what you can count, and every question halves what is left.
這一則是我們自己算的。每砍一半,就是回答一個「是或不是」的問題:它在這一半裡嗎?一個問題分得出 2 樣東西,兩個問題 4 樣,三個問題 8 樣。二十個問題分得出 1,048,576 樣東西,所以一百萬個箱子最多只要開 20 個。這是把第一課的「加倍」倒過來走:每多一個位元,能數的數目加倍;每多一個問題,剩下的少一半。
Myth vs. Fact · 常見迷思
✗ Myth · 迷思Algorithms are something only computers use.演算法是電腦才用的東西。
✓ Fact · 事實Long division is an algorithm, and Euclid wrote one down about 300 BCE. An algorithm is a method. A computer is one thing that can carry it out.直式除法就是演算法,歐幾里得在大約西元前 300 年就寫下了一個。演算法是方法;電腦只是能照著做的其中一樣東西。
✗ Myth · 迷思To make a program faster, you need a faster computer.要讓程式變快,就得換一台更快的電腦。
✓ Fact · 事實A computer twice as fast halves the time. Changing the method can turn a million steps into twenty.電腦快一倍,時間省一半。換一個方法,卻可以把一百萬步變成二十步。
✗ Myth · 迷思The halving method always works.每次砍一半的方法永遠管用。
✓ Fact · 事實It works only when things are in order. On boxes that are mixed up, it rules out the half where the answer is hiding.它只有在東西照順序排好時才管用。箱子弄亂之後,它會把藏著答案的那一半排除掉。
✗ Myth · 迷思The cleverer method is quicker every single time.比較聰明的方法,每一次都比較快。
✓ Fact · 事實If the number is in the first box, opening one by one takes 1 try and halving takes 4. Methods are compared by the most steps they could need, not by one lucky case.如果那個數剛好在第一個箱子,一個一個找只要 1 次,砍一半要 4 次。比較方法,比的是最多可能要幾步,不是某一次的運氣。
Remember It · 記憶口訣
An algorithm is the method. A program tells the computer how to follow it.
演算法是方法;程式是告訴電腦怎麼照做。
Each look rules out half.
每看一次,排除一半。
Halving needs sorted things.
砍一半的方法,東西要先排好。
A million boxes: at most 20.
一百萬個箱子:最多 20 次。
Before You Start · 動手之前
Classroom Activity 1 · 課堂活動一
You need · 準備材料
Steps · 步驟
With 16 cards in order, student B never needs more than 5 turns, and student A may need 16. Ask the class when A wins. In Taiwan’s junior high Information Technology curriculum, this lesson matches “Algorithms”: 資 A-IV-1, basic concepts of algorithms, and 資 A-IV-3, an introduction to basic algorithms: searching and sorting. Sequential search and binary search are named in the senior high curriculum.
16 張照順序排好的卡片,B 同學最多翻 5 張,A 同學可能要翻 16 張。問問全班:什麼時候 A 會贏?對照十二年國教國中「資訊科技」的學習內容,這一課對應「演算法」主題:資 A-IV-1 演算法基本概念,以及資 A-IV-3 基本演算法的介紹(搜尋、排序)。「循序搜尋與二元搜尋」這兩個名稱出現在高中階段的課綱。
Classroom Activity 2 · 課堂活動二
You need · 準備材料
Steps · 步驟
For 1,000 pages, exact halving never needs more than 10 openings; going page by page could take 1,000. Your hands are not exact, so your counts may be a little higher. Then play “Guess My Number” on this page and see whether you can always finish within 7 guesses.
1,000 頁的字典,精確地對半切最多只要翻 10 次;一頁一頁翻可能要 1,000 次。手沒辦法切得那麼準,所以你們的次數可能多一點。接著玩這一頁的「猜猜我想的數」,看看能不能每次都在 7 次以內猜到。
Go Further · 延伸閱讀
Sources · 資料出處
Facts on this page were checked against these sources (October 2026); the box model is our own illustration, and every count is tested · 本頁的事實依下列資料查證(2026 年 10 月);箱子模型是我們自己的示意,每一個步數都有測試