Algorithms and flowcharts
AdvancedAn algorithm is a clear step-by-step way to solve a problem, like a recipe. A flowchart draws it: oval for start/end, rectangle for actions, diamond for decisions, parallelogram for input/output.
- Algorithm = finite, clear, ordered steps
- Oval start/end, rectangle process, diamond decision, parallelogram input/output
- Diamonds have two exits; one start per chart
§Text Passage
1An algorithm is a clear sequence of steps for solving a problem, like a recipe: list the ingredients, follow the steps in order, and the dish is done. A sound algorithm must be clear, finite and ordered — every step specific, the number of steps limited, the order fixed, and swapping the order may cause errors. A flowchart draws it out: ovals for start and end, rectangles for processing, diamonds for decisions, arrows for the direction of flow.
2Before writing code, designing the algorithm and sketching the flowchart exposes logic errors early and saves debugging time later. Classic examples include finding the highest scorer in a class, computing subject averages, or sorting exam marks from high to low; each should begin by thinking through input, processing and output, then turning them into concrete steps — only then write the code, and mistakes become far fewer.
3Hong Kong daily life is full of them: the MTR journey planner proposes routes within seconds, the Octopus system computes the cheapest fare automatically, and food-delivery platforms arrange delivery routes for thousands of orders — all algorithms at work. Learning to think in orderly steps and break big problems into small ones is the common foundation of programming and computational thinking, and it helps problem-solving in other subjects too.
1Summary 重點摘要
An algorithm is a clear step-by-step way to solve a problem, like a recipe. A flowchart draws it: oval for start/end, rectangle for actions, diamond for decisions, parallelogram for input/output.
2Vocabulary cards Vocabulary
Clear step-by-step instructions to solve a problem: finite and ordered.
A diagram of an algorithm using standard shapes and arrows.
Marks the Start or End of the flow.
An action or calculation, e.g. add 10 to the total.
A yes/no question with two exits.
Getting data in or showing a result.
The symbol showing the direction of flow; every line needs an arrowhead.
Instructions written in a programming language; once the flowchart is clear, it is translated into code for the computer.
3Step by step Steps
- Three requirementsA sound algorithm must meet three requirements. First, clear: every step is exact and specific, never vague, so anyone following it gets the same result. Second, finite: the number of steps is limited, so it must finish and never loop forever. Third, ordered: the sequence is fixed, and swapping steps may break it — putting shoes on before socks does not work. A recipe helps here: one that never ends, or adds salt 'by mood', is not a sound algorithm. In answers, state all three requirements and attach a short example to each.
- Everyday example: making lemon teaAlgorithms do not need computers — daily life is full of them. Take making lemon tea: after starting, boil the water; then decide 'is there a lemon?' If yes, put it in; if no, buy one first and carry on; finally add the tea, and it is done. This has step-by-step instructions plus one decision branch, so it is already an algorithm. An algorithm is simply 'a clear sequence of steps for solving a problem' — the design before coding, even the steps for teaching a classmate to fold a paper crane, all fit the definition.
- Flowchart symbolsA flowchart expresses an algorithm with five standard symbols: an oval for start or end; a rectangle for process — an action or calculation; a diamond for decision, with yes and no paths; a parallelogram for input or output; and arrows for the direction of flow. Each symbol has its own job and must not be mixed up — a decision can never be drawn as a rectangle, nor input as one either. Memory trick: 'asking a question' takes a diamond, 'doing something' takes a rectangle, and 'data coming in or going out' takes a parallelogram.
- Drawing rulesDrawing a flowchart follows several rules: exactly one start; every arrow must show its direction; and every diamond must have two exits — yes and no — never just one. For a pass/fail check, the diamond must split into a pass path and a fail path, and both must finally reach the End symbol before the chart is complete. Common errors: forgetting the start or end oval, arrows without direction, or one branch left hanging after a decision. After drawing, follow the arrows from start to end once, and these problems will show up.
- Why draw firstSketching the flowchart before coding makes the logic clear and stops you getting lost halfway; a program is simply the flowchart translated into code. For example, with the grading chart finished first, no mark band is missed when coding, and debugging is faster too, because every branch can be checked against the chart. A Hong Kong example: the MTR journey planner proposes routes within seconds — a designed algorithm at work behind the scenes. Design first, code later: it is every programmer's habit and the core of computational thinking.
- Drawing a loop on a flowchartRepeated work appears in a flowchart as a 'return arrow': the flow line bends from below back upward, forming a loop. To stack 10 blocks: a rectangle 'stack one block', then a diamond 'ten blocks yet?' — when the answer is no, the arrow bends back up to 'stack one block'; when yes, the arrow goes on to the end. A diamond exit bending back upward is the mark of a loop. When drawing, write the condition beside the diamond clearly, and make sure the loop finally has an exit — otherwise the flow circles forever.
4Diagrams Diagrams
5Worked example Example
Example: describe in words a flowchart that checks whether a mark passes (50 or above).
- First draw the Start oval, then a parallelogram for 'input the mark', because the mark is data entering the program from outside.
- Next draw the diamond with the condition 'mark ≥ 50?'; it must have two exits, labelled yes and no.
- On the yes side, output 'Pass'; on the no side, output 'Fail' — the two branches must not share one output.
- Finally, both branches join arrows to the End oval; after drawing, follow the arrows from Start once to confirm no path is left hanging.
- Answer: The order is: Start (oval), input the mark (parallelogram), 'mark ≥ 50?' (diamond), yes outputs 'Pass' and no outputs 'Fail', and both branches finally reach End (oval). Key points: the diamond must have two exits (yes and no), and every arrow must finally reach the End symbol before the chart is complete.
6Common mistakes Mistakes
7Quick check Quick check
Q1In a flowchart, a diamond means…? A. start B. decision C. input
Q2Which shape should 'input the mark' use?
Q3How many 'start' points may an algorithm have?
Q4Which shape marks 'start' and 'end'?
Q5Write the three main steps of an algorithm that totals five subject marks.
8Recap Recap
- Algorithm = finite, clear, ordered steps
- Oval start/end, rectangle process, diamond decision, parallelogram input/output
- Diamonds have two exits; one start per chart
- Flowchart first, code second — logic stays clear
- Recipes and game guides are algorithms too — clear thinking needs no computer