This handout teaches Theme B1, Computational thinking, for the course first assessed in 2027. All of it is SL and HL content.
Prerequisites: none beyond basic arithmetic. Theme B2 then turns these ideas into Python code.
IB Computer Science SL · Topic 5
4:48
Computational thinking
Your school wants a canteen app. Students order lunch on a phone, pay from a card balance, and the kitchen sees the orders. Nobody can write that in one go.…
English narration · English and 中文 subtitles you can switch
This handout teaches Theme B1, Computational thinking, for the course first assessed in 2027. All of it is SL and HL content.
Prerequisites: none beyond basic arithmetic. Theme B2 then turns these ideas into Python code.
Your school wants a canteen app: students order lunch on a phone, pay from a card balance, and the kitchen sees the orders. Nobody can write that in one go. Computational thinking is the set of habits that turns a big, vague problem into small, exact steps a computer can follow.

| Approach | What you do | Canteen example |
|---|---|---|
| decomposition 分解 | split the problem into smaller sub-problems | log in, choose meal, pay, kitchen |
| pattern recognition 模式识别 | spot what sub-problems have in common | every screen shows a list and takes a choice |
| abstraction 抽象 | keep the details that matter, drop the rest | a meal is a name, a price and allergens, not its photo or recipe |
| algorithmic design 算法设计 | write exact steps for each sub-problem | the steps to deduct a price from a balance |

Decomposition lets a team share the work, test each part separately, and reuse parts: the "check balance" step serves both logging in and paying.
Pattern recognition finds the same structure in different places, so one solution can be reused. Calculating a total for a lunch order, a sports-kit order and a trip payment is the same pattern: add the prices, then deduct from a balance.
Abstraction builds a model 模型 that leaves out what does not affect the problem. A map of the school for fire drills shows exits and corridors, not wall colours. Too much abstraction loses something that matters: a canteen model with no allergens would be dangerous.
| English |
|---|
| decomposition/ˌdiːkɒmpəˈzɪʃn/ |
| pattern recognition/ˈpætn ˌrekəɡˈnɪʃn/ |
| abstraction/əbˈstrækʃn/ |
| algorithmic design/ˌælɡəˈrɪθmɪk dɪˈzaɪn/ |
| model/ˈmɒdl/ |
An algorithm 算法 is a finite sequence of exact steps that solves a problem. A good algorithm is:
"Add some salt" is not an algorithm step; "add 2 g of salt" is.
Every algorithm is built from three constructs:
| Construct | Meaning | Flowchart shape |
|---|---|---|
| sequence 顺序 | steps run one after another | arrows joining boxes |
| selection 选择 | a decision chooses the path | a diamond with yes and no |
| iteration 迭代 | steps repeat | an arrow looping back |

A flowchart 流程图 shows an algorithm as shapes joined by arrows.
| Symbol | Use |
|---|---|
| rounded rectangle (terminator) | START and END |
| parallelogram | INPUT or OUTPUT |
| rectangle | a process, such as an assignment |
| diamond | a decision with yes and no exits |

max ← 0 means "store 0 in max": the arrow is assignment.
A trace table 跟踪表 records each variable after each step. For the inputs 62, 85, 71:
count |
count < 3? |
mark |
mark > max? |
max |
Output |
|---|---|---|---|---|---|
| 0 | 0 | ||||
| 0 | yes | 62 | yes | 62 | |
| 1 | yes | 85 | yes | 85 | |
| 2 | yes | 71 | no | 85 | |
| 3 | no | 85 |
The algorithm outputs 85. Note the trap: if every mark could be negative, starting max at 0 gives a wrong answer; starting it at the first mark is safer.
The same algorithm written as pseudocode 伪代码, structured English that is close to code but not tied to one language:
max ← 0
count ← 0
loop while count < 3
input MARK
if MARK > max then
max ← MARK
end if
count ← count + 1
end loop
output max
| English |
|---|
| algorithm/ˈælɡərɪθəm/ |
| input/ˈɪnpʊt/ |
| output/ˈaʊtpʊt/ |
| sequence/ˈsiːkwəns/ |
| selection/sɪˈlekʃn/ |
| iteration/ˌɪtəˈreɪʃn/ |
| flowchart/ˈfləʊtʃɑːt/ |
| trace table/treɪs ˈteɪbl/ |
| pseudocode/ˈsuːdəʊkəʊd/ |
Choose tests from the problem's specification 规格说明, not just the cases you expect. For a mark from 0 to 100:
| Type | Purpose | Examples |
|---|---|---|
| normal data 正常数据 | typical valid data | 45, 72 |
| boundary data 边界数据 | the edges of the valid range, and just outside | 0, 100, -1, 101 |
| invalid data 无效数据 | data that must be rejected | -20, 150, "ten" |
One passing test proves only that the algorithm works for that input. When a test fails, decide whether the algorithm is wrong, the implementation (the code) does not match the algorithm, or the requirement never covered that case.
Two correct algorithms can differ greatly in speed. Finding a name in a register of 1000 by checking each in turn takes up to 1000 steps; halving a sorted register each time (binary search, B2) takes about 10. Theme B2 measures this with Big O.
| English |
|---|
| specification/ˌspesɪfɪˈkeɪʃn/ |
| normal data/ˈnɔːml ˈdeɪtə/ |
| boundary data/ˈbaʊndəri ˈdeɪtə/ |
| invalid data/ɪnˈvælɪd ˈdeɪtə/ |
Answers.
max becomes 40 after the first input; the second 40 is not greater than 40, so max stays 40; 90 is greater, so max becomes 90. Output 90.max stays 0. Output 0, which is not one of the marks: max should start at the first input, not 0.count ← 0 → INPUT n → decision n = 0?; no: count ← count + 1, INPUT n, back to the decision; yes: OUTPUT count → END.Loading subjects…