Algorithms and flowcharts

Advanced

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.

For:Secondary 1 Information & Communication Technology · Unit:Coding basics · Lesson 7 of 13 in the learning path

After this lesson, you can:
  • Algorithm = finite, clear, ordered steps
  • Oval start/end, rectangle process, diamond decision, parallelogram input/output
  • Diamonds have two exits; one start per chart
資訊及通訊科技Information & Communication Technology
Before this lesson you should know: The cloud and online services

§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

A
Algorithm演算法

Clear step-by-step instructions to solve a problem: finite and ordered.

F
Flowchart流程圖

A diagram of an algorithm using standard shapes and arrows.

T
Terminator (oval)起止框(橢圓)

Marks the Start or End of the flow.

P
Process box (rectangle)處理框(矩形)

An action or calculation, e.g. add 10 to the total.

D
Decision diamond決策框(菱形)

A yes/no question with two exits.

I
Input/Output (parallelogram)輸入輸出框(平行四邊形)

Getting data in or showing a result.

A
Arrow (flow line)箭頭(流程線)

The symbol showing the direction of flow; every line needs an arrowhead.

P
Program code程式碼

Instructions written in a programming language; once the flowchart is clear, it is translated into code for the computer.

3Step by step Steps

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

流程圖符號:四種磚頭 Flowchart symbols開始/結束處理 process判斷?輸入輸出圓角方形菱形平行四邊形例:計平均分流程開始 → 輸入三科分數 → 相加÷3(處理)→ 顯示結果 → 結束規矩:箭嘴表示行嘅次序;判斷菱形一定要有兩條出路(是/否)畫流程圖=諗清楚先寫 code——程式設計師嘅草稿
Fig. 1: Flowchart symbols

5Worked example Example

Example: describe in words a flowchart that checks whether a mark passes (50 or above).

  1. First draw the Start oval, then a parallelogram for 'input the mark', because the mark is data entering the program from outside.
  2. Next draw the diamond with the condition 'mark ≥ 50?'; it must have two exits, labelled yes and no.
  3. On the yes side, output 'Pass'; on the no side, output 'Fail' — the two branches must not share one output.
  4. Finally, both branches join arrows to the End oval; after drawing, follow the arrows from Start once to confirm no path is left hanging.
  5. 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

✗ Drawing decisions as rectangles.
✓ Decisions need a diamond — two exits (yes/no); a rectangle has only one path.
✗ Thinking algorithms need a computer.
✓ An algorithm is just the method: recipes and game guides are algorithms; computers only run them fast.
✗ Saying step order does not matter.
✓ Wrong order, wrong result — cracking the egg before boiling the water is not the same as the reverse.
✗ Drawing flow lines without arrowheads.
✓ Every flow line needs an arrow; without a direction, no one can tell which step comes first or whether the flow loops back.

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

Other subjects in this grade

Same subject, other grades