Developing Algorithms
| English | Chinese | Pinyin |
|---|---|---|
| algorithm | 算法 | suàn fǎ |
| finite | 有限的 | yǒu xiàn de |
| sequencing | 顺序 | shùn xù |
| flowchart | 流程图 | liú chéng tú |
| natural language | 自然语言 | zì rán yǔ yán |
| same result | 相同结果 | xiāng tóng jié guǒ |
| refine | 改进 | gǎi jìn |
| efficient | 高效 | gāo xiào |
What is an algorithm?
- An algorithm 算法 is a finite 有限的, step-by-step set of instructions to complete a task.
- "Finite" means it always ends after a limited number of steps.
- A recipe, a route to school, and a sorting method are all algorithms.
- Every program is built from algorithms.
An algorithm is:
"Finite" means it always ends after a limited number of steps.
Three building blocks
- Every algorithm can be built from three basic structures:
- sequencing 顺序: doing steps one after another;
- selection: choosing between paths;
- iteration: repeating steps.
Sequencing, selection, or iteration?
Every algorithm is built from three structures: sequencing (steps in order), selection (choosing a path), and iteration (repeating steps).
Which are the three building blocks of algorithms? (Select all that apply)
Sequencing, selection, and iteration build every algorithm.
A flowchart, pseudocode, and natural language can all express:
All three describe the same steps differently.
Two different algorithms can produce the same correct result, one faster than the other.
Neither is "more correct" if both give the right answer.
Ways to express it
- You can express an algorithm as pseudocode, as a flowchart 流程图 (boxes and arrows), or in plain natural language 自然语言.
- All three describe the same steps in different forms.
- Different algorithms can give the same result 相同结果 — one short but slow, another longer but fast.
- Neither is "more correct" if both give the right answer.
The "largest of three" algorithm runs on a=4, b=9, c=6. What does it output?
Start 4; 9 > 4 → 9; 6 > 9 is false → stays 9.
Improving an algorithm step by step to be correct, clear, and efficient is called ______.
Refining follows testing, making the algorithm better each pass.
Refine for efficiency
- We refine 改进 an algorithm so it is correct, clear, and efficient 高效.
- Refining means improving it step by step after testing.
Largest of three. largest ← a; IF b > largest: largest ← b; IF c > largest: largest ← c; DISPLAY largest. For a=4, b=9, c=6: start 4; 9 > 4 → largest 9; 6 > 9 is false → stays 9. Output 9. This uses sequencing and selection.
An algorithm is a finite set of steps, built from three structures: sequencing, selection, and iteration. You can express it as pseudocode, a flowchart, or natural language. Different algorithms can give the same result, so we refine them to be correct, clear, and efficient.