Skip to content
Subjects

A-Level Computer Science

  • 1 Information representation
    1.1

    Number systems

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of binary magnitudes and the difference between binary prefixes and decimal prefixes Understand the difference between and use: • kibi and kilomebi and megagibi and gigatebi and tera
    Show understanding of different number systems Use the binary, denary, hexadecimal number bases and Binary Coded Decimal (BCD) and one’s complement and two’s complement representation for binary numbers
    Convert an integer value from one number base/ representation to another
    Perform binary addition and subtraction Using positive and negative binary integers
    Show understanding of how overflow can occur
    Describe practical applications where Binary Coded Decimal (BCD) and Hexadecimal are used
    Show understanding of and be able to represent character data in its internal binary form, depending on the character set used Students are expected to be familiar with ASCII (American Standard Code for Information Interchange), extended ASCII and Unicode. Students will not be expected to memorise any particular character codes

    Source: Cambridge International syllabus

    Counting in binary: 0 to 15

    The three number systems 数制 you must use:

    • denary 十进制 (decimal, base 10) — uses digits 0–9. Place values are powers of ten.
    • binary 二进制 (base 2) — uses 0 and 1. Place values are powers of two. Every byte 字节 is 8 bits.
    • hexadecimal 十六进制 (base 16) — uses 0–9 then A–F for 10–15. Each hex digit 数位 stands for exactly 4 bits.
    Beads on a traditional abacus
    An abacus represents numbers by place value — the same idea behind decimal, binary and hexadecimal

    Conversions

    Denary → binary: keep dividing by 2 and record the remainders, read bottom-up. Or subtract the largest place value 位值 (power of 2) that fits.

    Example: $558_{10}$: $558 = 512 + 32 + 8 + 4 + 2 = 2^{9} + 2^{5} + 2^{3} + 2^{2} + 2^{1}$. In 12 bits: 0010 0010 1110.

    Binary → hex: group the bits into nibbles 半字节 (4 bits) from the right and convert each. 0010 0010 11102 2 E22E.

    Hex → binary: replace each hex digit with its 4-bit pattern. Hex → denary: multiply each digit by its place value. 22E $= 2 \times 256 + 2 \times 16 + 14 = 558$.

    Worked example. Convert denary 200 to 8-bit binary, then to hexadecimal.

    $200 = 128 + 64 + 8$, so the binary is 11001000. In nibbles, 1100 1000 $= 12$ and $8$, i.e. $\text{C}$ and $8$, so the hexadecimal is C8.

    A binary place-value chart for 200: the columns 128, 64, 32, 16, 8, 4, 2, 1 hold the bits 1,1,0,0,1,0,0,0; the two 4-bit nibbles 1100 and 1000 become the hex digits C and 8, so 200 = 11001000 = C8
    Reading 200 from its place values, then grouping the bits into nibbles to get hex C8

    Binary vs decimal prefixes

    Two prefix families look similar but differ — decimal (powers of 10) and binary (powers of 2):

    Decimal (SI) Binary (memory)
    kilo $= 10^{3}$ kibi (Ki) $= 2^{10} = 1024$
    mega $= 10^{6}$ mebi (Mi) $= 2^{20}$
    giga $= 10^{9}$ gibi (Gi) $= 2^{30}$
    tera $= 10^{12}$ tebi (Ti) $= 2^{40}$

    So a tebibyte (TiB) is slightly more than a terabyte (TB). A "1 TB" drive holds $10^{12}$ bytes, but an operating system that reports in TiB shows a smaller number.

    Explore

    Binary, denary and hex

    Type a number and see it in binary, denary and hexadecimal at once — and how the place values add up.

    Vocabulary Train
    English Chinese Pinyin
    number system 数制 shù zhì
    denary 十进制 shí jìn zhì
    binary 二进制 èr jìn zhì
    byte 字节 zì jié
    bit wèi
    hexadecimal 十六进制 shí liù jìn zhì
    digit 数位 shù wèi
    place value 位值 wèi zhí
    nibble 半字节 bàn zì jié
    1.1

    Binary arithmetic

    Binary addition

    Add column by column from the right, carrying as in denary:

    Bit A Bit B Carry in Sum bit Carry out
    0 0 0 0 0
    0 0 1 1 0
    0 1 0 1 0
    0 1 1 0 1
    1 1 0 0 1
    1 1 1 1 1

    Overflow 溢出 happens when the result needs more bits than the register 寄存器 can hold — the carry-out of the leftmost column is the overflow bit.

    Binary subtraction

    The usual way is two's complement 补码 addition: to do $A - B$, form the two's complement of $B$ (invert every bit and add 1), then add, and discard any final carry-out.

    To subtract $00011110$ from $01100100$ (unsigned 8-bit):

    • two's complement of $00011110$: invert → $11100001$, add 1 → $11100010$.
    • add to $01100100$: result $1\,01000110$ (9 bits) — discard the leading 1 → $01000110 = 70_{10}$. Check: $100 - 30 = 70$. ✓

    Two's complement signed integers

    In an $n$-bit two's-complement number:

    • the most significant bit 最高有效位 (MSB) is the sign bit 符号位: 0 = positive, 1 = negative.
    • to read a negative number: invert every bit, add 1, then negate.

    So $11100010$ is negative; invert → $00011101$, add 1 → $00011110 = 30$, so it is $-30$. This is a signed integer 有符号整数 (unlike an unsigned 无符号 one). The range for $n$ bits is $-2^{n-1}$ to $+2^{n-1} - 1$; for 8 bits, $-128$ ($10000000$) to $+127$ ($01111111$).

    An 8-bit two's-complement number line from -128 (10000000) to +127 (01111111); numbers with sign bit 1 are negative and those with sign bit 0 are positive, with -1 = 11111111 sitting just below 0 = 00000000
    8-bit two's complement: the sign bit splits the range into negative ($-128$ to $-1$) and positive ($0$ to $127$)

    Worked example. What denary value does the 8-bit two's-complement number $10110100$ represent?

    The MSB is 1, so it is negative. Invert → $01001011$, add 1 → $01001100 = 76$, so the value is $-76$. Check with place values: $-128 + 32 + 16 + 4 = -76$.

    Overflow in signed arithmetic happens when the true result falls outside this range — spotted when the sign bit flips wrongly (two positives giving a negative, or two negatives giving a positive).

    One's complement

    Before two's complement, an older scheme called one's complement 反码 represented a negative number by simply inverting every bit of the positive — there is no "add 1" step.

    • $+30 = 00011110$, so in one's complement $-30 = 11100001$ (just the inverse).
    • Drawback: it has two zeros$00000000$ ($+0$) and $11111111$ ($-0$) — which wastes a bit pattern and makes arithmetic awkward.

    Two's complement (invert and add 1) removes the negative zero: it has a single zero and lets addition and subtraction use the same circuit. That is why modern computers store signed integers in two's complement, not one's complement.

    Explore

    Binary & signed integers

    byte = Σ place values

    See how an 8-bit pattern maps to a number (and how it would overflow past 255).

    Explore

    Two's complement signed bits

    The leftmost bit carries a negative place value. Flip any bit — or hit Negate (invert every bit, then add 1) — and watch the signed value change.

    Vocabulary Train
    English Chinese Pinyin
    overflow 溢出 yì chū
    register 寄存器 jì cún qì
    two's complement 补码 bǔ mǎ
    most significant bit 最高有效位 zuì gāo yǒu xiào wèi
    sign bit 符号位 fú hào wèi
    signed integer 有符号整数 yǒu fú hào zhěng shù
    unsigned 无符号 wú fú hào
    one's complement 反码 fǎn mǎ
    1.1

    Binary Coded Decimal (BCD)

    In BCD 二进码十进数, each denary digit is written as its own 4-bit pattern. The number $93$ is 1001 0011 in BCD — not binary 93 ($01011101$). Each nibble uses only 0–9; patterns $1010$$1111$ are invalid.

    BCD reading: 0010 0111 0101 → 2, 7, 5 → 275.

    Use: calculators, digital clocks, and devices that show denary digits — each digit drives a 7-segment display 七段显示器. Currency code often uses BCD to avoid the rounding errors of converting fractions like 0.1 to binary.

    A single-digit seven-segment LED display component, showing its seven separate bars
    A seven-segment display shows one denary digit, often driven by BCD
    Vocabulary Train
    English Chinese Pinyin
    BCD 二进码十进数 èr jìn mǎ shí jìn shù
    7-segment display 七段显示器 qī duàn xiǎn shì qì
    1.1

    Hexadecimal — practical uses

    Hex is a compact way to write binary (1 hex digit = 4 bits):

    A byte splits into two nibbles; each nibble is one hexadecimal digit
    A byte is two nibbles; each nibble is one hex digit
    • memory addresses 内存地址 in low-level programming — 0x7FFE.
    • colour values in HTML/CSS — #FF8800.
    • MAC addressesAC:DE:48:00:11:22.

    Hex does not change the stored data — it just makes binary easier for humans.

    Vocabulary Train
    English Chinese Pinyin
    memory address 内存地址 nèi cún dì zhǐ
    1.1

    Character codes

    Computers store text as numbers; each character has a numeric code point 码点 set by a character set 字符集.

    ASCII

    • ASCII uses 7 bits — 128 code points. Basic Latin letters, digits, punctuation, and control codes.
    • Extended ASCII uses 8 bits — 256 code points; the lower 128 match ASCII, the upper 128 vary by region.
    A small ASCII table: the character A is code 65 = 01000001, a is 97 = 01100001, the digit 0 is 48 = 00110000, and space is 32 = 00100000
    Each character is stored as a number — a few ASCII code points in denary and binary

    Unicode

    • Unicode is a universal character set covering almost every script, plus symbols and emoji.
    • common encodings 编码: UTF-8 (1–4 bytes, ASCII-compatible), UTF-16 (2 or 4 bytes), UTF-32 (fixed 4 bytes).

    Why Unicode beats ASCII

    • it represents far more characters (every script, emoji); ASCII covers only basic English.
    • files are portable with no code-page confusion, and allow multilingual text in one document.
    • trade-off: Unicode files are usually larger for English-only text.
    Explore

    A character is stored as a number

    Each character has a code number — 'A' is 65. Flip the bits to see that code in binary and hex, exactly how the computer holds it.

    Vocabulary Train
    English Chinese Pinyin
    code point 码点 mǎ diǎn
    character set 字符集 zì fú jí
    encoding 编码 biān mǎ
    1.2

    Bitmap images

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of how data for a bitmapped image are encoded Use and understand the terms: pixel, file header, image resolution, screen resolution, colour depth / bit depth
    Perform calculations to estimate the file size for a bitmap image
    Show understanding of the effects of changing elements of a bitmap image on the image quality and file size Use the terms: image resolution, colour depth / bit depth
    Show understanding of how data for a vector graphic are encoded Use the terms: drawing object, property, drawing list
    Justify the use of a bitmap image or a vector graphic for a given task
    Show understanding of how sound is represented and encoded Use the terms: sampling, sampling rate, sampling resolution, analogue and digital data
    Show understanding of the impact of changing the sampling rate and resolution Including the impact on file size and accuracy

    Source: Cambridge International syllabus

    A bitmap 位图 image (also called a bitmapped image) stores the colour of every pixel 像素 in a grid. At the start of the file a file header 文件头 records the image's metadata — its width, height and colour depth — so software knows how to read the pixel data that follows.

    • image resolution 图像分辨率: the bitmap's own size, width × height in pixels (e.g. 1920 × 1080).
    • screen resolution 屏幕分辨率: the width × height the display can show. If an image's resolution is larger than the screen it is scaled down to fit; a low-resolution image looks blocky when stretched onto a higher-resolution screen.
    • colour depth 颜色深度 (bit depth 位深度): bits per pixel. 1 bit → black/white; 8 bits → 256 colours; 24 bits → 16.7 million ("true colour").
    The same disc stored on three pixel grids, A to C, getting blockier as the pixels grow larger and fewer
    The same image stored at three resolutions, from high (A) to low (C): fewer, larger pixels mean less detail

    File size

    $$\text{size in bits} = \text{width} \times \text{height} \times \text{bit depth}.$$

    Divide by 8 for bytes, by 1024 for KiB, etc. Example: a $3000 \times 2000$ image at 24 bpp is $3000 \times 2000 \times 24 = 1.44 \times 10^{8}$ bits $\approx 17.2\ \text{MiB}$.

    Changing settings

    • lower resolution → smaller file, less detail (looks blocky when enlarged).
    • lower colour depth → smaller file, but smooth shades show banding.
    • higher of either → larger file, better quality.
    Vocabulary Train
    English Chinese Pinyin
    bitmap 位图 wèi tú
    pixel 像素 xiàng sù
    file header 文件头 wén jiàn tóu
    image resolution 图像分辨率 tú xiàng fēn biàn lǜ
    screen resolution 屏幕分辨率 píng mù fēn biàn lǜ
    colour depth 颜色深度 yán sè shēn dù
    bit depth 位深度 wèi shēn dù
    1.2

    Vector graphics

    A vector graphic 矢量图形 stores the instructions to draw the image as a drawing list 绘图列表 — an ordered list of drawing objects 绘图对象 (geometric primitives 图元: lines, curves, polygons, circles). Each drawing object has properties 属性 such as colour, fill, line width and position (coordinates). To show it, the program renders 渲染 the drawing list at any resolution needed.

    A simple house drawing made from a rectangle body, triangle roof, circle window, door rectangle and a line, each labelled with its shape type and attributes
    A vector image is built from labelled geometric shapes, each with attributes

    Bitmap vs vector

    Task Better choice Why
    Photograph Bitmap Complex pixel-level detail can't be described as shapes.
    Logo, icon, sign Vector Sharp edges; scales to any size without blur.
    Engineering drawing Vector Precise geometry and scaling.
    Painting, texture Bitmap Smooth tonal detail per area.

    Vector advantage: it scales without losing quality — a vector logo stays sharp at any size, while a bitmap blurs when enlarged. Vector disadvantage: it cannot describe arbitrary pixel detail (photographs).

    Side by side, both enlarged: a bitmap diagonal is a jagged staircase of pixels, while a vector diagonal stays a smooth straight line
    Enlarged, a bitmap's pixels turn jagged; a vector stays smooth at any size
    Explore

    Computing concept lab

    Classify concrete examples by the computing idea they demonstrate.

    Vocabulary Train
    English Chinese Pinyin
    vector graphic 矢量图形 shǐ liàng tú xíng
    drawing list 绘图列表 huì tú liè biǎo
    drawing object 绘图对象 huì tú duì xiàng
    primitive 图元 tú yuán
    property 属性 shǔ xìng
    render 渲染 xuàn rǎn
    1.2

    Sound

    A continuous wave of analogue data 模拟数据 (the sound) is converted into digital data 数字数据 by sampling 采样:

    • sampling rate 采样率 — samples per second (Hz). CD quality is $44.1\ \text{kHz}$.
    • sampling resolution 采样分辨率 (bit depth) — bits per sample's amplitude 振幅. CD quality is 16 bits.
    A smooth analogue sound wave with vertical sample bars at regular time intervals, each bar reading the wave's amplitude
    Sampling a sound wave: its amplitude is read at each time interval

    File size

    $$\text{size in bits} = \text{sampling rate} \times \text{resolution} \times \text{duration} \times \text{channels}.$$

    A 10-second stereo CD clip: $44100 \times 16 \times 10 \times 2 = 14\,112\,000$ bits $\approx 1.68\ \text{MiB}$.

    Changing settings

    • higher sampling rate → captures higher pitches, larger file.
    • higher sample resolution → finer amplitude steps, less quantisation 量化 noise, larger file.
    • lower of either → smaller file, clear quality loss.

    (The sampling rate must be at least twice the highest frequency you want to keep.)

    Explore

    Sound sampling

    y = a sin(bt + c)

    Sampling measures a sound wave at regular intervals — a higher rate copies it more truly.

    Vocabulary Train
    English Chinese Pinyin
    analogue data 模拟数据 mó nǐ shù jù
    digital data 数字数据 shù zì shù jù
    sampling 采样 cǎi yàng
    sampling rate 采样率 cǎi yàng lǜ
    sampling resolution 采样分辨率 cǎi yàng fēn biàn lǜ
    amplitude 振幅 zhèn fú
    quantisation 量化 liàng huà
    1.3

    Compression

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the need for and examples of the use of compression
    Show understanding of lossy and lossless compression and justify the use of a method in a given situation
    Show understanding of how a text file, bitmap image, vector graphic and sound file can be compressed Including the use of run-length encoding (RLE)

    Source: Cambridge International syllabus

    Compression 压缩 reduces file size, saving storage and transmission bandwidth 带宽. Two kinds:

    • lossless 无损 — the original data is recovered exactly (text, programs, ZIP/PNG).
    • lossy 有损 — some detail is dropped for much smaller files (JPEG, MP3, video).

    When to use which

    • lossless for documents, source code, medical images — anything needing exact data.
    • lossy for streaming media. Real-time video streaming uses lossy compression because it must send huge amounts of data in real time over limited bandwidth; lossless would not shrink it enough. Raw HD video is gigabytes per minute, so without compression the picture would keep freezing.

    Lossless methods

    • run-length encoding 行程编码 (RLE): store "the next $n$ values are $x$" instead of repeating $x$. Great for flat areas; useless for noisy data.
    • dictionary methods 字典编码 (ZIP, PNG): replace repeated byte sequences with a short reference. Good for text and code.
    • Huffman coding 霍夫曼编码: give short codes to common symbols and long codes to rare ones, bringing the average code length near the data's entropy.
    An 8 by 8 black-and-white grid showing the letter F, with each row's binary pattern and its shorter run-length code listed beside it
    Run-length encoding of the letter F in an $8\times8$ black-and-white grid

    Lossy methods

    • images (JPEG): drop fine detail and colour differences the eye barely sees.
    • sound (MP3, AAC): drop pitches we hear less well, and quiet sounds hidden by louder ones.
    • video combines spatial 空间 compression (within each frame, like JPEG) with temporal 时间 compression (most frames store only the differences from the previous frame).
    A tree classifying compression into lossless (RLE, dictionary/ZIP/PNG, Huffman) and lossy (JPEG images, MP3/AAC sound, video) with examples under each branch
    Compression methods: lossless versus lossy, with common examples
    Explore

    Run-length encoding

    Watch a run of repeated symbols get squashed into a count — simple lossless compression.

    Vocabulary Train
    English Chinese Pinyin
    compression 压缩 yā suō
    bandwidth 带宽 dài kuān
    lossless 无损 wú sǔn
    lossy 有损 yǒu sǔn
    run-length encoding 行程编码 xíng chéng biān mǎ
    dictionary methods 字典编码 zì diǎn biān mǎ
    Huffman coding 霍夫曼编码 huò fū màn biān mǎ
    entropy shāng
    spatial 空间 kōng jiān
    temporal 时间 shí jiān
    1.3

    Exam tips

    • Show working for base conversions: denary → binary by place values, binary → hexadecimal in nibbles (groups of 4 bits).
    • For two's complement the MSB is negative; to negate, invert and add 1; watch for overflow when the sign bit flips wrongly.
    • Distinguish bitmap (pixels; file size $=$ width $\times$ height $\times$ colour depth) from vector (drawing commands; scales without loss).
    • Sound file size depends on sample rate $\times$ bit depth $\times$ time — more of each means better quality but a bigger file.
    • Compare lossless vs lossy compression and give a use for each.
  • 2 Communication
    2.1

    Networks: purpose and benefits

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the purpose and benefits of networking devices
    Show understanding of the characteristics of a LAN (local area network) and a WAN (wide area network)
    Explain the client-server and peer-to-peer models of networked computers Roles of the different computers within the network and subnetwork models Benefits and drawbacks of each model Justify the use of a model for a given situation
    Show understanding of thin-client and thick-client and the differences between them
    Show understanding of the bus, star, mesh and hybrid topologies Understand how packets are transmitted between two hosts for a given topology Justify the use of a topology for a given situation
    Show understanding of cloud computing Including the use of public and private clouds Benefits and drawbacks of cloud computing
    Show understanding of the differences between and implications of the use of wireless and wired networks Describe the characteristics of copper cable, fibre-optic cable, radio waves (including WiFi), microwaves, satellites
    Describe the hardware that is used to support a LAN Including switch, server, Network Interface Card (NIC), Wireless Network Interface Card (WNIC), Wireless Access Points (WAP), cables, bridge, repeater
    Describe the role and function of a router in a network
    Show understanding of Ethernet and how collisions are detected and avoided Including Carrier Sense Multiple Access/Collision Detection (CSMA/CD)
    Show understanding of bit streaming Methods of bit streaming, i.e. real-time and on-demand Importance of bit rates broadband speed on bit streaming
    Show understanding of the differences between the World Wide Web (WWW) and the internet
    Describe the hardware that is used to support the internet Including modems, PSTN (Public Switched Telephone Network), dedicated lines, cell phone network
    Explain the use of IP addresses in the transmission of data over the internet Including: • format of an IP address including IPv4 and IPv6 • use of subnetting in a network • how an IP address is associated with a device on a network • difference between a public IP address and a private IP address and the implications for security • difference between a static IP address and a dynamic IP address
    Explain how a Uniform Resource Locator (URL) is used to locate a resource on the World Wide Web (WWW) and the role of the Domain Name Service (DNS)

    Source: Cambridge International syllabus

    A network 网络 is a set of computing devices connected so they can communicate and share resources. Benefits:

    • sharing resources (printers, file servers, internet) — cheaper than equipping each computer.
    • sharing data — many users access the same files.
    • central management — install software, manage users and back up once on a server.
    • communication — email, video calls, messaging.
    • remote access — work from anywhere.
    Explore

    Network route lab

    Follow data from a device through network hardware and protocols.

    Vocabulary Train
    English Chinese Pinyin
    network 网络 wǎng luò
    2.1

    LAN vs WAN

    A local area network 局域网 (LAN) covers a small area — a home, office or school, usually owned by the organisation, with high data rates and low latency 延迟.

    A wide area network 广域网 (WAN) covers a large area — a city, country, or the world (the internet is the largest WAN). It uses telecom-company infrastructure — often the Public Switched Telephone Network 公共交换电话网 (PSTN), leased lines or fibre — with lower data rates and higher latency. A WAN connects LANs together.

    Several LAN sites spread across a large area, each joined through a central carrier WAN cloud, with one direct leased line between two distant sites
    A wide-area network links many systems across a large area
    Vocabulary Train
    English Chinese Pinyin
    local area network 局域网 jú yù wǎng
    latency 延迟 yán chí
    wide area network 广域网 guǎng yù wǎng
    PSTN 公共交换电话网 gōng gòng jiāo huàn diàn huà wǎng
    2.1

    Client-server and peer-to-peer

    Client-server

    • powerful machines act as servers 服务器, providing services (files, web pages, email).
    • other machines are clients 客户端 that request services.
    • central and easy to manage, but the server is a single point of failure unless backed up.
    A desktop, laptop and tablet client send requests through the internet to one central server, which sends responses back
    In a client-server network, clients request services from a central server

    Peer-to-peer (P2P)

    • all machines are equal peers; each can be both client and server (peer-to-peer 对等网络).
    • resources are spread across the peers — no central server. Robust to one failure, but harder to keep secure and consistent.
    Six peer computers in a ring, each linked directly to every other peer, with no central server; every peer is both client and server
    In a peer-to-peer network, every node is both client and server
    Vocabulary Train
    English Chinese Pinyin
    server 服务器 fú wù qì
    client 客户端 kè hù duān
    peer-to-peer 对等网络 duì děng wǎng luò
    2.1

    Thin and thick clients

    A thin client 瘦客户端 does little processing locally and relies on a powerful server (web terminals, remote desktops). A thick client 胖客户端 has strong local processing and storage and runs full applications itself (a normal desktop PC).

    Feature Thin client Thick client
    Local processing minimal substantial
    Local storage minimal substantial
    Reliance on network high lower
    Server load high lower
    Vocabulary Train
    English Chinese Pinyin
    thin client 瘦客户端 shòu kè hù duān
    thick client 胖客户端 pàng kè hù duān
    2.1

    Network topologies

    The topology 拓扑 is how the nodes and links are arranged.

    • bus 总线 — all devices on one shared cable. Cheap; the whole LAN fails if the bus fails; performance drops as more devices share the bandwidth 带宽.
    • star 星形 — every device connects to a central switch. One device failing does not affect others; the switch failing brings all down. Most common today.
    • mesh 网状 — every device links directly to others, with many paths. Very fault-tolerant 容错 (traffic reroutes) but needs lots of cabling.
    • hybrid — a mix (a star in each office, mesh links between offices).
    Six computers each connected by a drop cable to one shared backbone cable, with a terminator block at each end
    Bus topology: all devices share one cable with a terminator at each end
    Five computers each connected by its own dedicated cable to a central hub or switch
    Star topology: every device connects to a central hub or switch
    Six computers in a ring with a direct cable between every pair of devices
    Mesh topology: every device links directly to the others
    Three star clusters, each a switch with its own computers, all joined by one shared bus backbone with a terminator at each end
    Hybrid topology: star clusters joined by a central bus
    Explore

    Compare the network topologies

    Tap through the four topologies. Each trades off cost, speed and how well it survives a failure — notice what breaks the whole network in each one.

    Vocabulary Train
    English Chinese Pinyin
    topology 拓扑 tuò pū
    bus 总线 zǒng xiàn
    bandwidth 带宽 dài kuān
    star 星形 xīng xíng
    mesh 网状 wǎng zhuàng
    fault-tolerant 容错 róng cuò
    2.1

    Cloud computing

    Cloud computing 云计算 delivers computing services (servers, storage, software) over the internet, hosted by a third party. Benefits: scalability 可扩展性 (pay for what you need), lower cost, access from anywhere, and reliable redundant data centres. Drawbacks: needs internet, your data is held by a third party, and possible vendor lock-in.

    Vocabulary Train
    English Chinese Pinyin
    cloud computing 云计算 yún jì suàn
    scalability 可扩展性 kě kuò zhǎn xìng
    2.1

    Wired vs wireless

    • wired (Ethernet 以太网 over twisted-pair 双绞线 or fibre-optic 光纤): higher speed, lower latency, fewer errors, more secure.
    • wireless (Wi-Fi, Bluetooth, cellular): no cables, devices can move, but slower, prone to interference and eavesdropping.

    For the same generation, wired wins on speed and reliability; wireless wins on convenience.

    Vocabulary Train
    English Chinese Pinyin
    Ethernet 以太网 yǐ tài wǎng
    twisted-pair 双绞线 shuāng jiǎo xiàn
    fibre-optic 光纤 guāng xiān
    2.1

    LAN hardware

    • network interface card 网络接口卡 (NIC) — lets a device send and receive on the network; has a unique MAC address MAC地址 (a 48-bit hardware address). A wireless device uses a wireless network interface card 无线网络接口卡 (WNIC).
    • switch 交换机 — forwards Ethernet frames only to the port for the destination MAC address.
    • hub 集线器 — a simpler device that copies traffic to all ports (now obsolete).
    • wireless access point 无线接入点 (WAP) — lets wireless clients join a wired LAN.
    • cabling — twisted-pair for short runs; fibre-optic for longer, faster runs.
    A 5-port gigabit Ethernet switch on a white background, with five numbered RJ-45 ports along the front and a power light
    A network switch: each device's cable plugs into one of its ports
    A black Ethernet patch cable on a white background, with an RJ-45 plug at each end showing the gold metal contacts and the locking clip
    An RJ-45 plug on a twisted-pair Ethernet cable
    A frame addressed to computer C arrives at a switch, which forwards it out only the port for C, leaving the cables to A, B and D unused
    A switch sends each frame only to the port for its destination
    Vocabulary Train
    English Chinese Pinyin
    network interface card 网络接口卡 wǎng luò jiē kǒu kǎ
    MAC address MAC地址 MAC dì zhǐ
    switch 交换机 jiāo huàn jī
    hub 集线器 jí xiàn qì
    wireless access point 无线接入点 wú xiàn jiē rù diǎn
    wireless network interface card 无线网络接口卡 wú xiàn wǎng luò jiē kǒu kǎ
    2.1

    Routers

    A router 路由器 connects different networks and forwards data between them — usually at the boundary of a LAN and the internet. It does:

    • forwarding — reads each packet 数据包's destination IP address IP地址 and sends it out the right port, using a routing table 路由表.
    • network address translation 网络地址转换 (NAT) — lets many private LAN addresses share one public IP.
    • DHCP 动态主机配置协议 — hands out private IP addresses to LAN devices.
    • firewall 防火墙 — blocks unwanted incoming traffic.
    A LAN of three computers and a server joined to a switch, which connects through a router to both the internet and another LAN or WAN
    A router connects a LAN to the internet or another network
    Vocabulary Train
    English Chinese Pinyin
    router 路由器 lù yóu qì
    packet 数据包 shù jù bāo
    IP address IP地址 IP dì zhǐ
    routing table 路由表 lù yóu biǎo
    network address translation 网络地址转换 wǎng luò dì zhǐ zhuǎn huàn
    DHCP 动态主机配置协议 dòng tài zhǔ jī pèi zhì xié yì
    firewall 防火墙 fáng huǒ qiáng
    2.1

    Ethernet and CSMA/CD

    Ethernet is the main wired LAN technology. On shared media a collision 冲突 can happen when two devices send at once. The protocol is CSMA/CD 载波侦听多路访问/冲突检测 (Carrier Sense Multiple Access with Collision Detection):

    1. carrier sense — listen before sending; wait if the cable is busy.
    2. multiple access — many devices share the medium.
    3. collision detection — keep listening while sending; a clash is a collision.
    4. on a collision, both stop, send a brief "jam" signal, then wait a random backoff time before retrying.

    Modern switched Ethernet uses full-duplex 全双工 point-to-point links, so collisions no longer happen.

    A flowchart of the CSMA/CD process: assemble frame, check the line is idle, send, detect collisions, send a jam signal, back off and retry up to a maximum count
    The CSMA/CD process for handling collisions on shared media
    Vocabulary Train
    English Chinese Pinyin
    collision 冲突 chōng tū
    CSMA/CD 载波侦听多路访问/冲突检测 zài bō zhēn tīng duō lù fǎng wèn chōng tū jiǎn cè
    full-duplex 全双工 quán shuāng gōng
    2.1

    Bit streaming

    Bit streaming 流式传输 sends multimedia as a continuous stream that the receiver plays as it arrives, instead of downloading the whole file first.

    • real-time (live): captured and streamed as it happens (live sport, video calls). You cannot rewind; low latency is vital.
    • on-demand: pre-recorded on a server (YouTube, Netflix). You can pause and rewind; the server can buffer 缓冲 ahead.

    Real-time streaming works as a short pipeline:

    1. capture and sample the source (a camera or microphone).
    2. encode it, using compression 压缩 to shrink the data.
    3. send it across the network as packets.
    4. the receiver buffers a little, then plays it live — dropping any packet that arrives late, because a live stream cannot wait for it.

    Lossy 有损 compression is used here: moving pictures hide small losses, and the stream must be small enough to fit the bandwidth.

    Data flows from the source server into a buffer that fills between a low and a high mark, and the media player reads from the buffer
    Data streams from the server into a buffer before the media player reads it
    Vocabulary Train
    English Chinese Pinyin
    bit streaming 流式传输 liú shì chuán shū
    buffer 缓冲 huǎn chōng
    compression 压缩 yā suō
    lossy 有损 yǒu sǔn
    2.1

    The internet and the World Wide Web

    The internet 互联网 is a global network of networks using a common protocol 协议 suite (TCP/IP). The World Wide Web 万维网 (WWW) is a service that runs over it: hyperlinked documents identified by URLs, viewed in browsers via HTTP/HTTPS. Email and file transfer are other internet services that are not part of the WWW.

    The World Wide Web is one service running on top of the Internet
    The Web is one service running on top of the Internet
    Vocabulary Train
    English Chinese Pinyin
    internet 互联网 hù lián wǎng
    protocol 协议 xié yì
    World Wide Web 万维网 wàn wéi wǎng
    2.1

    IP addresses

    An IP address uniquely identifies a device.

    • IPv4 — 32-bit, four denary numbers 0–255 (192.168.1.10); about $4.3 \times 10^{9}$ addresses (now exhausted).
    • IPv6 — 128-bit, eight groups of four hex digits; about $3.4 \times 10^{38}$ addresses.

    Subnetting

    A network can be split into subnets 子网. The IP address splits into a network part and a host part, given by a subnet mask 子网掩码 (e.g. 255.255.255.0 = first 24 bits are network). Subnetting improves management, cuts broadcast traffic, and improves security.

    Six department subnets, each with its own /24 netID, all connected through one central router that also reaches the internet
    Splitting a network into subnets, one netID per department

    Public vs private addresses

    • private addresses are used within a LAN and are not routable on the internet (e.g. 192.168.0.0/16).
    • a public IP address is globally unique and routable, assigned by an ISP 互联网服务提供商.

    Devices behind NAT with private addresses are not directly reachable from the internet, giving some protection.

    Static vs dynamic

    • a static IP address is fixed; used for servers that must be found at a known address.
    • a dynamic IP address is assigned by DHCP and may change; easier for client devices and uses a limited address pool efficiently.

    Worked example. A host has IP address 192.168.10.130 with subnet mask 255.255.255.192. Which network is it on, and is 192.168.10.200 on the same one? The mask's last octet, 192, is 11000000 in binary, so the first 26 bits are the network part and the last 6 bits address the host. That makes the subnets step in blocks of $256 - 192 = 64$: .0, .64, .128, .192. The address 130 falls in the block starting at .128, so the host is on network 192.168.10.128/26, whose usable hosts run .129 to .190 (.191 is the broadcast address). 200 falls in the next block (.192), so it is on a different subnet and traffic between the two must pass through a router. Get the block size from the mask first ($256$ minus the mask octet) - guessing from the first three octets is what makes these go wrong.

    Vocabulary Train
    English Chinese Pinyin
    subnets 子网 zi wǎng
    subnet mask 子网掩码 zi wǎng yǎn mǎ
    ISP 互联网服务提供商 hù lián wǎng fú wù tí gōng shāng
    2.1

    URL and DNS

    A URL 统一资源定位符 (Uniform Resource Locator) locates a resource on the WWW:

    https://www.example.com/about/contact.html
    protocol     domain name        path
    
    • protocol: http, https, etc.
    • domain name 域名: a readable server address.
    • path: the resource on that server.

    The Domain Name System 域名系统 (DNS, also called the Domain Name Service) is a distributed set of servers that turns domain names into IP addresses. When you type a URL, the browser asks a DNS resolver for the IP, which queries DNS servers (root → top-level → authoritative) until it finds it; the browser then connects to that IP and requests the path. DNS saves humans from memorising IP addresses and lets a site change server without changing its name.

    Numbered one to five: the computer asks a DNS resolver for the IP, the resolver queries another DNS server, the IP is returned to the resolver and then the computer, and the browser connects to the website server
    How DNS finds a website's IP address before the browser connects
    Explore

    How DNS finds a website

    Step through a DNS lookup. The network routes by IP, not by name — so before anything loads, DNS must turn the domain name into an IP address.

    Vocabulary Train
    English Chinese Pinyin
    URL 统一资源定位符 tǒng yī zī yuán dìng wèi fú
    domain name 域名 yù míng
    Domain Name System 域名系统 yù míng xì tǒng
    2.1

    Exam tips

    • Distinguish LAN vs WAN and client-server vs peer-to-peer by who stores and controls the resources.
    • Match each topology (bus, star, mesh) to its advantages and drawbacks (cost, reliability, collisions).
    • Know the job of each device: a switch directs within a LAN by MAC address, a router routes between networks by IP.
    • Explain bit streaming and why buffering is needed (data arrives at a different rate from playback).
    • Distinguish IPv4 vs IPv6 and public vs private addresses; DNS turns a URL into an IP address.
  • 3 Hardware
    3.1

    Computers and their components

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the need for input, output, primary memory and secondary (including removable) storage
    Show understanding of embedded systems Including: benefits and drawbacks of embedded systems
    Describe the principal operations of hardware devices Including: Laser printer, 3D printer, microphone, speakers, magnetic hard disk, solid state (flash) memory, optical disc reader/writer, touchscreen, virtual reality headset
    Show understanding of the use of buffers
    Explain the differences between Random Access Memory (RAM) and Read Only Memory (ROM) Including their use in a range of devices and systems
    Explain the differences between Static RAM (SRAM) and Dynamic RAM (DRAM) Including the use of SRAM and DRAM in a range of devices and systems and the reasons for using one instead of the other depending on the device and its use
    Explain the difference between Programmable ROM (PROM), Erasable Programmable ROM (EPROM) and Electrically Erasable Programmable ROM (EEPROM)
    Show an understanding of monitoring and control systems Including: • difference between monitoring and control • use of sensors (including temperature, pressure, infra-red, sound) and actuators • importance of feedback

    Source: Cambridge International syllabus

    A general-purpose computer has four building blocks:

    • input devices 输入设备 — get data in (keyboard, mouse, microphone, scanner, sensors).
    • output devices 输出设备 — give results out (monitor, speakers, printer, actuators).
    • primary memory 主存储器 — fast memory the processor 处理器 (CPU) reaches directly (RAM and ROM). Holds the running program and its data.
    • secondary storage 辅助存储器 — slower, larger, keeps programs and data when not in use (hard disk, SSD, optical disc, USB stick).
    A full-size white wireless QWERTY computer keyboard on a white background
    A keyboard: a common input device for typing text and commands
    A modern wireless computer mouse on a white background, with two buttons and a scroll wheel
    A mouse: a pointing input device
    A flatbed scanner on a white background, with a photo coming out of the front after scanning
    A flatbed scanner: an input device that turns a paper page into a digital image
    A silver flat-screen computer monitor on a round stand, with a dark screen
    A monitor: a common output device that displays the screen image
    Explore

    Tap the blocks of a computer system

    Explore the four blocks plus the CPU. Data flows input → processing → output, while primary memory holds the running program and secondary storage keeps it for later.

    Explore

    Network route lab

    Follow data from a device through network hardware and protocols.

    Vocabulary Train
    English Chinese Pinyin
    input devices 输入设备 shū rù shè bèi
    output devices 输出设备 shū chū shè bèi
    primary memory 主存储器 zhǔ cún chǔ qì
    processor 处理器 chǔ lǐ qì
    secondary storage 辅助存储器 fǔ zhù cún chǔ qì
    3.1

    Embedded systems

    An embedded system 嵌入式系统 is a computer built into another device to do one fixed job (washing machine, microwave, car engine unit, thermostat).

    • benefits: optimised for one task (low power, small, cheap); reliable; fast to start; cheap in volume.
    • drawbacks: limited to its one task; hard to update (its firmware 固件 may need special tools); often not repairable; sometimes weak security.
    Vocabulary Train
    English Chinese Pinyin
    embedded system 嵌入式系统 qiàn rù shì xì tǒng
    firmware 固件 gù jiàn
    3.1

    Principal hardware devices

    Laser printer

    A laser printer 激光打印机 scans the page image onto a charged photosensitive drum 感光鼓. Toner 墨粉 sticks to the charged areas, transfers to the paper, and is melted on by a fuser. Fast, sharp, high-volume.

    A black desktop laser printer on a white background, with a printed page coming out of the top
    A laser printer: fast, sharp printing using a charged drum and toner

    3D printer

    A 3D printer 3D打印机 builds an object layer by layer: FDM melts plastic filament through a nozzle; stereolithography cures liquid resin with a UV laser. Used for prototypes and custom medical parts.

    A black enclosed desktop FDM 3D printer with a glass front panel, a part being printed inside, on a white background
    An FDM 3D printer builds an object layer by layer by melting plastic filament

    Microphone and speakers

    A microphone 麦克风 turns sound into an electrical signal (a diaphragm vibrates, changing capacitor 电容器 charge or coil position); the signal is digitised by an analogue-to-digital converter 模数转换器 (ADC). A speaker does the reverse — a varying signal drives a coil in a magnetic field, moving a cone to make sound.

    A black USB desktop microphone standing on its base, on a white background
    A microphone turns sound into an electrical signal
    Cutaway of a microphone: sound waves hit a diaphragm linked to a coil around a permanent magnet, giving an output current
    Inside a microphone: sound vibrates the diaphragm and coil to produce a current
    Cutaway of a loudspeaker: current in a coil around an iron core near a permanent magnet moves a paper cone to produce sound waves
    Inside a loudspeaker: a varying current in the coil moves the cone to make sound

    Magnetic hard disk (HDD)

    A hard disk 硬盘 stores data on spinning platters coated with magnetic material. Each platter has tracks 磁道 divided into sectors 扇区. A read/write head 读写头 floats just above and magnetises tiny regions (write) or senses them (read). Cheap per gigabyte, but slower than SSDs and has moving parts.

    An opened 3.5-inch hard disk drive: a shiny circular platter with the actuator arm and read/write head resting over it
    An opened hard disk: the actuator arm carries the read/write head over a platter
    A hard disk platter drawn as concentric track circles, one track highlighted, divided into sectors
    Tracks and sectors on a hard disk platter

    Solid-state (flash) memory

    A solid-state drive 固态硬盘 stores data as charge in transistors 晶体管, with no moving parts. Faster random access than HDDs, tougher, lower power, but dearer per gigabyte; each cell wears out after many writes.

    The opened circuit board of a solid-state drive on a white background: a large black flash-memory chip on the left, a smaller controller chip, many tiny components, and a flat SATA connector along the bottom edge — no platters or moving parts
    Inside an SSD: data is stored in flash memory chips, with no moving parts (compare the hard disk above)

    Optical disc

    A laser detects reflections from tiny pits on an optical disc 光盘 (CD, DVD, Blu-ray). The drive is an optical disc reader/writer: writing uses a stronger laser to change the surface's reflectivity.

    An external optical disc drive on a white background, its tray open with a rainbow-coloured disc loaded
    An optical disc drive: a laser reads tiny pits on a CD, DVD or Blu-ray disc

    Touchscreen

    A touchscreen 触摸屏 senses contact. Resistive 电阻式: two conductive layers pressed together; works with anything but is less accurate. Capacitive 电容式: a finger disturbs a charge field; accurate, multi-touch, used in phones.

    People using a tablet touchscreen and a laptop
    A touchscreen senses where a finger touches the glass

    Virtual reality headset

    A virtual reality 虚拟现实 (VR) headset has two small displays (one per eye) and motion sensors (accelerometer 加速度计, gyroscope 陀螺仪) that track head movement so the scene shifts as you look around.

    A white virtual reality headset with its head strap and front cameras, on a white background
    A virtual reality headset: two small displays and motion sensors track the head
    Vocabulary Train
    English Chinese Pinyin
    laser printer 激光打印机 jī guāng dǎ yìn jī
    drum 感光鼓 gǎn guāng gǔ
    toner 墨粉 mò fěn
    3D printer 3D打印机 3D dǎ yìn jī
    microphone 麦克风 mài kè fēng
    capacitor 电容器 diàn róng qì
    analogue-to-digital converter 模数转换器 mó shù zhuǎn huàn qì
    hard disk 硬盘 yìng pán
    tracks 磁道 cí dào
    sectors 扇区 shàn qū
    read/write head 读写头 dú xiě tóu
    solid-state drive 固态硬盘 gù tài yìng pán
    transistors 晶体管 jīng tǐ guǎn
    optical disc 光盘 guāng pán
    touchscreen 触摸屏 chù mō píng
    resistive 电阻式 diàn zǔ shì
    capacitive 电容式 diàn róng shì
    virtual reality 虚拟现实 xū nǐ xiàn shí
    accelerometer 加速度计 jiā sù dù jì
    gyroscope 陀螺仪 tuó luó yí
    3.1

    Buffers

    A buffer 缓冲 is memory that holds data temporarily while it moves between devices of different speeds. Example: the CPU writes a document to a printer buffer quickly, then is free to do other work while the printer prints from the buffer at its own pace. Buffers stop the fast device waiting for the slow one (also used in streaming, the keyboard, and disk access).

    Vocabulary Train
    English Chinese Pinyin
    buffer 缓冲 huǎn chōng
    3.1

    RAM and ROM

    • RAM 随机存取存储器 (Random Access Memory) — volatile 易失性 (loses data without power). Holds the OS, running programs and their data; read and written constantly.
    • ROM 只读存储器 (Read-Only Memory) — non-volatile 非易失性 (keeps data without power). Usually written once; holds firmware needed at start-up (the BIOS / boot loader).
    RAM is volatile and read/write; ROM is non-volatile and read-only
    RAM is volatile and read/write; ROM is non-volatile and read-only

    ROM starts the system; RAM then holds the active work.

    A RAM module (DIMM): a circuit-board stick with a black heat-spreader over the memory chips and a gold-edged connector that plugs into a slot on the motherboard
    A RAM module (DIMM) plugs into the motherboard as the computer's fast main memory
    Explore

    Device and storage lab

    Classify computing examples by what job they do in a system.

    Vocabulary Train
    English Chinese Pinyin
    RAM 随机存取存储器 suí jī cún qǔ cún chǔ qì
    volatile 易失性 yì shī xìng
    ROM 只读存储器 zhī dú cún chǔ qì
    non-volatile 非易失性 fēi yì shī xìng
    3.1

    SRAM vs DRAM

    • SRAM 静态RAM (Static RAM) stores each bit in a flip-flop 触发器 of several transistors. Fast, but expensive and not dense. Used for CPU cache 高速缓存.
    • DRAM 动态RAM (Dynamic RAM) stores each bit as charge on a tiny capacitor. Cheaper and denser but slower, and must be refreshed 刷新 (rewritten) thousands of times a second. Used for main memory.

    Use SRAM for small fast memory (cache); DRAM for large main memory.

    Vocabulary Train
    English Chinese Pinyin
    SRAM 静态RAM jìng tài RAM
    flip-flop 触发器 chù fā qì
    cache 高速缓存 gāo sù huǎn cún
    DRAM 动态RAM dòng tài RAM
    refreshed 刷新 shuā xīn
    3.1

    PROM, EPROM and EEPROM

    ROM variants you can program after manufacture:

    • PROM (Programmable ROM) — written once (fuses burned by a programmer); cannot be changed.
    • EPROM (Erasable Programmable ROM) — erased by strong UV light through a window, then rewritten (whole chip at once).
    • EEPROM (Electrically Erasable Programmable ROM) — erased and rewritten electrically, a byte at a time, in circuit. Flash memory is a derivative optimised for block erase.
    3.1

    Monitoring and control systems

    Both read sensors; the difference is what they do next.

    • monitoring 监控 — collects and reports data but takes no action (a weather station logging readings).
    • control system 控制系统 — uses sensor data to decide and act through actuators, usually in a feedback loop (a thermostat turning a boiler on/off).
    Flowchart: sensors send signals through an ADC to the processor, which either reports a warning for monitoring or sends signals to actuators in a feedback loop for control
    Monitoring reports data; a control system acts through a feedback loop

    Sensors and actuators

    A sensor 传感器 turns a physical quantity into a signal: temperature (a thermistor 热敏电阻 or thermocouple), pressure (strain gauge), infra-red, sound. Analogue signals need an ADC first. An actuator 执行器 does the reverse — turns a signal into an action (a motor, valve, heater, buzzer).

    Small bead thermistors with two wire legs each, on a white background
    A thermistor: a temperature sensor whose resistance changes with heat
    A small metal stepper motor with a central shaft and coloured wires, on a dark studio background
    A small electric motor: an actuator that turns a signal into movement

    Feedback

    In a control system the actuator changes the environment, which the sensors then re-measure — a feedback 反馈 loop. Without feedback the system cannot correct itself or know when to stop (a thermostat with no temperature feedback would heat forever).

    Explore

    The control feedback loop

    Tap round the loop a thermostat or autopilot repeats. A control system doesn't just read the world — it acts, then re-measures, correcting itself again and again.

    Vocabulary Train
    English Chinese Pinyin
    monitoring 监控 jiān kòng
    control system 控制系统 kòng zhì xì tǒng
    sensor 传感器 chuán gǎn qì
    thermistor 热敏电阻 rè mǐn diàn zǔ
    actuator 执行器 zhí xíng qì
    feedback 反馈 fǎn kuì
    3.2

    Logic gates

    Syllabus
    Candidates should be able to: Notes and guidance
    Use the following logic gate symbols: [NOT, AND, OR, NAND, NOR, XOR]
    Understand and define the functions of: NOT, AND, OR, NAND, NOR and XOR (EOR) gates All gates except the NOT gate will have two inputs only.
    Construct the truth table for each of the logic gates above
    Construct a logic circuit From: • a problem statement • a logic expression • a truth table
    Construct a truth table From: • a problem statement • a logic circuit • a logic expression
    Construct a logic expression From: • a problem statement • a logic circuit • a truth table

    Source: Cambridge International syllabus

    The half adder: XOR + AND add two bits

    A logic gate 逻辑门 is a small circuit that does one Boolean 布尔 operation. Inputs and outputs are 0 (false, low) or 1 (true, high). Know the symbol, function and truth table 真值表 for each gate.

    The circuit symbols for NOT, AND, OR, NAND, NOR and XOR gates in a two-by-three grid
    The symbols for the six logic gates

    NOT (inverter)

    A NOT A
    0 1
    1 0

    AND — output 1 only if all inputs are 1

    A B A AND B
    0 0 0
    0 1 0
    1 0 0
    1 1 1

    OR — output 1 if at least one input is 1

    A B A OR B
    0 0 0
    0 1 1
    1 0 1
    1 1 1

    NAND (NOT AND) — output 0 only when all inputs are 1

    A B A NAND B
    0 0 1
    0 1 1
    1 0 1
    1 1 0

    NOR (NOT OR) — output 1 only when all inputs are 0

    A B A NOR B
    0 0 1
    0 1 0
    1 0 0
    1 1 0

    XOR (Exclusive OR, also called EOR) — output 1 if the inputs are different

    A B A XOR B
    0 0 0
    0 1 1
    1 0 1
    1 1 0
    Explore

    Logic gates

    Switch the inputs and pick a gate. Each gate has its own rule — the building blocks of every digital circuit.

    Vocabulary Train
    English Chinese Pinyin
    logic gate 逻辑门 luó jí mén
    Boolean 布尔 bù ěr
    truth table 真值表 zhēn zhí biǎo
    3.2

    Logic circuits

    A logic circuit 逻辑电路 is a network of gates that carries out a Boolean expression. You should be able to move between a problem statement, a logic expression, a truth table, and a circuit diagram.

    From expression to circuit

    Draw one gate per operator and wire them up. For $X = (A \text{ AND } B) \text{ OR } (\text{NOT } C)$: a NOT gate on $C$, an AND gate on $A$ and $B$, then an OR gate on the two results.

    A logic circuit: an AND gate on inputs A and B, a NOT gate on input C, both feeding an OR gate that gives output X
    Gates wired together to carry out a Boolean expression

    From circuit to expression

    Work forwards from the inputs, labelling each gate's output, until you reach the final output.

    From circuit to truth table

    For $n$ inputs there are $2^{n}$ rows. List every input combination; for each, work out the internal gates then the output.

    From truth table to expression (sum of products)

    For each row that outputs 1, write an AND of the inputs (with NOT on any input that is 0 in that row); OR these together. Example: a table that is 1 only on $(A=0,B=1)$ and $(A=1,B=0)$ gives $\overline{A}B + A\overline{B}$, which is $A \text{ XOR } B$.

    From a problem statement

    Turn the English into a Boolean expression first: "A and B" → A AND B; "A or B or both" → A OR B; "exactly one of A and B" → A XOR B; "neither A nor B" → A NOR B; "not both" → A NAND B.

    Worked example. A machine's alarm $X$ sounds when the guard is open ($A=1$) and either the motor is running ($B=1$) or the temperature is high ($C=1$). Write the Boolean expression, and give the rows where $X=1$. Turn the English into logic one clause at a time: "either B or C" is $B + C$, and "A and that" is $X = A\cdot(B + C)$. For the rows, $X=1$ needs $A=1$ and at least one of $B$, $C$ equal to 1 - so $(A,B,C) = (1,0,1)$, $(1,1,0)$ and $(1,1,1)$, three rows out of eight. Notice $A=0$ can never sound the alarm, whatever $B$ and $C$ do. Bracket the OR before ANDing it: $X = A\cdot B + C$ is a different circuit altogether, one that would sound the alarm on a high temperature even with the guard closed.

    Explore

    Half adder

    Wire XOR and AND to the same two inputs: XOR gives the sum bit, AND gives the carry. Click A and B.

    Explore

    Logic circuits

    gates combine into circuits

    Each gate has a fixed rule; chaining them builds every circuit — start with one gate.

    Vocabulary Train
    English Chinese Pinyin
    logic circuit 逻辑电路 luó jí diàn lù
    3.2

    Exam tips

    • Distinguish RAM (volatile, read/write) from ROM (non-volatile, holds the bootstrap); SRAM (cache, faster) from DRAM (main memory, needs refreshing).
    • For a logic circuit, build the Boolean expression gate by gate, then a truth table covering every input combination.
    • Learn the symbol, expression and truth table for each gate (AND, OR, NOT, NAND, NOR, XOR).
    • Explain a buffer (a temporary store bridging two different speeds) and the role of an interrupt.
  • 4 Processor Fundamentals
    4.1

    Von Neumann architecture

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the basic Von Neumann model for a computer system and the stored program concept
    Show understanding of the purpose and role of registers, including the difference between general purpose and special purpose registers Special purpose registers including: • Program Counter (PC) • Memory Data Register (MDR) • Memory Address Register (MAR) • The Accumulator (ACC) • Index Register (IX) • Current Instruction Register (CIR) • Status Register
    Show understanding of the purpose and roles of the Arithmetic and Logic Unit (ALU), Control Unit (CU) and system clock, Immediate Access Store (IAS)
    Show understanding of how data are transferred between various components of the computer system using the address bus, data bus and control bus
    Show understanding of how factors contribute to the performance of the computer system Including: • processor type and number of cores • the bus widthclock speedcache memory
    Understand how different ports provide connection to peripheral devices Including connection to: • Universal Serial Bus (USB) • High Definition Multimedia Interface (HDMI) • Video Graphics Array (VGA)
    Describe the stages of the Fetch-Execute (F-E) cycle Describe and use 'register transfer' notation to describe the F-E cycle
    Show understanding of the purpose of interrupts Including: • possible causes of interrupts • applications of interrupts • use of an Interrupt Service Routine (ISR) • when interrupts are detected during the fetch-execute cycle • how interrupts are handled

    Source: Cambridge International syllabus

    The fetch-decode-execute cycle

    The Von Neumann architecture·诺依曼体系结构 underlies almost every general-purpose computer:

    • a single memory — the Immediate Access Store 立即存取存储器 (IAS) — holds both program instructions and data (the stored program 存储程序 concept).
    • a processor 处理器 (CPU) fetches instructions from memory and runs them one at a time.
    • instructions run in order unless a branch changes the flow.

    The stored-program idea is what makes a computer flexible: change the program and you change what it does, with no rewiring.

    Explore

    Tap the parts of a Von Neumann computer

    Explore each block. The CPU (control unit, ALU, registers) talks to a single main memory over the buses — and that one shared memory for instructions AND data is the Von Neumann idea.

    Vocabulary Train
    English Chinese Pinyin
    Von Neumann architecture 冯·诺依曼体系结构 féng · nuò yī màn tǐ xì jié gòu
    stored program 存储程序 cún chǔ chéng xù
    processor 处理器 chǔ lǐ qì
    Immediate Access Store 立即存取存储器 lì jí cún qǔ cún chǔ qì
    4.1

    The CPU's main parts

    All of these parts sit inside one small chip. The diagram later in this section shows how they connect; the photo below shows the real thing.

    The underside of an Intel CPU chip on a white background, a flat square covered in a grid of hundreds of small gold contact pads that press onto the motherboard socket
    A modern CPU: the whole processor is one small chip (here seen from below, showing the contacts)
    A square CPU socket on a motherboard, with a grid of tiny pins and a metal retention lever, surrounded by circuit tracks
    The matching CPU socket on the motherboard: the chip's contacts press onto these pins

    Arithmetic and Logic Unit (ALU)

    The ALU 算术逻辑单元 does the arithmetic (add, subtract, …) and logic (AND, OR, comparisons). It takes operands from registers 寄存器 and puts results back in a register.

    Control Unit (CU)

    The control unit 控制单元 decodes each instruction and sends the control signals to carry it out — opening data paths, telling the ALU what to do, and controlling memory reads and writes.

    System clock

    The clock sends a steady stream of pulses that keep the CPU in step. Each instruction takes a fixed number of cycles, and the clock speed 时钟频率 (e.g. 3.8 GHz) is one factor in performance.

    Registers

    Registers are tiny, very fast stores inside the CPU. The special purpose registers 专用寄存器 each have a fixed job in the cycle:

    • Program Counter 程序计数器 (PC) — the address of the next instruction.
    • Memory Address Register 内存地址寄存器 (MAR) — the address being read or written.
    • Memory Data Register 内存数据寄存器 (MDR) — the data going to or from memory.
    • Current Instruction Register 当前指令寄存器 (CIR) — the instruction being decoded.
    • Accumulator 累加器 (ACC) — the value the ALU is working on.
    • Status Register 状态寄存器 — holds flags 标志 (carry, zero, negative, overflow) used by branches.
    • Index Register 变址寄存器 — an offset used in indexed addressing.

    General-purpose registers 通用寄存器 are used by the programmer for temporary values during a calculation. Movements of data between registers and memory are written in register transfer 寄存器传送 notation — e.g. MAR ← [PC] ("copy the contents of PC into MAR").

    Block diagram of the Von Neumann CPU showing PC, MAR, MDR, CIR, ACC, status register, control unit, ALU and system clock, linked to main memory and input/output by the address, data and control buses
    The Von Neumann CPU: registers, control unit and ALU linked by buses
    Vocabulary Train
    English Chinese Pinyin
    arithmetic and logic unit 算术逻辑单元 suàn shù luó jí dān yuán
    register 寄存器 jì cún qì
    control unit 控制单元 kòng zhì dān yuán
    clock speed 时钟频率 shí zhōng pín lǜ
    Program Counter 程序计数器 chéng xù jì shù qì
    Memory Address Register 内存地址寄存器 nèi cún dì zhǐ jì cún qì
    Memory Data Register 内存数据寄存器 nèi cún shù jù jì cún qì
    Current Instruction Register 当前指令寄存器 dāng qián zhǐ lìng jì cún qì
    Accumulator 累加器 lěi jiā qì
    Status Register 状态寄存器 zhuàng tài jì cún qì
    flags 标志 biāo zhì
    Index Register 变址寄存器 biàn zhǐ jì cún qì
    general-purpose registers 通用寄存器 tōng yòng jì cún qì
    special purpose registers 专用寄存器 zhuān yòng jì cún qì
    register transfer 寄存器传送 jì cún qì chuán sòng
    4.1

    Buses

    Three internal buses 总线 (sets of parallel wires) connect the parts:

    • address bus 地址总线 — carries the memory address. One-way (CPU → memory).
    • data bus 数据总线 — carries the data. Two-way.
    • control bus 控制总线 — carries control signals (read, write, interrupt). Two-way.

    An $n$-bit address bus can reach $2^{n}$ memory locations. The data-bus width sets how many bits move per access (often the word size).

    CPU, memory and input/output each tapping the address bus (one-way), data bus and control bus inside the system bus
    The three system buses connecting the CPU, memory and input/output
    Vocabulary Train
    English Chinese Pinyin
    buses 总线 zǒng xiàn
    address bus 地址总线 dì zhǐ zǒng xiàn
    data bus 数据总线 shù jù zǒng xiàn
    control bus 控制总线 kòng zhì zǒng xiàn
    4.1

    What affects performance

    • clock speed — more cycles per second.
    • number of cores 核心 — a multi-core CPU runs several threads at once.
    • word size 字长 — a 64-bit CPU handles 64-bit chunks per cycle and can address far more memory than a 32-bit one.
    • amount of RAM 随机存取存储器 — more RAM holds more of the working set; too little forces the OS to page to disk.
    • cache memory 高速缓存 size — more cache cuts average memory access time.
    • secondary storage 辅助存储器 type — an SSD loads programs far faster than an HDD.
    • bus width and speed — wider/faster buses move data more quickly.

    Match the specs to the workload: a quad-core beats a dual-core on parallel work, but higher per-core speed wins on single-threaded work.

    Vocabulary Train
    English Chinese Pinyin
    cores 核心 hé xīn
    word size 字长 zì zhǎng
    RAM 随机存取存储器 suí jī cún qǔ cún chǔ qì
    page
    secondary storage 辅助存储器 fǔ zhù cún chǔ qì
    cache memory 高速缓存 gāo sù huǎn cún
    4.1

    Ports

    A port 端口 is a physical socket for connecting a peripheral 外围设备:

    • USB (Universal Serial Bus) — general-purpose (keyboards, drives, phones).
    • HDMI (High Definition Multimedia Interface) — digital video and audio to a screen.
    • VGA (Video Graphics Array) — older analogue video output to a monitor.
    • Ethernet (RJ-45) — wired LAN. Audio jacks — headphones/microphone.

    Different ports use different signals, so an HDMI cable will not fit a USB socket. USB-C is unusual in carrying video, data and power.

    Vocabulary Train
    English Chinese Pinyin
    port 端口 duān kǒu
    peripheral 外围设备 wài wéi shè bèi
    4.1

    Fetch-Execute cycle

    The CPU repeats the fetch-execute cycle 取指-执行周期, one run per machine instruction.

    Fetch

    1. the PC's address is copied to the MAR.
    2. the PC is incremented to point to the next instruction.
    3. a read signal goes over the control bus.
    4. memory puts the instruction on the data bus.
    5. it is copied into the MDR, then into the CIR.
    The fetch register transfers in order: 1 the PC's address goes to the MAR; 2 the MAR sends the address to memory; 3 the instruction returns to the MDR; 4 the MDR copies it to the CIR; meanwhile the PC is incremented
    The register transfers in a fetch: PC → MAR → memory → MDR → CIR, with the PC incremented

    Decode

    The CU decodes the instruction in the CIR — what operation, and which operands or addresses.

    Execute

    The CU carries it out: arithmetic/logic goes to the ALU (result to the ACC); a load/store moves data between memory and a register; a branch changes the PC. Then the cycle repeats.

    Flowchart of the fetch-execute cycle from START: the fetch stage (PC to MAR, increment PC, read signal, memory to data bus to MDR to CIR), the decode stage, the execute stage, then a check for interrupts that loops back to START
    The fetch-execute cycle, with a check for interrupts each time
    Explore

    The fetch-execute cycle

    Tap round the loop the CPU repeats billions of times a second. Watch how fetch uses the PC/MAR/MDR/CIR registers, then decode and execute act on what was fetched.

    Explore

    The fetch–execute cycle

    Step through how the CPU runs one instruction — fetch it from memory, decode it, then execute it, over and over.

    Vocabulary Train
    English Chinese Pinyin
    fetch-execute cycle 取指-执行周期 qǔ zhǐ - zhí xíng zhōu qī
    4.1

    Interrupts

    An interrupt 中断 is a signal that pauses the normal cycle so the CPU can handle an urgent event (a key press, a packet arriving, a hardware fault, division by zero, the OS timer).

    Handling one:

    1. finish the current instruction.
    2. save the state (PC and registers).
    3. load the address of the interrupt service routine 中断服务程序 (ISR) into the PC and run it.
    4. the ISR handles the event.
    5. restore the saved state and carry on.

    Interrupts let the system respond promptly without the CPU constantly checking devices, and are how the OS multitasks.

    Flowchart of interrupt handling: the running program is interrupted, the CPU finishes the current instruction, saves its state (PC and registers) on the stack, runs the interrupt service routine, restores the state and resumes
    How an interrupt fits into the fetch-execute cycle
    Vocabulary Train
    English Chinese Pinyin
    interrupt 中断 zhōng duàn
    interrupt service routine 中断服务程序 zhōng duàn fú wù chéng xù
    4.2

    Assembly language and machine code

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the relationship between assembly language and machine code
    Describe the different stages of the assembly process for a two-pass assembler Apply the two-pass assembler process to a given simple assembly language program
    Trace a given simple assembly language program
    Show understanding that a set of instructions are grouped Including the following groups: • Data movement • Input and output of data • Arithmetic operations • Unconditional and conditional instructions • Compare instructions
    Show understanding of and be able to use different modes of addressing Including immediate, direct, indirect, indexed, relative

    Source: Cambridge International syllabus

    The CPU actually runs machine code 机器码 — bit patterns, specific to one architecture. Assembly language 汇编语言 is a readable form, with one instruction per machine instruction, written using mnemonics 助记符 like LDD, ADD, JMP. An assembler 汇编器 translates it to machine code.

    An assembler translates assembly mnemonics into machine-code bit patterns
    An assembler turns mnemonics into machine-code bit patterns

    Two-pass assembler

    A two-pass assembler reads the source twice:

    • pass 1 builds a symbol table 符号表: each time a label 标签 (like LOOP:) appears, record its address; no code yet.
    • pass 2 generates code: translate each instruction, and when one refers to a label (like JMP LOOP), look up its address in the symbol table.

    Two passes handle forward references 前向引用 (a jump to a label defined later).

    Example instruction set

    Cambridge uses a small generic set: data movement (LDD, LDM, LDI, LDX, STO, MOV), arithmetic (ADD, SUB, INC, DEC), logic/bit (AND, OR, XOR, LSL, LSR), compare and branch (CMP, JMP, JPE, JPN), I/O (IN, OUT), and END. The exact mnemonics are given in the paper's reference table.

    Explore

    How a two-pass assembler works

    Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined later still works.

    Vocabulary Train
    English Chinese Pinyin
    machine code 机器码 jī qì mǎ
    assembly language 汇编语言 huì biān yǔ yán
    mnemonics 助记符 zhù jì fú
    assembler 汇编器 huì biān qì
    symbol table 符号表 fú hào biǎo
    label 标签 biāo qiān
    forward references 前向引用 qián xiàng yǐn yòng
    4.2

    Addressing modes

    The addressing mode 寻址方式 (the modes of addressing) says how the CPU finds the operand:

    • immediate addressing 立即寻址 — the operand is the value in the instruction. LDM #10 loads 10.
    • direct addressing 直接寻址 — the instruction holds an address; the operand is the value there. LDD 200.
    • indirect addressing 间接寻址 — the instruction holds an address that holds another address, which is the data. LDI 200.
    • indexed addressing 变址寻址 — effective address is address + index register; used for arrays. LDX 100 with IR = 5 reads address 105.

    (Relative addressing 相对寻址 gives the address as an offset from the PC — used for jumps.)

    Four addressing modes reaching their operand. Immediate: LDM #10 gives 10 directly. Direct: LDD 200 reads memory location 200 (=42). Indirect: LDI 200 reads location 200 (=250) then location 250 (=99). Indexed: LDX 100 with index register 5 reads location 105 (=7)
    How each addressing mode reaches its operand — immediate, direct, indirect and indexed

    Worked example. Memory holds: location 200 = 250, location 250 = 99, location 105 = 7. The index register holds 5. What is in the accumulator after each of LDM #200, LDD 200, LDI 200 and LDX 100? Follow how far each mode has to look. LDM #200 is immediate - the operand is the number written in the instruction, so the accumulator holds 200. LDD 200 is direct - go to location 200 and take what is there: 250. LDI 200 is indirect - location 200 holds 250, which is another address, so go on to location 250: 99. LDX 100 is indexed - add the index register to the address, $100 + 5 = 105$, and read location 105: 7. Count the hops to keep them apart: immediate 0, direct 1, indirect 2, indexed 1 (once the index has been added).

    Vocabulary Train
    English Chinese Pinyin
    addressing mode 寻址方式 xún zhǐ fāng shì
    immediate addressing 立即寻址 lì jí xún zhǐ
    direct addressing 直接寻址 zhí jiē xún zhǐ
    indirect addressing 间接寻址 jiàn jiē xún zhǐ
    indexed addressing 变址寻址 biàn zhǐ xún zhǐ
    relative addressing 相对寻址 xiāng duì xún zhǐ
    4.2

    Tracing an assembly program

    To trace it: make a table with columns for the PC, ACC, index register, each variable and any flags. Step through the instructions, updating the table after each; follow branches when they change the PC; stop at END. A common pattern is a loop over an array using indexed addressing.

    4.3

    Binary shifts

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of and perform binary shifts Logical, arithmetic and cyclic Left shift, right shift
    Show understanding of how bit manipulation can be used to monitor/control a device Carry out bit manipulation operations Test and set a bit (using bit masking)
    Instruction Label | Opcode | Operand Explanation
    AND #n / Bn / &n Bitwise AND operation of the contents of ACC with the operand
    AND
    Bitwise AND operation of the contents of ACC with the contents of
    XOR #n / Bn / &n Bitwise XOR operation of the contents of ACC with the operand
    XOR
    Bitwise XOR operation of the contents of ACC with the contents of
    OR #n / Bn / &n Bitwise OR operation of the contents of ACC with the operand
    OR
    Bitwise OR operation of the contents of ACC with the contents of
    LSL #n Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
    LSR #n Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end
    Labels an instruction
    Gives a symbolic address
    All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator IX denotes Index Register
    can be an absolute or symbolic address # denotes a denary number, e.g. #123 B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A

    Source: Cambridge International syllabus

    A logical shift 逻辑移位 moves all the bits left or right by some places, filling new positions with 0.

    • left shift by 1 (LSL #1) — bits move left, a 0 enters on the right; for an unsigned number this is × 2.
    • right shift by 1 (LSR #1) — bits move right, a 0 enters on the left; for an unsigned number this is integer ÷ 2.

    Shifting by $n$ places multiplies or divides by $2^{n}$. Example: 00001011 (11) LSL #100010110 (22).

    An arithmetic right shift keeps the sign bit so a negative signed number stays negative. A cyclic shift 循环移位 (rotate) feeds the bit that drops off one end back in at the other end, so no bits are lost.

    Three 8-bit shifts: LSL #1 turns 00001011 into 00010110 (times 2, a 0 enters on the right); LSR #1 turns it into 00000101 (integer divide by 2, a 0 enters on the left); ASR #1 turns 10110100 into 11011010, copying the sign bit
    Logical left ($\times 2$), logical right ($\div 2$) and arithmetic right (keeps the sign bit)

    Bit manipulation for monitoring/control

    Embedded devices often use one bit of a register per signal (e.g. bit $n$ = LED $n$). Using a mask 掩码bit masking — you can:

    • set bit $n$: R = R OR a mask with bit $n$ set.
    • clear bit $n$: R = R AND a mask with bit $n$ clear and the rest set.
    • toggle bit $n$: R = R XOR a mask with bit $n$ set.
    • test bit $n$: R AND the mask, then check if the result is non-zero.
    Bit masking on the byte 01001000: set bit 2 with OR 00000100 to get 01001100; clear bit 6 with AND 10111111 to get 00001000; toggle bit 3 with XOR 00001000 to get 01000000
    Set a bit with OR, clear it with AND, toggle it with XOR — each using a mask

    Bit manipulation is fast, uses little memory, and lets one byte hold up to 8 on/off states.

    Explore

    Shift and mask the bits of a byte

    Pick an operator and watch each result bit. A left shift (<<) moves every bit up one place (×2); a right shift (>>) moves them down (÷2); AND with a mask clears the bits you don't want.

    Vocabulary Train
    English Chinese Pinyin
    logical shift 逻辑移位 luó jí yí wèi
    mask 掩码 yǎn mǎ
    bit wèi
    cyclic shift 循环移位 xún huán yí wèi
    4.3

    Exam tips

    • Learn the fetch-execute cycle in register-transfer terms (PC, MAR, MDR, CIR, ACC) and what increments the PC.
    • Name each register's job; the address bus is one-way, the data bus is two-way.
    • Distinguish the addressing modes (immediate, direct, indirect, indexed) — a frequent question.
    • Explain how clock speed, number of cores, cache size and word length affect performance.
    • For a binary shift, state whether it is logical or arithmetic; a left shift multiplies by 2, a right shift divides by 2.
  • 5 System Software
    5.1

    Operating systems

    Syllabus
    Candidates should be able to: Notes and guidance
    Explain why a computer system requires an Operating System (OS)
    Explain the key management tasks carried out by the Operating System Including memory management, file management, security management, hardware management (input/output/peripherals), process management
    Show understanding of the need for typical utility software provided with an Operating System Including disk formatter, virus checker, defragmentation software, disk contents analysis / disk repair software, file compression, back-up software
    Show understanding of program libraries Including: • software under development is often constructed using existing code from program libraries • the benefits to the developer of software constructed using library files, including Dynamic Link Library (DLL) files

    Source: Cambridge International syllabus

    Why a computer needs an OS

    Hardware on its own can only fetch and run instructions — it knows nothing about files, programs, networks or users. The operating system 操作系统 (OS) is the software layer that:

    • manages the hardware (processor 处理器, memory, I/O, storage) for the running programs.
    • provides services (file system, network, user accounts) through a clear interface, so programs need not talk to the hardware directly.
    • provides a user interface (command line, GUI, touch).
    • lets several programs share the hardware safely — each gets fair CPU time and is kept out of the others' memory.

    Without an OS, every program would need its own drivers, and only one program could safely run at a time.

    A desktop operating system on screen
    A desktop operating system manages the screen, files and programs for the user
    A smartphone showing its home screen
    A smartphone runs a mobile operating system such as Android

    Key management tasks

    • process management 进程管理 — load programs, schedule them on the CPU, switch between them, and kill misbehaving ones. (A running program is a process 进程.)
    • memory management 内存管理 — give memory to processes, keep them apart, and use virtual memory 虚拟内存 / paging 分页 so the working set can exceed physical RAM 随机存取存储器.
    • file management — organise files and folders on secondary storage 辅助存储器, control permissions, prevent write corruption.
    • device management (hardware management) — handle I/O and peripherals through device drivers 设备驱动, buffer data, manage interrupts, and give a uniform interface.
    • security management — accounts, permissions, firewall, encryption.
    • user interface and networking.
    Hub diagram with the operating system at the centre linked by spokes to memory, process, file, device and security management and the user interface
    The main jobs the operating system manages
    A memory map with the operating system and three applications each in their own block, separated by boundary addresses; an access inside a block is allowed but an access that strays past a boundary is blocked
    Memory protection keeps each application in its own block of memory

    Utility software

    Most OSes include utility programs 实用程序 to maintain the system:

    Common utility programs: antivirus, backup, file compression and disk defragmenter
    Utility programs: antivirus, backup, compression and defragmenter
    • disk formatter — a file / disk management tool that prepares a disk (sets up its file system); related tools copy, move and delete files.
    • defragmentation software (disk defragmenter 碎片整理) — moves the pieces of fragmented files together on a hard disk to cut seek time (not useful on SSDs).
    • disk contents analysis / disk repair software — check disk integrity and fix file-system errors and bad sectors.
    • back-up software (backup 备份) — copies user data elsewhere so it can be recovered.
    • virus checker (antivirus 杀毒软件) — scans for malware and quarantines threats.
    • firewall 防火墙 — filters network traffic by rules.
    • file compression (compression 压缩) / archiving; system monitor; updates.

    Bundling these with the OS saves the user installing each one.

    Explore

    Where the operating system sits

    Tap each layer. The OS is the middle layer — it sits between your applications and the hardware, sharing the machine safely so programs never touch the hardware directly.

    Vocabulary Train
    English Chinese Pinyin
    operating system 操作系统 cāo zuò xì tǒng
    processor 处理器 chǔ lǐ qì
    process management 进程管理 jìn chéng guǎn lǐ
    process 进程 jìn chéng
    memory management 内存管理 nèi cún guǎn lǐ
    virtual memory 虚拟内存 xū nǐ nèi cún
    paging 分页 fēn yè
    RAM 随机存取存储器 suí jī cún qǔ cún chǔ qì
    secondary storage 辅助存储器 fǔ zhù cún chǔ qì
    device driver 设备驱动 shè bèi qū dòng
    utility program 实用程序 shí yòng chéng xù
    disk defragmenter 碎片整理 suì piàn zhěng lǐ
    backup 备份 bèi fèn
    antivirus 杀毒软件 shā dú ruǎn jiàn
    firewall 防火墙 fáng huǒ qiáng
    compression 压缩 yā suō
    5.1

    Program libraries

    A program library 程序库 is pre-written code (subroutines 子程序, classes, modules) that programs reuse instead of writing it themselves — e.g. a maths library, a network library, a graphics library.

    A new program under development reusing ready-made routines from a maths library, a graphics library and a network library
    A new program reusing ready-made routines from libraries

    Benefits: saves time (off-the-shelf code), reliable (well-tested, widely used), and standardised (consistent behaviour).

    • a static library 静态库 is copied into the executable at compile time (stands alone, but larger and needs rebuilding to update).
    • a dynamic library 动态库 (DLL, Dynamic Link Library; .so) is loaded at run time (smaller executables, shared by many programs, updated once for all).
    A static library is copied into the executable at compile time, making a bigger standalone program; a dynamic library file (.dll or .so) stays separate, is loaded at run time, and is shared by several programs
    Static: the library is copied into the executable. Dynamic: a shared library file is loaded at run time
    Explore

    Computing concept lab

    Classify concrete examples by the computing idea they demonstrate.

    Vocabulary Train
    English Chinese Pinyin
    program library 程序库 chéng xù kù
    subroutines 子程序 zi chéng xù
    static library 静态库 jìng tài kù
    dynamic library 动态库 dòng tài kù
    5.2

    Language translators

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the need for: • assembler software for the translation of an assembly language program • a compiler for the translation of a high-level language program • an interpreter for translation and execution of a high-level language program
    Explain the benefits and drawbacks of using either a compiler or interpreter and justify the use of each
    Show awareness that high-level language programs may be partially compiled and partially interpreted, such as Java (console mode)
    Describe features found in a typical Integrated Development Environment (IDE) Including: • for coding, including context-sensitive prompts • for initial error detection, including dynamic syntax checks • for presentation, including prettyprint, expand and collapse code blocks • for debugging, including single stepping, breakpoints, i.e. variables, expressions, report window

    Source: Cambridge International syllabus

    You write source code; the computer runs machine code 机器码. A translator 翻译器 converts between them.

    Assembler

    An assembler 汇编器 translates assembly language 汇编语言 into machine code, one instruction per instruction. Used for low-level code (embedded systems, drivers).

    Compiler

    A compiler 编译器 translates a high-level program into machine code once, before it runs.

    • it reports all errors at compile time; once clean, it produces a stand-alone executable 可执行文件 that runs without the compiler installed and can be run many times.
    • generally faster at run time (no translation while running), but tied to one CPU/OS — recompile for each platform.

    Interpreter

    An interpreter 解释器 translates and runs a high-level program one line at a time, producing no executable.

    • it reports an error when it reaches that line, then stops; you can fix it and continue — good for development.
    • the interpreter must be installed to run the program; generally slower (each run re-translates), but easy to port across platforms.
    A compiler translates the source once into an executable that then runs many times with no translator present; an interpreter translates and runs the source one line at a time, on every run
    A compiler translates once into a standalone program; an interpreter translates line by line, every run

    Choosing between them

    Use a compiler when: Use an interpreter when:
    run-time speed matters you want fast edit–run cycles
    distributing to users without dev tools writing cross-platform scripts
    the program runs many times the program is small or run once
    teaching beginners

    Hybrid: Java

    Java is compiled into bytecode 字节码 (a platform-independent intermediate form), which a virtual machine 虚拟机 (the JVM) then interprets — or uses just-in-time compilation 即时编译 to turn hot parts into native code. So errors are caught early, the bytecode runs anywhere with a JVM ("write once, run anywhere"), and long-running programs reach near-native speed. C# and Python use similar designs.

    Java source is compiled once into platform-independent bytecode (.class), which a JVM on Windows, macOS or Linux then interprets or JIT-compiles into native code
    Java compiles to portable bytecode that any JVM runs — write once, run anywhere

    Worked example. Java source is compiled to bytecode, which a JVM then interprets. Why use both, instead of compiling straight to machine code? A compiler produces machine code for one processor and operating system, so a program compiled on one machine will not run on another. Java's compiler instead targets a virtual machine, so the bytecode it produces is identical everywhere; each platform then supplies its own JVM to interpret that bytecode into its own native instructions. One compiled file therefore runs anywhere a JVM exists - "write once, run anywhere". The price is speed: interpreting bytecode is slower than running native code, which is why a real JVM also uses JIT compilation to turn frequently-run bytecode into native code while the program runs. Name both sides - the marks are for portability bought at the cost of speed.

    Explore

    The compiler route: source to running program

    Step through how a compiler works — translating the whole program once, before it runs. Contrast it with an interpreter, which translates and runs one line at a time.

    Vocabulary Train
    English Chinese Pinyin
    machine code 机器码 jī qì mǎ
    translator 翻译器 fān yì qì
    assembler 汇编器 huì biān qì
    assembly language 汇编语言 huì biān yǔ yán
    compiler 编译器 biān yì qì
    executable 可执行文件 kě zhí xíng wén jiàn
    interpreter 解释器 jiě shì qì
    bytecode 字节码 zì jié mǎ
    virtual machine 虚拟机 xū nǐ jī
    just-in-time compilation 即时编译 jí shí biān yì
    5.2

    Integrated Development Environment (IDE)

    An integrated development environment 集成开发环境 (IDE) brings the tools to write, test and debug code into one application:

    An IDE gathers the code editor, a Run button and a debugger into one program
    An IDE bundles the editor, a Run button and a debugger
    • source code editor with syntax highlighting 语法高亮 (keywords, strings, comments in different colours), auto-indent and bracket matching.
    • auto-complete 自动补全 — suggests names and shows function parameters as you type.
    • translator integration — compile/run with one keystroke; errors shown inline.
    • debugger 调试器 — set breakpoints 断点 to pause, step through line by line, and inspect variables.
    • version control 版本控制 integration (git), project management, a help system, refactoring 重构 tools (safe renaming), and unit test 单元测试 integration.

    An IDE speeds development by putting writing → running → debugging → fixing behind one interface. Common IDEs: Visual Studio, PyCharm, Eclipse, VS Code.

    A debugger workflow: set a breakpoint, run the program, and when it reaches the breakpoint it pauses so you can inspect the variables, then step a line at a time or continue
    A debugger: set a breakpoint, run, then pause to inspect variables and step through the code
    Vocabulary Train
    English Chinese Pinyin
    integrated development environment 集成开发环境 jí chéng kāi fā huán jìng
    syntax highlighting 语法高亮 yǔ fǎ gāo liàng
    auto-complete 自动补全 zì dòng bǔ quán
    debugger 调试器 tiáo shì qì
    breakpoints 断点 duàn diǎn
    version control 版本控制 bǎn běn kòng zhì
    refactoring 重构 zhòng gòu
    unit test 单元测试 dān yuán cè shì
    5.2

    Exam tips

    • List the OS's jobs (memory, process, file, device and security management) — "manages resources" alone is too vague.
    • Compare compiler vs interpreter vs assembler: what each translates and when errors are reported.
    • Explain what an IDE provides (editor, debugger, error diagnostics, auto-complete).
  • 6 Security, privacy and data integrity
    6.1

    Security, privacy and integrity — three different ideas

    Syllabus
    Candidates should be able to: Notes and guidance
    Explain the difference between the terms security, privacy and integrity of data
    Show appreciation of the need for both the security of data and the security of the computer system
    Describe security measures designed to protect computer systems, ranging from the stand-alone PC to a network of computers Including user accounts, passwords, authentication techniques such as digital signatures and biometrics, firewall, anti-virus software, anti-spyware, encryption
    Show understanding of the threats to computer and data security posed by networks and the internet Including malware (virus, spyware), hackers, phishing, pharming
    Describe methods that can be used to restrict the risks posed by threats
    Describe security methods designed to protect the security of data Including encryption, access rights

    Source: Cambridge International syllabus

    These sound alike but mean different things:

    • security 安全 — protecting data from unauthorised 未授权 access, change or destruction.
    • privacy 隐私 — an individual's right to control who sees their personal data, with consent and a clear purpose.
    • integrity 完整性 — the data being accurate and complete — not corrupted or accidentally changed.

    A file can be secure (only the right people can open it) but lack integrity (a typo corrupted it); or accurate but not private (anyone can read it). All three are needed.

    Explore

    Risk and responsibility lab

    Sort examples by the rule, risk or protection involved.

    Vocabulary Train
    English Chinese Pinyin
    security 安全 ān quán
    unauthorised 未授权 wèi shòu quán
    privacy 隐私 yǐn sī
    integrity 完整性 wán zhěng xìng
    6.1

    Why security matters

    Two things to protect: the data itself (keep it confidential, intact and available) and the computer system (a compromised system can attack others, steal credentials, or be held to ransom).

    6.1

    Threats from networks and the internet

    Threats fall into three groups.

    A man-in-the-middle attacker sits between Alice and Bob, reading or altering messages
    A man-in-the-middle attacker sits between the two parties

    1. Malware 恶意软件 (malicious software) — harmful programs:

    • virus 病毒 — self-copying code that attaches to other programs and spreads when they run.
    • worm 蠕虫 — self-copying code that spreads over networks 网络 with no user action.
    • Trojan horse 木马 — looks useful but hides malicious code.
    • spyware 间谍软件 — secretly collects information (keystrokes, passwords).
    • ransomware 勒索软件 — encrypts your files and demands payment.
    • adware 广告软件 — pushes unwanted adverts.

    2. Tricking people (social attacks):

    • phishing 网络钓鱼 — fake emails/sites that trick users into giving credentials.
    • pharming 域名欺骗 — redirects a user to a fake site even when they type the correct address.
    • social engineering 社会工程 — tricking people into giving up information.

    3. Attacks on the network:

    • hacking 黑客入侵 by hackers 黑客 — unauthorised access, often via weak passwords or software flaws.
    • denial of service 拒绝服务 (DoS/DDoS) — floods a server so real users cannot reach it.
    • eavesdropping 窃听 — capturing data in transit (a risk on open Wi-Fi).
    • man-in-the-middle 中间人攻击 — an attacker secretly relays or alters messages between two parties.
    Malware grouped by behaviour: self-spreading types are the virus (attaches to programs) and worm (spreads over networks); hidden or disguised types are the Trojan (looks useful), spyware, ransomware and adware
    Malware by behaviour: self-spreading (virus, worm) versus hidden/disguised (Trojan, spyware, ransomware, adware)
    Vocabulary Train
    English Chinese Pinyin
    1. Malware 恶意软件 è yì ruǎn jiàn
    virus 病毒 bìng dú
    worm 蠕虫 rú chóng
    networks 网络 wǎng luò
    Trojan horse 木马 mù mǎ
    spyware 间谍软件 jiàn dié ruǎn jiàn
    ransomware 勒索软件 lè suǒ ruǎn jiàn
    adware 广告软件 guǎng gào ruǎn jiàn
    phishing 网络钓鱼 wǎng luò diào yú
    pharming 域名欺骗 yù míng qī piàn
    social engineering 社会工程 shè huì gōng chéng
    hacking 黑客入侵 hēi kè rù qīn
    hackers 黑客 hēi kè
    denial of service 拒绝服务 jù jué fú wù
    eavesdropping 窃听 qiè tīng
    man-in-the-middle 中间人攻击 zhōng jiān rén gōng jī
    malware 恶意软件 è yì ruǎn jiàn
    6.1

    Security measures

    Measures protect both the security of data (against loss, theft or corruption) and the security of the computer system (its hardware, software and network).

    A standalone PC

    • a strong password; antivirus kept up to date; prompt software updates; backup 备份 to separate media; full-disk encryption 加密; a locked screen.

    A networked PC

    All the above, plus a firewall 防火墙, per-user permissions (admin rights only for admins), central management of user accounts 用户账户, and audit logs 审计日志 (who logged in, what they touched).

    A box diagram with the user's computer on the trusted side, then the firewall, then the internet on the untrusted side, connected by double-headed arrows
    A firewall sits between the user's computer and the internet

    Across the internet

    • VPN 虚拟专用网 — encrypts traffic between the user and the corporate gateway.
    • HTTPS / TLS — encrypt web traffic.
    • digital signatures 数字签名 — prove who sent a message and that it was not altered in transit.
    • intrusion detection — watches traffic for known attack patterns.
    Vocabulary Train
    English Chinese Pinyin
    backup 备份 bèi fèn
    encryption 加密 jiā mì
    firewall 防火墙 fáng huǒ qiáng
    user accounts 用户账户 yòng hù zhàng hù
    audit logs 审计日志 shěn jì rì zhì
    VPN 虚拟专用网 xū nǐ zhuān yòng wǎng
    digital signatures 数字签名 shù zì qiān míng
    6.1

    Matching measures to threats

    • interception in transitencrypt the data (HTTPS, VPN). Intercepted ciphertext is useless without the key.
    • unauthorised access → strong authentication 身份验证 (long passwords; two-factor authentication 双因素认证 with a phone code or key); user authorisation 授权; lock-out after failed logins.
    • malwareanti-virus software and anti-spyware 反间谍软件 with real-time scanning; patching; avoid untrusted downloads.
    • phishing → user training; email filtering; check the URL before entering credentials.
    • internal threats → the least-privilege 最小权限 principle (give each user only what they need); auditing.
    • DDoS → rate limiting and traffic filtering.
    Vocabulary Train
    English Chinese Pinyin
    authentication 身份验证 shēn fèn yàn zhèng
    two-factor authentication 双因素认证 shuāng yīn sù rèn zhèng
    authorisation 授权 shòu quán
    anti-spyware 反间谍软件 fǎn jiàn dié ruǎn jiàn
    least-privilege 最小权限 zuì xiǎo quán xiàn
    6.1

    Protecting the data itself

    • encryption — turn plaintext 明文 into ciphertext 密文 with a key. Symmetric encryption 对称加密 (AES) uses one shared key; asymmetric encryption 非对称加密 (RSA) uses a public key 公钥 and a private key 私钥. Protects data at rest and in transit.
    • access control 访问控制 — file permissions (read/write/execute) and access rights 访问权限, enforced by the OS.
    • authenticationauthentication techniques verify the user: something you know (password), have (token, phone), or are (biometrics 生物识别 — fingerprint, face, iris); strongest combined.
    • backups — keep copies (some off-site) so loss or corruption is recoverable.
    • physical security — locked server rooms, cable locks.
    Symmetric encryption uses one shared key to both encrypt and decrypt the message; asymmetric encryption encrypts with the receiver's public key and decrypts with their private key
    Symmetric uses one shared key; asymmetric uses a public key to encrypt and a private key to decrypt
    A grey RSA SecurID key-fob security token with an LCD screen showing a six-digit code
    A security token shows a changing code for two-factor authentication ("something you have")
    A small USB fingerprint reader with an optical sensor pad
    A fingerprint reader checks "something you are" — a feature of the person, not a password
    Explore

    Encrypt with a Caesar cipher

    Change the shift — that is the key. Each letter slides that many places along the alphabet to make the ciphertext, and the same key slides it back. That shared key is symmetric encryption in miniature.

    Vocabulary Train
    English Chinese Pinyin
    plaintext 明文 míng wén
    ciphertext 密文 mì wén
    Symmetric encryption 对称加密 duì chèn jiā mì
    asymmetric encryption 非对称加密 fēi duì chèn jiā mì
    public key 公钥 gōng yào
    private key 私钥 sī yào
    access control 访问控制 fǎng wèn kòng zhì
    access rights 访问权限 fǎng wèn quán xiàn
    biometrics 生物识别 shēng wù shí bié
    6.2

    Data integrity

    Syllabus
    Candidates should be able to: Notes and guidance
    Describe how data validation and data verification help protect the integrity of data
    Describe and use methods of data validation Including range check, format check, length check, presence check, existence check, limit check, check digit
    Describe and use methods of data verification during data entry and data transfer During data entry including visual check, double entry During data transfer including parity check (byte and block), checksum

    Source: Cambridge International syllabus

    Data has integrity when it is accurate and complete. Two techniques: data validation (catch bad data before storing) and data verification (confirm data was entered or transferred correctly).

    Validation — does the data make sense?

    Validation 验证 checks data against sensible rules, automatically:

    • range check — within limits (a month is 1–12).
    • limit check — on the correct side of a single limit (e.g. age ≥ 18).
    • existence check — the referenced item exists (e.g. a product code is in the table).
    • length check — the right number of characters.
    • type / character check — the right kind of data (a phone field allows only digits).
    • format check — matches a pattern (an email must contain @).
    • presence check — required fields are not empty.
    • check digit 校验位 — an extra digit computed from the others (ISBN, card numbers) that spots transcription errors.
    • lookup check and consistency check (e.g. delivery date ≥ order date).

    Validation catches data that is wrongly formatted, but not data that is the right format yet factually wrong ("Bob" for "Bib").

    Verification — was the data entered or transferred correctly?

    Verification 核对 checks the data was not changed in moving from one place to another.

    During entry: double entry (type it twice and compare, as for a new password) or visual check.

    During transfer (bits can flip):

    • parity check 奇偶校验 — an extra bit makes the number of 1s even (even parity) or odd. The receiver re-counts. Catches single-bit errors.
    • checksum 校验和 — the sender sends a summary value of the data; the receiver recomputes it and compares.
    • cyclic redundancy check 循环冗余校验 (CRC) — a stronger checksum using polynomial division, catching many more error types.

    A parity block check 奇偶块校验 goes further and locates the error. Arrange the bytes in a grid: give each byte a row parity bit, then compute one extra parity byte whose bits are the column parity of the bytes above. A single flipped bit now fails one row and one column – their intersection pinpoints exactly which bit changed, so it can even be corrected.

    The same seven data bits shown twice: a 0 parity bit gives four 1s for even parity, a 1 parity bit gives five 1s for odd parity
    The parity bit is set to make the number of 1s even or odd
    The sender computes a checksum and sends it with the data block; the receiver recomputes the checksum and compares, plus a worked example of the byte-sum-mod-256 calculation
    Working out a checksum for a block of data

    Verification only proves what arrived matches what was sent — not that the data is correct, and not against deliberate tampering. Validation asks "is this sensible?"; verification asks "was this copied correctly?" — use both.

    Side by side: validation asks "is this data sensible?" and checks rules like range, type and format before storing (catching nonsense data); verification asks "was it copied correctly?" and uses double entry, parity and checksums (catching copying errors)
    Validation checks the data makes sense; verification checks it was copied without change

    Worked example. A user types their date of birth as 31/02/2009, and types their email address twice. Which check catches which error, and what is the difference? Validation asks "is this data sensible?" - the computer tests it against a rule, and a format or range check rejects 31/02/2009 because February never has 31 days. Verification asks "was this data entered correctly?" - typing the email twice is double entry, and comparing the two copies catches a typing slip. The limit is what makes this a favourite question: validation can never tell you the data is right, only that it is possible - 01/02/2009 passes every validation rule even if the user was actually born on a different day. Say what each check can and cannot catch.

    Explore

    Computing concept lab

    Classify concrete examples by the computing idea they demonstrate.

    Vocabulary Train
    English Chinese Pinyin
    Validation 验证 yàn zhèng
    check digit 校验位 jiào yàn wèi
    Verification 核对 hé duì
    parity check 奇偶校验 jī ǒu jiào yàn
    checksum 校验和 jiào yàn hé
    cyclic redundancy check 循环冗余校验 xún huán rǒng yú jiào yàn
    parity block check 奇偶块校验 jī ǒu kuài jiào yàn
    6.2

    Exam tips

    • Keep the three ideas separate: security (keeping data safe), privacy (who may see it), integrity (keeping it correct).
    • Match each threat (malware, hacking, phishing, interception) to a measure (firewall, encryption, authentication, access rights).
    • Encryption protects confidentiality, not integrity — use a checksum, parity or check digit for integrity.
    • Distinguish a virus, worm and Trojan and how each spreads.
  • 7 Ethics and Ownership
    7.1

    Ethics for computing professionals

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the need for and purpose of ethics as a computing professional Understand the importance of joining a professional ethical body including BCS (British Computer Society), IEEE (Institute of Electrical and Electronic Engineers)
    Show understanding of the need to act ethically and the impact of acting ethically or unethically for a given situation
    Show understanding of the need for copyright legislation
    Show understanding of the different types of software licencing and justify the use of a licence for a given situation Licences to include free Software Foundation, the Open Source Initiative, shareware and commercial software
    Show understanding of Artificial Intelligence (AI) Understand the impact of AI including social, economic and environmental issues
    Understand the applications of AI

    Source: Cambridge International syllabus

    A computing professional is someone whose work — software, systems, networks, data — affects other people. Because the work is technical, others often cannot judge whether it was done well or honestly. So the profession follows shared ethics 伦理 (principles for good behaviour).

    Why ethics matters

    • trust — users and employers trust professionals to act in their interest. Without that trust, software loses credibility.
    • impact — software runs medical devices, banking, vehicles. Careless or dishonest work can hurt people.

    Professional bodies (BCS, ACM, IEEE) publish codes of ethics for members.

    A wall of CCTV monitors in a control room
    CCTV raises privacy concerns — one of the ethical issues a computing professional must weigh
    A pile of discarded electronic equipment
    Discarded electronics (e-waste) are a growing environmental cost of computing
    A hub diagram with public wellbeing at the centre, linked to health and safety concerns, the public interest, benefits to the public and concerns of the public
    Software development affects the public's wellbeing in several ways

    Typical principles

    • public interest first — protect the safety and welfare of those affected.
    • honesty and competence — be honest about your skills; don't claim expertise you lack.
    • confidentiality 保密性 — protect clients' and employers' private information.
    • avoid conflicts of interest 利益冲突 — don't take work where your interest clashes with the client's.
    • keep your skills current; respect intellectual property 知识产权 and privacy 隐私; treat colleagues fairly.

    Acting ethically vs unethically

    Acting ethically protects users, strengthens reputation, reduces legal risk, and builds trust. Acting unethically (skipping testing, hiding bugs, misusing data) can harm real users, lead to dismissal or legal action, damage reputation, and erode trust in technology generally.

    When you face a borderline decision: identify whose interests are affected, check the code of ethics and the law, weigh the consequences, ask a trusted senior, and choose the option that protects users above short-term convenience.

    Worked example. Your team's new AI hiring tool sorts CVs ten times faster, but you notice it rejects more older applicants. Shipping it pleases your manager, but it treats one group unfairly. The ethical choice is to hold it back until the bias is fixed — public interest and fairness come before short-term convenience.

    Explore

    Risk and responsibility lab

    Sort examples by the rule, risk or protection involved.

    Vocabulary Train
    English Chinese Pinyin
    ethics 伦理 lún lǐ
    confidentiality 保密性 bǎo mì xìng
    conflicts of interest 利益冲突 lì yì chōng tū
    intellectual property 知识产权 zhī shí chǎn quán
    privacy 隐私 yǐn sī
    7.1

    Copyright

    Copyright 版权 is the legal right of the creator of an original work to control how it is copied, distributed, modified and performed. It applies automatically (no registration) to source code, software, documents, images, audio and video.

    Without copyright, anyone could copy software freely, the developer would not be paid, and plagiarism would be legal. With copyright, developers can earn from their work (encouraging more software), users know who made it, and re-use happens on the developer's terms through licensing. Copyright lasts a long time (often 70 years after the creator's death). General ideas and algorithms are not covered by copyright but may be covered by a patent 专利.

    Copyright is automatic with no registration and lasts about 70 years after the creator's death, covering code, images and documents; a patent must be filed and lasts about 20 years, covering inventions and algorithms
    Copyright is automatic and long-lasting; a patent must be filed and lasts about 20 years
    Explore

    Risk and responsibility lab

    Sort examples by the rule, risk or protection involved.

    Vocabulary Train
    English Chinese Pinyin
    copyright 版权 bǎn quán
    patent 专利 zhuān lì
    7.1

    Software licences

    A software licence 软件许可证 is a contract granting permission to use software on the owner's terms; choosing and applying one is called software licencing.

    Commercial (proprietary)

    • commercial software is sold: you buy a licence; the software is used only within its terms.
    • the source code is not given (a proprietary 专有 product); you cannot modify or redistribute it.
    • examples: Microsoft Office, Adobe Photoshop, most games.

    Used when the developer wants revenue per user and to keep control of the code.

    Open-source

    • the source code is public; users can read, modify and redistribute it (open-source 开源).
    • permissive licences (MIT, BSD) allow almost any use; copyleft 著佐权 licences (GPL) require that modified versions are released under the same licence ("share-alike").
    • the Free Software Foundation (FSF) and the Open Source Initiative (OSI) promote and approve open-source licences.
    • examples: Linux, Python, Apache.

    Used when the developer wants the software widely used and improved by the community.

    Freeware and shareware

    • freeware 免费软件 — free of charge, no source code, may be redistributed but not modified (Acrobat Reader, WhatsApp).
    • shareware 共享软件 — free for a trial period, then you pay to keep using it; no source code.
    Type Cost Source Redistribute Modify
    Commercial Paid No No No
    Open-source Free Yes Yes Often, with conditions
    Freeware Free No Yes No
    Shareware Free trial, then paid No Sometimes No
    A decision tree for choosing a licence: if you want to sell it or keep control, choose commercial; otherwise if you share the source code, choose open-source; otherwise if it is free forever, choose freeware, else shareware (a free trial then pay)
    Choosing a licence from the developer's goal

    To justify a licence choice, link it to the developer's goal (revenue, reach, community), the user's needs (cost, customising), and the use case.

    Vocabulary Train
    English Chinese Pinyin
    software licence 软件许可证 ruǎn jiàn xǔ kě zhèng
    proprietary 专有 zhuān yǒu
    open-source 开源 kāi yuán
    copyleft 著佐权 zhù zuǒ quán
    freeware 免费软件 miǎn fèi ruǎn jiàn
    shareware 共享软件 gòng xiǎng ruǎn jiàn
    7.1

    Artificial Intelligence (AI)

    Artificial intelligence 人工智能 builds systems that do tasks once thought to need human intelligence — recognising speech and images, translating, playing games, driving.

    Most modern AI uses machine learning 机器学习 — algorithms that improve at a task by learning patterns from large amounts of data, instead of being programmed step by step. Deep learning 深度学习, using neural networks 神经网络 with many layers, is the leading approach today.

    Everyday examples

    AI tasks split into two kinds — understanding input, and producing output or decisions.

    Understanding input:

    • speech recognition 语音识别 — spoken words to text (voice assistants).
    • image recognition 图像识别 — finding objects, faces or text in images.

    Producing output or decisions:

    • machine translation 机器翻译 — automatic translation between languages.
    • recommendation systems 推荐系统 — suggesting products, videos or music.
    • autonomous vehicles 自动驾驶汽车 and robots.

    A common exam scenario: a program reads a label with a camera, translates it, and reads it aloud — using optical character recognition 光学字符识别 to find the words, machine translation to convert them, and text-to-speech 文本转语音 for the audio.

    Reading a foreign label aloud: the camera image goes to OCR to find the words, then to machine translation, then to text-to-speech for the audio
    A common scenario: OCR → machine translation → text-to-speech reads a foreign label aloud

    Benefits

    • accessibility — speech/image AI helps users with impairments; translation helps non-native speakers.
    • productivity — automating repetitive tasks frees people for creative work.
    • decision support — AI spots patterns in huge datasets (medical diagnosis, fraud detection).
    • always available, and personalised to each user.

    Concerns

    • bias 偏见 — unfair patterns in the training data become unfair AI decisions (hiring, lending).
    • job displacement — AI may replace some roles.
    • privacy — training often uses large amounts of personal data.
    • transparency — large models are "black boxes", hard to explain.
    • accountability — when AI is wrong, who is responsible: developer, user, or operator?
    • misuse — deepfakes, misinformation, surveillance.
    Biased training data leads the model to learn the bias, which then produces unfair decisions such as in hiring or lending
    How bias gets into AI: biased data → a biased model → unfair decisions

    Professionals must understand the limits of the AI they build, inform users, and reduce harm.

    Explore

    Computing concept lab

    Classify concrete examples by the computing idea they demonstrate.

    Vocabulary Train
    English Chinese Pinyin
    artificial intelligence 人工智能 rén gōng zhì néng
    machine learning 机器学习 jī qì xué xí
    deep learning 深度学习 shēn dù xué xí
    neural networks 神经网络 shén jīng wǎng luò
    speech recognition 语音识别 yǔ yīn shí bié
    image recognition 图像识别 tú xiàng shí bié
    machine translation 机器翻译 jī qì fān yì
    recommendation systems 推荐系统 tuī jiàn xì tǒng
    autonomous vehicles 自动驾驶汽车 zì dòng jià shǐ qì chē
    optical character recognition 光学字符识别 guāng xué zì fú shí bié
    text-to-speech 文本转语音 wén běn zhuǎn yǔ yīn
    bias 偏见 piān jiàn
    7.1

    Exam tips

    • Answer ethics questions against a professional code of conduct (public interest, competence, honesty), not personal opinion.
    • Distinguish copyright (protects the expression) from a patent (protects an invention).
    • Compare software licences: proprietary, open-source, freeware, shareware and FOSS.
  • 8 Databases
    8.1

    File-based storage and its limits

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the limitations of using a file-based approach for the storage and retrieval of data
    Describe the features of a relational database that address the limitations of a file-based approach
    Show understanding of and use the terminology associated with a relational database model Including entity, table, record, field, tuple, attribute, primary key, candidate key, secondary key, foreign key, relationship (one-to-many, one-to-one, many-to-many), referential integrity, indexing
    Use an entity-relationship (E-R) diagram to document a database design
    Show understanding of the normalisation process First Normal Form (1NF), Second Normal Form (2NF) and Third Normal Form (3NF)
    Explain why a given set of database tables are, or are not, in 3NF
    Produce a normalised database design for a description of a database, a given set of data, or a given set of tables

    Source: Cambridge International syllabus

    Before databases, programs stored data in flat files 平面文件 — usually one file per program. This is fine for small data but breaks down at scale.

    A hand searching a card-index filing cabinet
    File-based storage keeps data in separate files, like papers in a filing cabinet — hard to search and easy to duplicate

    Limitations

    • data redundancy 数据冗余 — the same data (a customer's address) is held in several files.
    • data inconsistency 数据不一致 — redundant copies updated separately get out of sync.
    • data dependence — programs are tied to the file format; change the format and every program must be rewritten.
    • hard to enforce integrity 完整性, hard to share safely, weak querying, and weak per-field security.
    An opened hard disk drive showing its platters and read/write head
    The files themselves are stored on devices such as hard disk drives
    The Payroll and Sales programs each link to their own separate data file, so the Staff Number field is stored twice
    The file-based approach: each program keeps its own files

    A relational database 关系数据库 fixes these by storing data in tables managed by one piece of software (the DBMS) that all programs use.

    One DBMS holding tables design, validation rules, access rights and the data, with a single shared database, used by both the payroll and sales applications
    The database approach: one DBMS serves all the programs
    Vocabulary Train
    English Chinese Pinyin
    flat files 平面文件 píng miàn wén jiàn
    data redundancy 数据冗余 shù jù rǒng yú
    data inconsistency 数据不一致 shù jù bù yī zhì
    integrity 完整性 wán zhěng xìng
    relational database 关系数据库 guān xì shù jù kù
    8.1

    Relational model — terms

    • table (relation) — a grid of rows and columns; one table per type of entity 实体 (e.g. CUSTOMER).
    • record 记录 (row, also called a tuple 元组) — one row; one instance of the entity.
    • field 字段 (column, also called an attribute 属性) — one column; one piece of information about each record.
    • primary key 主键 — a field (or fields) that uniquely identifies each record; never null or duplicated.
    • foreign key 外键 — a field whose value matches the primary key of another table, linking the two.
    • composite key 复合键 — a primary key made of two or more fields together.
    • candidate key 候选键 — any field(s) that could be the primary key.
    • secondary key 次键 — a non-primary field that is indexed for fast searching.
    • indexing 索引 — building an index on a field so look-ups and joins run faster.
    • referential integrity 参照完整性 — every foreign-key value must match an existing primary key (no orphan records).

    A table is written in shorthand with the primary key underlined and foreign keys noted:

    CUSTOMER(CustomerID, Name, Phone)
    ORDER(OrderID, CustomerID, OrderDate)   -- CustomerID is FK → CUSTOMER
    
    Two tables linked by a foreign key: the CUSTOMER table has primary key CustomerID; the ORDER table has its own primary key OrderID plus a CustomerID foreign key whose value matches a CustomerID in CUSTOMER
    A foreign key links two tables: ORDER.CustomerID matches the primary key CUSTOMER.CustomerID
    Explore

    Read a relational table with SELECT

    A relational table is just rows (records) and columns (fields). WHERE keeps the rows that match a condition; SELECT then keeps only the columns you asked for.

    Vocabulary Train
    English Chinese Pinyin
    table biǎo
    entity 实体 shí tǐ
    record 记录 jì lù
    field 字段 zì duàn
    primary key 主键 zhǔ jiàn
    foreign key 外键 wài jiàn
    composite key 复合键 fù hé jiàn
    candidate key 候选键 hòu xuǎn jiàn
    referential integrity 参照完整性 cān zhào wán zhěng xìng
    tuple 元组 yuán zǔ
    attribute 属性 shǔ xìng
    secondary key 次键 cì jiàn
    indexing 索引 suǒ yǐn
    8.1

    Entity-relationship (E-R) diagrams

    An entity-relationship diagram 实体关系图 shows the structure: each entity is a rectangle, each relationship a line, with the cardinality 基数 marked at each end:

    • one-to-one (1:1).
    • one-to-many 一对多 (1:M) — each Customer has many Orders; each Order has one Customer.
    • many-to-many (M:N) — Students take many Courses, and Courses have many Students.
    An E-R diagram with a STUDENT entity and a CLASS entity joined by a relationship line, crow's-foot many at the student end and one bar at the class end
    An E-R diagram: one class has many students
    Crow's-foot line-end symbols for one, many, one and only one, zero or one, one or many, and zero or many
    Crow's-foot symbols for the cardinality of a relationship

    A many-to-many relationship cannot be stored directly. Break it into two one-to-many relationships through a link table 连接表 holding the two foreign keys:

    ENROLMENT(StudentID, CourseID, EnrolmentDate)
    
    A many-to-many relationship between STUDENT and COURSE stored as two one-to-many relationships through an ENROLMENT link table holding StudentID and CourseID
    A link table resolves a many-to-many relationship into two one-to-many relationships
    Vocabulary Train
    English Chinese Pinyin
    entity-relationship diagram 实体关系图 shí tǐ guān xì tú
    cardinality 基数 jī shù
    one-to-many 一对多 yī duì duō
    link table 连接表 lián jiē biǎo
    8.1

    Normalisation

    Normalisation 规范化 organises tables to cut redundancy and inconsistency, going through normal forms 范式 in order.

    • First normal form (1NF) — every field holds a single (atomic 原子) value, with no repeating groups, and a primary key.
    • Second normal form (2NF) — in 1NF, and every non-key field depends on the whole primary key (only matters for a composite key).
    • Third normal form (3NF) — in 2NF, and every non-key field depends only on the primary key, not on another non-key field (no transitive dependency 传递依赖).

    A 3NF design stores each fact once, so insert/update/delete anomalies disappear. The trade-off is more tables and more joins. Aim for 3NF.

    To produce a 3NF design: find the entities and their attributes; choose a primary key for each; split repeating/non-atomic fields (1NF); split fields depending on part of a composite key (2NF); split fields depending transitively on the key (3NF); add foreign keys for the relationships.

    Normalisation: one table where the customer name and phone repeat on every order is split into a separate ORDER table and CUSTOMER table, so each fact is stored once
    Normalisation removes redundancy by splitting repeated data into its own table

    Worked example. The table ORDER(OrderID, CustomerID, CustomerName, ProductID, Quantity) has the composite primary key (OrderID, ProductID). Normalise it to 3NF. Test each non-key field against the key. Quantity depends on both OrderID and ProductID, which is fine. But CustomerID depends on OrderID alone - only part of the composite key. That is a partial dependency, so the table is not in 2NF. Split it into ORDER_LINE(OrderID, ProductID, Quantity) and ORDER(OrderID, CustomerID, CustomerName). Now test 3NF: in that new ORDER table, CustomerName depends on CustomerID, which is not the key - a transitive dependency. Split again: ORDER(OrderID, CustomerID) and CUSTOMER(CustomerID, CustomerName). Name the dependency that breaks each form (partial breaks 2NF, transitive breaks 3NF); "it has repeated data" describes the symptom and earns nothing.

    Vocabulary Train
    English Chinese Pinyin
    normalisation 规范化 guī fàn huà
    normal forms 范式 fàn shì
    atomic 原子 yuán zi
    transitive dependency 传递依赖 chuán dì yī lài
    8.2

    Database Management System (DBMS)

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the features provided by a Database Management System (DBMS) that address the issues of a file based approach Including: • data management, including maintaining a data dictionarydata modellinglogical schemadata integritydata security, including backup procedures and the use of access rights to individuals / groups of users
    Show understanding of how software tools found within a DBMS are used in practice Including the use and purpose of: • developer interfacequery processor

    Source: Cambridge International syllabus

    A DBMS 数据库管理系统 manages the database centrally. Features that fix the file-based limits:

    • data dictionary 数据字典 — a description of every table, field, type and key; programs query it instead of hard-coding the structure.
    • redundancy/consistency control — each fact stored once.
    • concurrent access 并发访问 control — locks and transactions let many users work at once.
    • backup 备份 and recovery; security and per-user permissions.
    • integrity rules — keys, unique and range constraints, enforced centrally.
    • transactions 事务 — a group of operations that all succeed or all fail.
    • views 视图 — virtual tables that show each user "their" slice of the data.
    • data management 数据管理 and data modelling 数据建模 — control how data is stored and define its structure as a logical schema 逻辑模式 (the logical design, independent of physical storage).
    • data integrity 数据完整性 and data security 数据安全 — enforce correctness and control access centrally.
    • a query processor 查询处理器 runs queries; a developer interface 开发者接口 gives tools and APIs for building applications.

    Its tools include a data-dictionary editor, a query builder, a forms builder, a report generator, user management, and an SQL editor.

    Explore

    Database service lab

    Watch how a DBMS turns a query into safe shared data access.

    Explore

    Database service lab

    Watch how a DBMS turns a query into safe shared data access.

    Vocabulary Train
    English Chinese Pinyin
    DBMS 数据库管理系统 shù jù kù guǎn lǐ xì tǒng
    data dictionary 数据字典 shù jù zì diǎn
    concurrent access 并发访问 bìng fā fǎng wèn
    backup 备份 bèi fèn
    transactions 事务 shì wù
    views 视图 shì tú
    data management 数据管理 shù jù guǎn lǐ
    data modelling 数据建模 shù jù jiàn mó
    logical schema 逻辑模式 luó jí mó shì
    data integrity 数据完整性 shù jù wán zhěng xìng
    data security 数据安全 shù jù ān quán
    query processor 查询处理器 chá xún chǔ lǐ qì
    developer interface 开发者接口 kāi fā zhě jiē kǒu
    8.3

    DDL and DML

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding that the DBMS carries out all creation/modification of the database structure using its Data Definition Language (DDL)
    Show understanding that the DBMS carries out all queries and maintenance of data using its DML
    Show understanding that the industry standard for both DDL and DML is Structured Query Language (SQL) Understand a given SQL statement
    Understand given SQL (DDL) statements and be able to write simple SQL (DDL) statements using a sub-set of statements Create a database (CREATE DATABASE) Create a table definition (CREATE TABLE), including the creation of attributes with appropriate data types: • CHARACTER • VARCHAR(n) • BOOLEAN • INTEGER • REAL • DATE • TIME change a table definition (ALTER TABLE) add a primary key to a table (PRIMARY KEY (field)) add a foreign key to a table (FOREIGN KEY (field) REFERENCES Table (Field))
    Write an SQL script to query or modify data (DML) which are stored in (at most two) database tables Queries including SELECT... FROM, WHERE, ORDER BY, GROUP BY, INNER JOIN, SUM, COUNT, AVG
    Data maintenance including INSERT INTO, DELETE FROM, UPDATE

    Source: Cambridge International syllabus

    SQL 结构化查询语言 (Structured Query Language) has two halves:

    SQL splits into DDL (builds the structure) and DML (works with the data)
    DDL builds the database structure; DML works with the data
    • Data Definition Language 数据定义语言 (DDL) — creates or changes the structure (tables, keys, constraints).
    • Data Manipulation Language 数据操纵语言 (DML) — works with the data (insert, update, delete, query 查询).

    DDL basics

    CREATE TABLE CUSTOMER (
      CustomerID INTEGER PRIMARY KEY,
      Name VARCHAR(50) NOT NULL,
      Phone VARCHAR(20)
    );
    

    Add a foreign key:

    CREATE TABLE ORDER (
      OrderID INTEGER PRIMARY KEY,
      CustomerID INTEGER,
      OrderDate DATE,
      FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID)
    );
    

    Modify and drop:

    ALTER TABLE CUSTOMER ADD Email VARCHAR(100);
    DROP TABLE CUSTOMER;
    

    Common types: INTEGER, REAL, VARCHAR(n), CHAR(n) (also CHARACTER(n)), DATE, TIME, BOOLEAN, DECIMAL(p, s).

    DML basics

    Query with SELECT:

    A SELECT query returns just the rows that match its condition
    A SELECT query returns only the rows that match its condition
    SELECT Name, Phone
    FROM CUSTOMER
    WHERE City = 'London'
    ORDER BY Name ASC;
    

    SELECT lists fields, FROM names the table, WHERE filters rows, ORDER BY sorts.

    A join 连接 combines two tables using a foreign-key relationship:

    SELECT C.Name, O.OrderDate
    FROM CUSTOMER C INNER JOIN ORDER O
      ON C.CustomerID = O.CustomerID
    WHERE O.OrderDate >= '2024-01-01';
    

    Aggregate functions 聚合函数 (COUNT, SUM, AVG, MIN, MAX) are often used with GROUP BY:

    SELECT CustomerID, COUNT(*) AS NumOrders
    FROM ORDER
    GROUP BY CustomerID;
    

    Insert, update, delete:

    INSERT INTO CUSTOMER (CustomerID, Name, Phone)
    VALUES (101, 'Ada Lovelace', '020-1234-5678');
    
    UPDATE CUSTOMER SET Phone = '020-9999-0000' WHERE CustomerID = 101;
    
    DELETE FROM CUSTOMER WHERE CustomerID = 101;
    

    Always put a WHERE clause on UPDATE and DELETE, or the change hits every row.

    Tips for exam SQL

    • use the exact table and field names from the question.
    • quote strings with single quotes ('Smith'); don't quote numbers.
    • comparisons: =, <, >, <=, >=, <>.
    • LIKE 'A%' matches anything starting with A (% = any string, _ = one character); IN (1,2,3); BETWEEN 10 AND 20.
    • combine conditions with AND / OR / NOT, and end each statement with a semicolon.
    Explore

    Stitch two tables with INNER JOIN

    A join matches rows where the foreign key equals the primary key — here Orders.CustomerID = Customer.CustomerID — and combines each matching pair into one wider row.

    Explore

    SELECT … WHERE

    Step through a query: WHERE keeps the rows that match, then SELECT picks the columns you asked for.

    Vocabulary Train
    English Chinese Pinyin
    SQL 结构化查询语言 jié gòu huà chá xún yǔ yán
    Data Definition Language 数据定义语言 shù jù dìng yì yǔ yán
    Data Manipulation Language 数据操纵语言 shù jù cāo zòng yǔ yán
    query 查询 chá xún
    join 连接 lián jiē
    aggregate functions 聚合函数 jù hé hán shù
    8.3

    Exam tips

    • Define the terms exactly: entity, attribute, primary key, foreign key, and the relationship types (1:1, 1:many, many:many).
    • Give a reason at each normal form: 1NF (no repeating groups), 2NF (no partial dependency), 3NF (no non-key dependency).
    • Explain what a DBMS provides (data independence, security, integrity, concurrent access).
    • Distinguish DDL (define the structure) from DML (query and change the data).
  • 9 Algorithm Design and Problem-solving
    9.1

    Computational thinking

    Syllabus
    Candidates should be able to: Notes and guidance
    Show an understanding of abstraction Need for and benefits of using abstraction Describe the purpose of abstraction Produce an abstract model of a system by only including essential details
    Describe and use decomposition Break down problems into sub-problems leading to the concept of a program module (procedure / function)

    Source: Cambridge International syllabus

    Computational thinking 计算思维 is the set of mental tools for analysing a problem and designing a solution a computer can run. Two key ones are abstraction and decomposition.

    A part-finished jigsaw puzzle
    Computational thinking breaks a big problem into smaller, easier parts — like solving a jigsaw

    Abstraction

    Abstraction 抽象 means keeping the essential features of a problem and ignoring the irrelevant detail, giving a simpler model.

    Examples:

    • a train-network map keeps the stations and lines but drops the geography.
    • a class in object-oriented programming keeps only the attributes and methods the system needs.
    • a function hides a piece of work behind a name.

    A full model of any real problem would be too big to reason about, so abstraction is essential.

    Abstraction turns a cluttered real geography (a wiggly route with scattered buildings) into a clean metro map — evenly spaced station circles on a straight line, keeping the stations and lines and dropping the geography
    Abstraction keeps the essentials (stations and lines) and drops irrelevant detail (the geography)

    Decomposition

    Decomposition 分解 means breaking a large problem into smaller sub-problems, each easier to solve and tackled one at a time.

    1. find the main parts of the task.
    2. break each into smaller sub-tasks.
    3. continue until each is small enough to design directly.
    4. solve the small tasks and combine them.

    For stock control: "manage stock" → "record sales", "record deliveries", "produce reports" → ("record sales") "look up product", "decrease stock count", "save the transaction". Decomposition makes big problems manageable, lets a team divide the work, and gives modular code — each module becomes a procedure 过程 or function.

    A tree with "Manage stock" at the top branching into the modules "Record sales", "Record deliveries" and "Produce reports", and "Record sales" splitting into the sub-tasks "Look up product", "Decrease stock count" and "Save the transaction"
    Decomposing a program into modules and sub-modules
    Explore

    Solving a problem the computational way

    Step through the four cornerstones in the order you'd use them — break the problem down, spot what repeats, strip it to essentials, then write the steps.

    Vocabulary Train
    English Chinese Pinyin
    computational thinking 计算思维 jì suàn sī wéi
    abstraction 抽象 chōu xiàng
    decomposition 分解 fēn jiě
    procedure 过程 guò chéng
    9.2

    Algorithms

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding that an algorithm is a solution to a problem expressed as a sequence of defined steps
    Use suitable identifier names for the representation of data used by a problem and represent these using an identifier table
    Write pseudocode that contains input, process and output
    Write pseudocode using the three basic constructs of sequence, selection and iteration (repetition)
    Document a simple algorithm using a structured English description, a flowchart or pseudocode
    Write pseudocode from: • a structured English description • a flowchart
    Draw a flowchart from: • a structured English description • pseudocode
    Describe and use the process of stepwise refinement to express an algorithm to a level of detail from which the task may be programmed
    Use logic statements to define parts of an algorithm solution

    Source: Cambridge International syllabus

    Bubble sort, pass by pass

    An algorithm 算法 is a solution expressed as a sequence of defined steps. Each step is unambiguous 无歧义 (one meaning), deterministic 确定性 (same input → same output), finite (the steps end), and effective (each can be done). An algorithm says what to do, independent of the programming language used to implement it.

    Explore

    Selection: follow the IF / ELSE branches

    Drag the score and watch which branch runs. Selection tests each condition in turn and takes the FIRST one that is true — that is how IF … ELSE IF … ELSE works.

    Vocabulary Train
    English Chinese Pinyin
    algorithm 算法 suàn fǎ
    unambiguous 无歧义 wú qí yì
    deterministic 确定性 què dìng xìng
    9.2

    Identifier table

    When you start an algorithm, list every piece of data in an identifier table 标识符表 — its variable 变量 name, data type 数据类型, and description:

    Variable name Data type Description
    Category STRING the product category
    SaleDate DATE when the item was sold
    ItemCost REAL cost of the item
    InStock BOOLEAN TRUE if in stock

    Use descriptive names (ItemCost, not x); common types are INTEGER, REAL, STRING, CHAR, BOOLEAN, DATE, plus arrays. The table forces you to name every piece of data before writing code.

    An identifier table listing each variable with its name, data type and description, for example ItemCost as a REAL for the cost of the item
    An identifier table names every piece of data before you write code
    Vocabulary Train
    English Chinese Pinyin
    identifier table 标识符表 biāo shí fú biǎo
    variable 变量 biàn liàng
    data type 数据类型 shù jù lèi xíng
    9.2

    Pseudocode — the three basic constructs

    Pseudocode 伪代码 is a structured, language-neutral way to describe algorithms.

    The three basic constructs as mini-flowcharts: sequence runs step A then B then C; selection tests a condition and does X or Y; iteration repeats a body while a condition holds, looping back
    The three building blocks of any algorithm: sequence, selection and iteration

    1. Sequence

    Steps run one after another (sequence 顺序):

    INPUT Name
    INPUT Age
    OUTPUT "Hello", Name
    

    2. Selection

    A choice of which steps run, based on a condition (selection 选择):

    IF Age >= 18 THEN
        OUTPUT "Adult"
    ELSE
        OUTPUT "Minor"
    ENDIF
    

    For more options, use CASE OF ... ENDCASE.

    3. Iteration

    Repeating a block (iteration 迭代, a loop 循环):

    FOR i ← 1 TO 10
        OUTPUT i
    NEXT i
    

    A WHILE loop tests the condition before each pass (may run zero times); a REPEAT...UNTIL loop tests after each pass (always runs at least once).

    Common operations

    • assignment 赋值: x ← 5 (an arrow; = is for comparison).
    • input/output: INPUT variable, OUTPUT expression.
    • comparisons =, <>, <, >, <=, >=; logic AND, OR, NOT.
    • arithmetic + - * /, plus DIV (integer division) and MOD (remainder).
    • strings: LENGTH, LEFT, RIGHT, MID, and & for concatenation 拼接 (joining).

    Input → Process → Output

    Every program follows this shape:

    INPUT Length
    INPUT Width
    Area ← Length * Width
    OUTPUT "Area = ", Area
    

    Listing the inputs and outputs first makes the algorithm cleaner.

    Every program follows the shape input, then process, then output, shown with the area example: input the length and width, process by multiplying, output the area
    Every program follows the Input, Process, Output shape
    Explore

    IF … ELSE selection

    Change the value and watch which branch runs — how a program makes a decision.

    Vocabulary Train
    English Chinese Pinyin
    pseudocode 伪代码 wěi dài mǎ
    sequence 顺序 shùn xù
    selection 选择 xuǎn zé
    iteration 迭代 dié dài
    loop 循环 xún huán
    assignment 赋值 fù zhí
    concatenation 拼接 pīn jiē
    9.2

    Three notations

    The same algorithm can be written three ways.

    • structured English 结构化英语 — natural language with indentation and fixed keywords; good for a high-level description.
    • flowchart 流程图 — a diagram with standard shapes:
    Shape Meaning
    Rounded rectangle Start / Stop
    Parallelogram Input / Output
    Rectangle Process
    Diamond Decision
    Arrow Flow of control
    • pseudocode — the keyword notation above; closest to code.

    You should be able to convert between any pair: each IF is a decision diamond, each loop is a back-arrow, and a sequence is stacked rectangles.

    A flowchart for averaging numbers: rounded Start and Stop terminators, input/output parallelograms, process rectangles, and a "count < n?" decision diamond whose Yes branch loops back to read the next value
    A flowchart for averaging a list of numbers, using the standard shapes
    Vocabulary Train
    English Chinese Pinyin
    structured English 结构化英语 jié gòu huà yīng yǔ
    flowchart 流程图 liú chéng tú
    9.2

    Stepwise refinement

    Stepwise refinement 逐步求精 starts with a high-level outline and expands each step until it is small enough to code. For an average of $n$ numbers:

    Level 1:

    Read in the numbers
    Compute the average
    Output the average
    

    Level 2:

    INPUT n
    total ← 0
    FOR i ← 1 TO n
        INPUT value
        total ← total + value
    NEXT i
    average ← total / n
    OUTPUT average
    

    Each refinement keeps the previous structure and adds detail.

    Stepwise refinement: a Level 1 outline (read in the numbers, compute the average, output the average) is expanded into Level 2 detailed pseudocode with the input loop and the division
    Stepwise refinement: expand each high-level step into detailed pseudocode
    Explore

    Stepwise refinement: outline to code

    Step down the levels. You start with the whole task in one line and keep expanding each step into smaller ones — until every step is simple enough to code directly.

    Vocabulary Train
    English Chinese Pinyin
    stepwise refinement 逐步求精 zhú bù qiú jīng
    9.2

    Logic statements

    A logic statement 逻辑语句 is a Boolean 布尔 condition that controls branching, built from comparisons (x > 10), connectives (AND, OR, NOT) and brackets. Use it as the condition of IF, WHILE or REPEAT...UNTIL:

    WHILE attempts < 3 AND NOT loggedIn DO
        INPUT password
        IF password = correctPassword THEN
            loggedIn ← TRUE
        ELSE
            attempts ← attempts + 1
        ENDIF
    ENDWHILE
    

    Precedence 优先级 (highest to lowest): NOT, then AND, then OR. Use brackets when unsure. Common mistakes:

    • a = 1 OR 2 is wrong — write a = 1 OR a = 2.
    • NOT a > 5 means NOT (a > 5), i.e. a <= 5.
    • NOT (A AND B) is the same as (NOT A) OR (NOT B) (De Morgan's law 德摩根定律) — handy for simplifying conditions.
    A parse tree for "attempts < 3 AND NOT loggedIn": NOT applies to loggedIn first, then AND joins that with attempts < 3
    Precedence: NOT binds to loggedIn first, then AND combines the two sides

    Worked example. Write an identifier table and pseudocode to read 10 numbers and output the largest. The identifier table names each variable with its data type and purpose: Count : INTEGER (loop counter), Num : REAL (the number just read), Max : REAL (largest so far).

    Max ← -999999
    FOR Count ← 1 TO 10
        INPUT Num
        IF Num > Max THEN
            Max ← Num
        ENDIF
    NEXT Count
    OUTPUT Max
    

    The design decision carrying the marks is initialising Max: it must start lower than any possible input - or, safer still, be set to the first number read. Initialise it to 0 and the algorithm wrongly returns 0 for a list of negative numbers, a bug your trace only exposes if the test data include a negative.

    Vocabulary Train
    English Chinese Pinyin
    logic statement 逻辑语句 luó jí yǔ jù
    Boolean 布尔 bù ěr
    precedence 优先级 yōu xiān jí
    De Morgan's law 德摩根定律 dé mó gēn dìng lǜ
    9.2

    Exam tips

    • Define an algorithm as an unambiguous, finite, deterministic sequence of steps, independent of language.
    • Use the three constructs correctly — sequence, selection, iteration — and keep an identifier table with data types.
    • Break a problem down by decomposition and abstraction, then stepwise refinement.
    • Write pseudocode that would actually run: declare variables and follow the exam's pseudocode style.
  • 10 Data Types and Structures
    10.1

    Choosing data types

    Syllabus
    Candidates should be able to: Notes and guidance
    Select and use appropriate data types for a problem solution including integer, real, char, string, Boolean, date (pseudocode will use the following data types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE, ARRAY, FILE)
    Show understanding of the purpose of a record structure to hold a set of data of different data types under one identifier Write pseudocode to define a record structure
    Write pseudocode to read data from a record structure and save data to a record structure

    Source: Cambridge International syllabus

    Every variable needs a data type 数据类型 — the kind of value it holds and the operations allowed:

    • INTEGER — a whole number (42, -7). For counts, indexes, IDs.
    • REAL — a number with a fractional part (3.14). For money, measurements.
    • STRING — characters in quotes ("Hello"). For text.
    • CHAR — a single character ('A').
    • BOOLEANTRUE or FALSE. For flags.
    • DATE — a calendar date.

    Pick the smallest precise type that fits: INTEGER for whole counts, BOOLEAN for flags (not the strings "yes"/"no").

    Vocabulary Train
    English Chinese Pinyin
    data type 数据类型 shù jù lèi xíng
    10.1

    Records

    A record 记录 (a record structure 记录结构) holds several fields of different types under one name — useful when several values describe one thing.

    TYPE TStockItem
        DECLARE ItemID : INTEGER
        DECLARE Category : STRING
        DECLARE ItemCost : REAL
        DECLARE InStock : BOOLEAN
    ENDTYPE
    

    This defines the type TStockItem; declare variables of it:

    DECLARE Item1 : TStockItem
    DECLARE Items : ARRAY[1:100] OF TStockItem
    

    Use dot notation to reach each field 字段:

    Item1.Category ← "Fruit"
    OUTPUT Item1.Category, " costs ", Item1.ItemCost
    

    Use a record when values always belong together (a customer, a stock item); use separate variables for unrelated values.

    A TStockItem record drawn as a stack of four fields under one name — ItemID (INTEGER), Category (STRING), ItemCost (REAL), InStock (BOOLEAN) — reached with dot notation like Item1.Category
    A record holds several fields of different types under one name
    Explore

    A record groups fields under one name

    A record bundles related fields together. Each field is a named label you reach with dot notation — Item1.Category — not by a numeric index.

    Vocabulary Train
    English Chinese Pinyin
    record 记录 jì lù
    field 字段 zì duàn
    record structure 记录结构 jì lù jié gòu
    10.2

    Arrays

    Syllabus
    Candidates should be able to: Notes and guidance
    Use the technical terms associated with arrays Including index, upper bound and lower bound
    Select a suitable data structure (1D or 2D array) to use for a given task
    Write pseudocode for 1D and 2D arrays
    Write pseudocode to process array data Sort using a bubble sort Search using a linear search

    Source: Cambridge International syllabus

    An array 数组 is an ordered collection of items of the same type, under one name, reached by an index 索引.

    • element 元素 — one item in the array.
    • bounds 边界 — the lowest and highest valid indices.
    • dimension 维度 — 1-D (a list), 2-D (a table), etc.

    1-D arrays

    DECLARE Names : ARRAY[1:5] OF STRING
    Names[3] ← "Cara"
    OUTPUT Names[3]
    

    Process every element with a FOR loop:

    FOR i ← 1 TO 5
        OUTPUT Names[i]
    NEXT i
    
    A row of indexed cells named myList, with indices 0 to 8 and the lower bound (first index) and upper bound (last index) marked
    A 1-D array (a list) with indices and bounds

    2-D arrays (2D array)

    DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER
    Grid[2, 3] ← 99
    

    The first index is the row, the second the column. Use nested loops to visit every cell. Use 1-D for a single sequence, 2-D for two natural dimensions (a grid, rows × columns).

    A 3 by 4 grid with row indices and column indices; the cell at row 2, column 3 is highlighted
    A 2-D array (a table) with row and column indices

    Common operations

    A linear search 线性查找 checks each element until found:

    FOR i ← 1 TO n
        IF A[i] = Target THEN
            OUTPUT "Found at ", i
        ENDIF
    NEXT i
    

    To find a sum, count, maximum or minimum, set a running variable then sweep through:

    Max ← A[1]
    FOR i ← 2 TO n
        IF A[i] > Max THEN Max ← A[i]
    NEXT i
    

    A bubble sort 冒泡排序 puts an array in order: pass through it comparing each adjacent pair and swapping any that are out of order; repeat the passes until one pass makes no swaps.

    One pass of a bubble sort over 5, 2, 8, 1: compare 5 and 2 and swap to give 2, 5, 8, 1; compare 5 and 8 (already in order); compare 8 and 1 and swap to give 2, 5, 1, 8, so the largest value 8 reaches the end
    One pass of a bubble sort: adjacent pairs are compared and swapped, bubbling the largest value to the end
    Explore

    A 2-D array

    Pick a row and column to read one element — how a grid of data is stored and indexed.

    Vocabulary Train
    English Chinese Pinyin
    array 数组 shù zǔ
    index 索引 suǒ yǐn
    element 元素 yuán sù
    bounds 边界 biān jiè
    dimension 维度 wéi dù
    linear search 线性查找 xiàn xìng chá zhǎo
    bubble sort 冒泡排序 mào pào pái xù
    10.3

    Files

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of why files are needed
    Write pseudocode to handle text files that consist of one or more lines

    Source: Cambridge International syllabus

    A file 文件 is data stored on secondary storage 辅助存储器, kept between program runs. Variables in RAM disappear when the program ends, so to save data permanently (high scores, records, settings) the program writes to a file. Files also let programs share data and restart from a saved state.

    Variables in RAM are lost when the program ends, but a file on disk is kept between runs, so the program saves to and loads from it
    Variables in RAM vanish when the program ends; a file on disk persists between runs

    A text file 文本文件 holds one or more lines of readable characters; programs read and write text files line by line. Open a file before use and close it after:

    OPENFILE "data.txt" FOR READ      // or FOR WRITE, FOR APPEND
    WHILE NOT EOF("data.txt") DO
        READFILE "data.txt", LineString
        OUTPUT LineString
    ENDWHILE
    CLOSEFILE "data.txt"
    

    EOF tests the end of file 文件结束 before reading. To write:

    OPENFILE "log.txt" FOR WRITE
    FOR i ← 1 TO 100
        WRITEFILE "log.txt", "Event " & i
    NEXT i
    CLOSEFILE "log.txt"
    

    Always close every file — otherwise buffered writes may be lost and other programs may be locked out.

    Explore

    Handling a file: open → use → close

    Step through the lifecycle every file follows. The two easy-to-forget parts are testing EOF while reading in a loop, and always closing at the end.

    Vocabulary Train
    English Chinese Pinyin
    file 文件 wén jiàn
    secondary storage 辅助存储器 fǔ zhù cún chǔ qì
    text file 文本文件 wén běn wén jiàn
    end of file 文件结束 wén jiàn jié shù
    10.4

    Abstract Data Types (ADTs)

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding that an ADT is a collection of data and a set of operations on those data
    Show understanding that a stack, queue and linked list are examples of ADTs Describe the key features of a stack, queue and linked list and justify their use for a given situation
    Use a stack, queue and linked list to store data Candidates will not be required to write pseudocode for these structures, but they should be able to add, edit and delete data from these structures
    Describe how a queue, stack and linked list can be implemented using arrays

    Source: Cambridge International syllabus

    Linked list: insert by rewiring pointers
    Stack vs queue: LIFO and FIFO

    An Abstract Data Type 抽象数据类型 (ADT) is a collection of data plus operations on it, defined by what it does, not how it is stored. The user works only through the operations; the implementation is hidden, so it can change without affecting code that uses the ADT. Know three: stack, queue, linked list.

    Stack

    A stack works in LIFO 后进先出 order (Last In, First Out). Operations: push 入栈 (add to the top), pop 出栈 (remove from the top), peek (look at the top), and tests for empty/full. Uses: undo history, function-call return addresses, expression parsing, backtracking.

    A stack stored in an array shown in three states; the Top pointer moves up after a push and down after a pop, while the base of the stack stays fixed
    Push and pop change the top pointer; the base pointer stays put
    A tall pile of books stacked flat on top of one another
    A pile of books is a stack you can see. You can only add or take a book from the top, so the last one you put on is the first one you take off — that is exactly LIFO

    Queue

    A queue 队列 works in FIFO 先进先出 order (First In, First Out). Operations: enqueue 入队 (add to the rear), dequeue 出队 (remove from the front), and tests for empty/full. Uses: print spooling, scheduling, breadth-first search, buffering.

    A linear queue stored in an array shown in three states; enqueue advances the Rear pointer and dequeue advances the Front pointer, leaving the start cell empty and wasted
    Enqueue adds at the rear; dequeue removes from the front
    A very long line of people waiting one behind another, stretching along a wall into the distance
    A line of people is a queue you can see. You join at the back and are served from the front, so whoever waited longest is served first — that is exactly FIFO

    Linked list

    A linked list 链表 stores data as a sequence of nodes 节点. Each node holds a value and a pointer 指针 to the next node; a head pointer marks the start, and the last node's pointer is a sentinel (e.g. NULL). Operations: insert, delete, search, and traverse 遍历 (visit each node in order). Its advantage over an array is cheap insertion/deletion (just adjust pointers); its disadvantage is slow random access (you must follow pointers from the head).

    Four nodes in a row, each holding a value and a next-pointer field; a head pointer points to the first node and the last node's pointer is NULL
    A linked list: each node points to the next
    Explore

    A linked list: nodes joined by pointers

    Each node stores a value and a pointer to the next node. Inserting or deleting just re-links pointers — no items shift along, unlike an array.

    Explore

    Stacks and queues

    Push and pop. A stack is last-in-first-out; a queue is first-in-first-out — two key ADTs.

    Vocabulary Train
    English Chinese Pinyin
    abstract data type 抽象数据类型 chōu xiàng shù jù lèi xíng
    stack zhàn
    LIFO 后进先出 hòu jìn xiān chū
    push 入栈 rù zhàn
    pop 出栈 chū zhàn
    queue 队列 duì liè
    FIFO 先进先出 xiān jìn xiān chū
    enqueue 入队 rù duì
    dequeue 出队 chū duì
    linked list 链表 liàn biǎo
    node 节点 jié diǎn
    pointer 指针 zhǐ zhēn
    traverse 遍历 biàn lì
    10.4

    Implementing ADTs using arrays

    Stack using an array

    Hold items in Stack[1:MaxSize] with an integer Top (0 when empty).

    • Push(x): if Top = MaxSize the stack is full (overflow 溢出); else Top ← Top + 1; Stack[Top] ← x.
    • Pop(): if Top = 0 the stack is empty (underflow 下溢); else return Stack[Top] and Top ← Top - 1.

    Queue using a circular array

    A simple queue lets Front and Rear march off the end, wasting the start. The fix is a circular array 循环数组 — when a pointer reaches MaxSize it wraps back to 1:

    • Enqueue(x): check full; else Rear ← (Rear MOD MaxSize) + 1; Queue[Rear] ← x.
    • Dequeue(): check empty; else return Queue[Front] and Front ← (Front MOD MaxSize) + 1.

    Track a separate count to tell empty from full.

    For example, with MaxSize = 6: if Rear = 5, then (5 MOD 6) + 1 = 6, so the next item goes in cell 6; if Rear = 6, then (6 MOD 6) + 1 = 1, so the pointer wraps back to cell 1.

    A circular queue stored in an array; the filled cells wrap past the last cell back to the start, with a curved arrow showing the pointer wrapping from the last index to cell 1
    A circular queue wraps the pointers back to the start of the array

    Linked list using an array

    Use an array of records, each with a Next index:

    TYPE TNode
        DECLARE Value : INTEGER
        DECLARE Next : INTEGER     // index of the next node, or -1 for end
    ENDTYPE
    
    DECLARE Nodes : ARRAY[1:MaxSize] OF TNode
    DECLARE Head : INTEGER         // index of first node, -1 if empty
    DECLARE FreeListHead : INTEGER // first available free node
    

    A free list 空闲列表 chains the unused slots, just as the data list chains its used ones. To insert: take a slot from FreeListHead, set the new node's value and Next, and update the previous node's Next (or Head). To delete: unlink the node and return its slot to the free list. This gives the flexibility of a linked structure with the static allocation of an array.

    A Value array and a parallel Next array implementing a linked list; a Head pointer chains the used nodes and a FreeListHead pointer chains the free slots, each ending in Next = -1
    A linked list stored in an array: a data array and a pointer array

    Worked example. A circular queue is held in an array of size 5 (indices 0 to 4) with Front = 3, Rear = 3 and one item stored. Two items are added, then two are removed. Where are the pointers, and why use a circular queue at all? Every move uses (pointer + 1) MOD size, so the pointers wrap. Adding twice moves Rear: $3 \rightarrow 4$, then $4 \rightarrow 0$ (because $(4+1) \bmod 5 = 0$), so Rear = 0 and three items are stored. Removing twice moves Front the same way: $3 \rightarrow 4$, then $4 \rightarrow 0$, leaving Front = 0 and one item. The wrap is the whole point: in a linear array queue the pointers march to the end and the freed space at the front is wasted even when the queue is empty. Remember a queue removes at the Front and adds at the Rear - a stack uses one pointer for both.

    Explore

    Implementing ADTs with arrays

    FIFO

    A queue is first-in-first-out — enqueue at the back, dequeue from the front.

    Vocabulary Train
    English Chinese Pinyin
    overflow 溢出 yì chū
    underflow 下溢 xià yì
    circular array 循环数组 xún huán shù zǔ
    free list 空闲列表 kòng xián liè biǎo
    10.4

    Exam tips

    • Choose the right data structure and justify it (a record for mixed fields, a 2-D array for a grid).
    • Know how to implement a stack, queue and linked list with an array and pointers (top; front/rear; next).
    • Distinguish an ADT (its behaviour) from its implementation (array plus pointers).
  • 11 Programming
    11.1

    Programming basics

    Syllabus
    Candidates should be able to: Notes and guidance
    Implement and write pseudocode from a given design presented as either a program flowchart or structured English
    Write pseudocode statements for: • the declaration and initialisation of constants • the declaration of variables • the assignment of values to variables • expressions involving any of the arithmetic or logical operators input from the keyboard and output to the console
    Use built-in functions and library routines Any functions not given in the pseudocode guide will be provided String manipulation functions will always be given

    Source: Cambridge International syllabus

    Lines of source code on a dark screen
    Programming turns a design into instructions written as code
    A programmer working at a computer
    A programmer writes the code and tests it as they go

    From design to code

    You should be able to turn a design — a flowchart 流程图 (program flowchart) or structured English 结构化英语 — into pseudocode 伪代码, and then into a real language:

    1. find the variables 变量 and their data types 数据类型.
    2. turn input/output boxes into INPUT / OUTPUT.
    3. turn decision diamonds into IF...ELSE...ENDIF (or CASE).
    4. turn loop arrows into WHILE, REPEAT...UNTIL, or FOR.
    5. turn process boxes into assignments or calculations.
    6. check by tracing a small input.
    A mapping from flowchart symbols to pseudocode: an input/output parallelogram becomes INPUT or OUTPUT, a decision diamond becomes IF...THEN or CASE, a process box becomes an assignment x = expression, and a loop arrow becomes WHILE, FOR or REPEAT
    Each flowchart symbol becomes a pseudocode keyword

    Constants and variables

    A constant 常量 holds a value that never changes; a variable holds one that may change. Declare them with a type:

    A variable's value can change; a constant stays fixed
    A variable's value can change; a constant stays fixed
    CONSTANT Pi ← 3.14159
    DECLARE Radius : REAL
    DECLARE Area : REAL
    
    Radius ← 5
    Area ← Pi * Radius * Radius
    

    Use constants for fixed values that recur (Pi, MaxScore); they make code clearer and easy to change in one place.

    Assignment and expressions

    Use for assignment 赋值:

    Total ← Total + 1
    Average ← Sum / Count
    

    Expressions use operators 运算符:

    • arithmetic + - * /, plus DIV (integer division) and MOD (remainder): 7 DIV 2 = 3; 7 MOD 2 = 1.
    • comparisons =, <>, <, >, <=, >=.
    • logic AND, OR, NOT.

    Precedence 优先级 (highest to lowest): NOT* / DIV MOD+ - → comparisons → ANDOR. Use brackets when unsure.

    Input and output

    OUTPUT "Enter your name:"
    INPUT Name
    OUTPUT "Hello, ", Name
    

    Built-in functions and library routines

    Many tasks have ready-made library routines 库例程, so you need not write them:

    • string: LENGTH(s), LEFT(s, n), RIGHT(s, n), MID(s, start, len), UCASE(s), LCASE(s).
    • numeric: INT(x), ROUND(x), ABS(x), MOD(a, b), RANDOM().
    • conversion: STR(x) (number → string), VAL(s) (string → number).

    Use the exact names from the question paper's reference list.

    The string COMPUTER shown as eight numbered character boxes (positions 1 to 8), with worked results: LENGTH(s) = 8, LEFT(s, 3) = COM, MID(s, 4, 3) = PUT, RIGHT(s, 2) = ER, and UCASE/LCASE changing the letter case
    The common string routines acting on s = "COMPUTER" (positions 1–8)
    Explore

    A variable is a labelled box

    Each assignment stores one value in a named box; reassigning the same name overwrites it. Step through the program and watch each box take its current value.

    Vocabulary Train
    English Chinese Pinyin
    flowchart 流程图 liú chéng tú
    structured English 结构化英语 jié gòu huà yīng yǔ
    pseudocode 伪代码 wěi dài mǎ
    variables 变量 biàn liàng
    data types 数据类型 shù jù lèi xíng
    constant 常量 cháng liàng
    assignment 赋值 fù zhí
    operators 运算符 yùn suàn fú
    precedence 优先级 yōu xiān jí
    library routines 库例程 kù lì chéng
    11.2

    Selection

    Syllabus
    Candidates should be able to: Notes and guidance
    Use pseudocode to write: • an ‘IF’ statement including the ‘ELSE’ clause and nested IF statements • a ‘CASE’ structure • a ‘count-controlled’ loop: • a ‘post-condition’ loop • a ‘pre-condition’ loop
    Justify why one loop structure may be better suited to solve a problem than the others

    Source: Cambridge International syllabus

    Selection 选择 chooses which steps run.

    IF age >= 18 THEN
        OUTPUT "Adult"
    ELSE
        OUTPUT "Minor"
    ENDIF
    
    A flowchart: from start, a decision diamond tests age >= 18; the TRUE branch outputs Adult and the FALSE branch outputs Minor, and both rejoin at end
    An IF...ELSE tests the condition once, then runs exactly one branch

    For more than two cases you can use a nested 嵌套 IF, but deep nesting is hard to read — a CASE is cleaner when testing one value against several options:

    CASE OF Grade
        "A": OUTPUT "Excellent"
        "B": OUTPUT "Good"
        OTHERWISE: OUTPUT "Try again"
    ENDCASE
    

    Cambridge CASE allows single values, value lists (1, 2, 3:), and ranges (1 TO 5:).

    A flowchart of a CASE OF Grade statement: the value is tested against each guard in turn (a single value, a value list, then a range); the first matching branch runs its statement, otherwise the OTHERWISE branch runs, and all branches rejoin at ENDCASE
    A CASE statement runs the branch that matches the value
    Explore

    Selection (IF / ELSE)

    Change the input and see which branch runs — the essence of selection.

    Vocabulary Train
    English Chinese Pinyin
    selection 选择 xuǎn zé
    nested 嵌套 qiàn tào
    11.2

    Iteration

    Iteration 迭代 repeats a block. Three loops differ in how many times the body runs.

    Count-controlled (FOR) loop

    A count-controlled loop 计数循环 — use it when you know how many times to repeat:

    FOR i ← 1 TO 10
        OUTPUT i
    NEXT i
    

    A STEP can change the count (e.g. FOR i ← 10 TO 1 STEP -1). Best for a fixed number of repeats or processing each element of an array 数组.

    Pre-condition (WHILE) loop

    A pre-condition loop 前测循环 tests the condition before each pass, so it may run zero times:

    WHILE total < 100 DO
        INPUT n
        total ← total + n
    ENDWHILE
    

    Post-condition (REPEAT...UNTIL) loop

    A post-condition loop 后测循环 tests the condition after each pass, so it always runs at least once:

    REPEAT
        INPUT password
    UNTIL password = correctPassword
    

    Choosing the right loop

    Three flowchart columns. FOR: a count box (i = 1 to N) then a body box, looping back, for a set number of passes. WHILE: a test diamond above a body box, so the condition is checked before the body and the loop may run zero times. REPEAT: a body box above a test diamond, so the condition is checked after the body and the loop runs at least once
    The three loops differ in where the condition is tested — before the body (WHILE), after it (REPEAT), or a set number of times (FOR)
    • count known up front → FOR.
    • may need zero passes → WHILE.
    • always at least one pass → REPEAT...UNTIL.

    Justify your choice by whether the count is known and whether the body must run at least once. A typical question gives a scenario ("ask for a password until correct, but always ask at least once") and asks which loop fits.

    Explore

    Trace a loop, pass by pass

    A trace table records each variable after every pass of the loop. Watch the counter i climb while the running total builds up — exactly what an exam trace question asks you to fill in.

    Explore

    Tracing a loop

    Step through the loop and watch the variables change each pass — exactly what a trace table records.

    Vocabulary Train
    English Chinese Pinyin
    iteration 迭代 dié dài
    count-controlled loop 计数循环 jì shù xún huán
    array 数组 shù zǔ
    pre-condition loop 前测循环 qián cè xún huán
    post-condition loop 后测循环 hòu cè xún huán
    11.3

    Procedures and functions

    Syllabus
    Candidates should be able to: Notes and guidance
    Define and use a procedure
    Explain where in the construction of an algorithm it would be appropriate to use a procedure
    Use parameters A procedure may have none, one or more parameters A parameter can be passed by reference or by value
    Define and use a function
    Explain where in the construction of an algorithm it is appropriate to use a function A function is used in an expression, e.g. the return value replaces the call
    Use the terminology associated with procedures and functions including procedure/function header, procedure/function interface, parameter, argument, return value
    Write efficient pseudocode

    Source: Cambridge International syllabus

    Structured programming 结构化编程 builds a program from small named subroutines 子程序, each with one job.

    Procedure

    A procedure 过程 is a named block that does an action; it may take parameters 参数 but does not return a value.

    PROCEDURE Greet(name : STRING)
        OUTPUT "Hello, ", name
    ENDPROCEDURE
    
    CALL Greet("Ada")
    

    Function

    A function 函数 is like a procedure but it returns a value that becomes part of an expression.

    FUNCTION Square(x : INTEGER) RETURNS INTEGER
        RETURN x * x
    ENDFUNCTION
    
    result ← Square(5) + 1     // result = 26
    

    Use a procedure when the subroutine performs an action; use a function when it computes a value for the caller.

    Two panels. Procedure: call Greet(Ada) does an action and prints Hello, Ada, returning no value. Function: set y = Square(5) computes 5 times 5 = 25, returns 25, so y then holds 25
    A procedure does an action and returns nothing; a function returns a value you use in an expression

    Parameters

    A parameter is a variable a subroutine declares to receive input; the values the caller supplies are arguments 实参. Two ways to pass them:

    • pass by value 传值 — the routine gets a copy; changes inside it do not affect the caller. Use for inputs it only reads.
    • pass by reference 传引用 — the routine gets a reference to the caller's variable; changes do affect the caller. Use when it must update a parameter.
    Two memory-box diagrams. Pass by value: the caller's variable x = 5 is copied into a separate parameter box a = 5, so changing a leaves x as 5. Pass by reference: the parameter a is an arrow pointing to the caller's own x box, so changing a changes x too
    Pass by value copies the value into a new box; pass by reference lets the routine change the caller's own variable
    PROCEDURE Swap(BYREF a : INTEGER, BYREF b : INTEGER)
        DECLARE temp : INTEGER
        temp ← a
        a ← b
        b ← temp
    ENDPROCEDURE
    

    Local vs global variables

    A local variable 局部变量 is declared inside a subroutine and exists only while it runs. A global variable 全局变量 is declared outside and is visible everywhere. Prefer locals and parameters — heavy use of globals makes code hard to follow and test. (The region where a name is visible is its scope 作用域.)

    A large outer box labelled global scope holds the global variable Total, visible everywhere, and a smaller inner box labelled PROCEDURE Calc, local scope, holds the local variable temp, which exists only while Calc runs
    A global variable is visible everywhere; a local variable exists only inside its own procedure

    When to use a subroutine

    Use a subroutine when:

    • the same logic appears in more than one place — write it once, call it many times.
    • a block has a clear named purpose — the name documents what it does.
    • the program is complex — break it into parts (decomposition 分解).
    • you want to test a piece in isolation.

    Don't make them so tiny that the call costs more than the work inside.

    Terminology

    • definition — the PROCEDURE ... ENDPROCEDURE (or function) block.
    • call — where it is invoked. argument — a value passed in. parameter — the variable that receives it.
    • return value — what a function passes back.
    • procedure/function header — the first line giving the name and parameters (PROCEDURE Name(params) or FUNCTION Name(params) RETURNS type).
    • procedure/function interface / signature 签名 — name + parameters + return type: what a caller must know to use it.

    Worked example. Which loop suits each task? (a) print the 12 times table; (b) keep reading numbers until the user enters 0; (c) ask for a password until it is correct. Choose by asking how many times the body runs and when the test happens. (a) The count is known in advance (12), so use a FOR loop. (b) The count is unknown, and the very first input might already be 0 - so the test must come before the body: a WHILE loop, which runs zero or more times. (c) The count is unknown, but you must always ask at least once before there is anything to test - so the test comes after the body: a REPEAT...UNTIL, which runs one or more times. The deciding question is whether the body must run at least once: WHILE may run zero times, REPEAT always runs once.

    Explore

    The call stack: push on call, pop on return

    Calling a subroutine pushes a new frame on top; returning pops it and hands a value back to the caller. The call that is running is always the frame on top.

    Vocabulary Train
    English Chinese Pinyin
    structured programming 结构化编程 jié gòu huà biān chéng
    subroutines 子程序 zi chéng xù
    procedure 过程 guò chéng
    parameters 参数 cān shù
    function 函数 hán shù
    arguments 实参 shí cān
    pass by value 传值 chuán zhí
    pass by reference 传引用 chuán yǐn yòng
    local variable 局部变量 jú bù biàn liàng
    global variable 全局变量 quán jú biàn liàng
    scope 作用域 zuò yòng yù
    decomposition 分解 fēn jiě
    signature 签名 qiān míng
    11.3

    Writing efficient pseudocode

    • move invariants out of loops — if a value (an invariant 不变量) does not change with the loop counter, compute it once before the loop.
    • exit a loop early when the answer is found (stop a linear search 线性查找 as soon as the target appears).
    • avoid redundant work — store a result and reuse it instead of recomputing.
    • choose the right data structure — an array beats many separate variables when the items belong together.
    • replace deep nested IFs with CASE when testing one value against many.
    • comment the intent, not the mechanics (// validate the postcode, not // loop 6 times).
    • use meaningful names (numberOfPupils, not n) and initialise variables before use.
    Move work that never changes out of the loop, so it runs once instead of every pass
    Move unchanging work out of the loop so it runs once
    Vocabulary Train
    English Chinese Pinyin
    invariant 不变量 bù biàn liàng
    linear search 线性查找 xiàn xìng chá zhǎo
    11.3

    Exam tips

    • Distinguish a procedure (no return value) from a function (returns a value); know pass by value vs by reference.
    • Choose the right loop: count-controlled (FOR) when the number of repeats is known, condition-controlled (WHILE/REPEAT) otherwise.
    • Distinguish local vs global variables and scope; prefer local variables in reusable modules.
  • 12 Software Development
    12.1

    Program development life cycle

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the purpose of a development life cycle
    Show understanding of the need for different development life cycles depending on the program being developed Including: waterfall, iterative, rapid application development (RAD)
    Describe the principles, benefits and drawbacks of each type of life cycle
    Show understanding of the analysis, design, coding, testing and maintenance stages in the program development life cycle

    Source: Cambridge International syllabus

    A development life cycle 开发生命周期 is the set of stages from idea to finished, maintained software. It exists to plan, manage and control a project — to build the right product, on time, with good quality.

    A software team collaborating around a table
    Software is built by teams who follow a development life cycle to stay coordinated
    A flowchart with terminators, process boxes and decision diamonds
    A flowchart plans a program's logic during the design stage of the cycle

    Why a life cycle is needed

    It manages complexity (break a big program into phases), coordinates teams, tracks progress with milestones, builds in testing, records design decisions for later, and manages risk.

    Why there are different ones

    No single life cycle fits every project, so several development life cycles exist. The choice depends on the size and complexity, how clear the requirements 需求 are at the start, how much change is expected, the risk level, the team, and the deadline.

    Common models

    • Waterfall 瀑布模型 — a linear sequence (Analysis → Design → Coding → Testing → Maintenance), each stage finished before the next. Clear and well-documented; good for stable requirements, but poor at coping with mid-project change, and the customer sees nothing working until the end.
    • Iterative model 迭代模型 — repeated passes, each producing a partial version that is reviewed and refined. Catches problems earlier; good when requirements are discovered over time, but harder to estimate.
    • Rapid Application Development 快速应用开发 (RAD) — heavy use of a prototype 原型 and user feedback. Very fast first delivery; good for changing requirements, but depends on user availability and suits smaller systems.
    • Agile 敏捷 — short iterations ("sprints"), constant collaboration and testing. Flexible and adaptive, but needs a committed customer and a skilled team.
    Five boxes (Analysis, Design, Coding, Testing, Maintenance) cascading down, each leading to the next
    The waterfall model: each stage is finished before the next begins
    A Design-Build-Test-Review cycle with a repeat loop back to Design, and version bars growing taller each pass until complete
    The iterative model: repeated passes refine the program
    Three parts built in parallel as prototypes that refine with user feedback, then combine into the final system
    Rapid application development: teams work on parts in parallel

    The standard stages

    • analysis — find what the program must do; gather and document requirements.
    • design — decide how: data structures, algorithms, modules, interface, file layouts.
    • coding (implementation 实现**)** — write the source code following the design.
    • testing — run against test data and fix bugs.
    • maintenance 维护 — after release, keep it working and useful.
    Explore

    The program development life cycle

    Step through the stages every project passes through. Getting the requirements right in analysis matters most — a mistake caught in testing is far costlier to fix than one caught early.

    Explore

    Software process lab

    Classify development examples by the stage or tool they belong to.

    Vocabulary Train
    English Chinese Pinyin
    development life cycle 开发生命周期 kāi fā shēng mìng zhōu qī
    requirements 需求 xū qiú
    waterfall 瀑布模型 pù bù mó xíng
    iterative model 迭代模型 dié dài mó xíng
    rapid application development 快速应用开发 kuài sù yìng yòng kāi fā
    prototype 原型 yuán xíng
    agile 敏捷 mǐn jié
    implementation 实现 shí xiàn
    maintenance 维护 wéi hù
    12.2

    Program design tools

    Syllabus
    Candidates should be able to: Notes and guidance
    Use a structure chart to decompose a problem into sub-tasks and express the parameters passed between the various modules/procedures/functions which are part of the algorithm design Describe the purpose of a structure chart Construct a structure chart for a given problem Derive equivalent pseudocode from a structure chart
    Show understanding of the purpose of state-transition diagrams to document an algorithm

    Source: Cambridge International syllabus

    Structure chart

    A structure chart 结构图 shows the hierarchical decomposition 分解 of a program into modules (subroutines 子程序) and the parameters 参数 passed between them. Each module is a rectangle; lines link caller (above) to callee (below); small arrows show data going down and results coming back up. The design can then be turned into equivalent pseudocode 伪代码.

                    CalculatePay
                /        |         \
           GetEmployee  CalculateBonus  CalculateTax
           Returns:     Takes: sales    Takes: gross
           employeeID   Returns: bonus  Returns: tax
    

    It is a design-stage tool, and you can read the procedure signatures off it.

    A structure chart with Convert temperature at the top and INPUT, Convert to Celsius and OUTPUT modules below, with temperature parameters on the links
    A structure chart: modules with the parameters passed between them

    State-transition diagram

    A state-transition diagram 状态转换图 shows the states 状态 a system can be in and the events that move it between them — good for vending machines, traffic lights, user interfaces. State-transition diagrams are used to document the behaviour of an algorithm or system. Each state is a circle; each transition is an arrow labelled with the event.

       coin inserted               item selected
    [Idle] ──────────────→ [Awaiting selection] ──────────→ [Dispensing]
    

    It makes missing transitions easy to spot ("what if a second coin is inserted while awaiting selection?").

    A state diagram: Locked to Waiting for second digit to Waiting for third digit to Unlocked, with correct-digit and wrong-digit transitions
    A state-transition diagram for a door lock with code 259
    Explore

    Software process lab

    Classify development examples by the stage or tool they belong to.

    Vocabulary Train
    English Chinese Pinyin
    structure chart 结构图 jié gòu tú
    decomposition 分解 fēn jiě
    subroutines 子程序 zi chéng xù
    parameters 参数 cān shù
    state-transition diagram 状态转换图 zhuàng tài zhuǎn huàn tú
    states 状态 zhuàng tài
    pseudocode 伪代码 wěi dài mǎ
    12.3

    Errors

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of ways of exposing and avoiding faults in programs
    Locate and identify the different types of errors syntax errorslogic errorsrun-time errors
    Correct identified errors
    Show understanding of the methods of testing available and select appropriate data for a given method Including dry run, walkthrough, white-box, black-box, integration, alpha, beta, acceptance, stub
    Show understanding of the need for a test strategy and test plan and their likely contents
    Choose appropriate test data for a test plan Including normal, abnormal and extreme/boundary
    Show understanding of the need for continuing maintenance of a system and the differences between each type of maintenance Including perfective, adaptive, corrective
    Analyse an existing program and make amendments to enhance functionality

    Source: Cambridge International syllabus

    • syntax error 语法错误 — breaks the language's grammar (missing bracket, misspelled keyword). Caught at translation time; the program won't run until fixed.
    • run-time error 运行时错误 — happens while running (divide by zero, file not found, array index out of range). The program crashes or raises an exception; fix by adding checks.
    • logic error 逻辑错误 — the program runs but gives wrong results (using + for -, an off-by-one loop, conditions in the wrong order). The hardest to find; the only sign is wrong output, so use careful testing and tracing.
    A pipeline from write code to translate to run to output: a syntax error stops it at translation, a run-time error crashes during the run, and a logic error runs fine but gives the wrong output
    When each error shows up: syntax at translation, run-time during the run, logic in the output
    Vocabulary Train
    English Chinese Pinyin
    syntax error 语法错误 yǔ fǎ cuò wù
    run-time error 运行时错误 yùn xíng shí cuò wù
    logic error 逻辑错误 luó jí cuò wù
    12.3

    Testing methods

    • dry run 手工跟踪 — trace the code on paper, writing each variable's value in a table.
    • walkthrough 走查 — a team review of the code.
    • white-box testing 白盒测试 — designed from the code's internal structure, covering every statement, branch and loop.
    • black-box testing 黑盒测试 — designed from the specification only: feed inputs, check outputs.
    • integration testing 集成测试 — combine modules and test the interfaces between them.
    • alpha testing α测试 — by the developers/in-house before release; beta testing β测试 — by a limited group of real users in their own environment.
    • acceptance testing 验收测试 — by the customer, to decide if the product is fit for purpose.
    • stub — a placeholder for a module that does not exist yet, so the structure can be tested top-down.
    Black-box testing works from the specification; white-box tests the code's internal paths
    Black-box tests the specification; white-box tests the code paths
    Vocabulary Train
    English Chinese Pinyin
    dry run 手工跟踪 shǒu gōng gēn zōng
    walkthrough 走查 zǒu chá
    white-box testing 白盒测试 bái hé cè shì
    black-box testing 黑盒测试 hēi hé cè shì
    integration testing 集成测试 jí chéng cè shì
    alpha testing α测试 α cè shì
    beta testing β测试 β cè shì
    acceptance testing 验收测试 yàn shōu cè shì
    stub zhuāng
    12.3

    Test strategy and test plan

    A test strategy 测试策略 is the high-level approach — which kinds of testing, who does them, when, and the criteria to move on. A test plan 测试计划 is the detailed list of tests — each with input data, expected output, and a column for the actual output.

    Choosing test data

    For each field or condition, include three kinds:

    • normal data 正常数据 — typical values inside the valid range (for marks 0–100: 50, 75).
    • abnormal data 异常数据 — values that should be rejected (-10, 200, "abc").
    • extreme data 极端数据 — the largest and smallest values still accepted (0 and 100).
    • boundary data 边界数据 — values at the edges, where off-by-one errors hide (each accepted extreme and the rejected value just outside it: 0/-1, 100/101).
    A number line for a mark field 0 to 100: normal values 50 and 75 inside, the extremes 0 and 100 at the accepted boundaries, and abnormal values -1, 101, -10 and 200 rejected outside
    Test data for a 0–100 field: normal inside, extremes at the boundaries, abnormal outside

    Worked example. A field accepts an exam mark from 0 to 100. Give test data of each kind with its expected result. Normal: 50 - accepted, a typical value inside the range. Abnormal: -10, 200, "abc" - all rejected, being out of range or the wrong data type. Extreme: 0 and 100 - the largest and smallest values that are still accepted. Boundary: the pairs straddling each edge - -1 rejected alongside 0 accepted, and 100 accepted alongside 101 rejected. Every value must carry its expected result, or the test plan proves nothing. Extreme and boundary are the pair most often confused: an extreme value sits inside and is accepted, while a boundary test is always a pair either side of the edge - which is exactly where off-by-one errors hide.

    Vocabulary Train
    English Chinese Pinyin
    test strategy 测试策略 cè shì cè lüè
    test plan 测试计划 cè shì jì huà
    normal data 正常数据 zhèng cháng shù jù
    abnormal data 异常数据 yì cháng shù jù
    boundary data 边界数据 biān jiè shù jù
    extreme data 极端数据 jí duān shù jù
    12.3

    Maintenance

    Most of a program's lifetime cost is in maintenance. Three kinds:

    The three kinds of maintenance: perfective, adaptive and corrective
    Three kinds of maintenance: perfective, adaptive and corrective
    • perfective maintenance 完善性维护 — improving performance or features even though it works (a faster query, a new option).
    • adaptive maintenance 适应性维护 — keeping it working in a changing environment (a new OS, a new API, a legal change).
    • corrective maintenance 纠正性维护 — fixing bugs found in use.

    A program may need all three throughout its life.

    Vocabulary Train
    English Chinese Pinyin
    perfective maintenance 完善性维护 wán shàn xìng wéi hù
    adaptive maintenance 适应性维护 shì yìng xìng wéi hù
    corrective maintenance 纠正性维护 jiū zhèng xìng wéi hù
    12.3

    Amending an existing program

    When asked to add a feature or fix a bug:

    1. read the existing code until you understand the algorithm and data flow.
    2. find where the change goes — which subroutine, which lines.
    3. make the change as small as possible — don't rewrite working code.
    4. update related parts — every caller of a changed parameter list, every routine using a changed data structure.
    5. test the new behaviour and the old (regression testing 回归测试 — check you broke nothing).
    6. document the change.

    Clear comments, meaningful names, decomposed subroutines and a structure chart make a program much easier to amend — which is why the design tools matter even after the first release.

    Vocabulary Train
    English Chinese Pinyin
    regression testing 回归测试 huí guī cè shì
    12.3

    Exam tips

    • Compare development models (waterfall, iterative, RAD) and know the stages of the program development life cycle.
    • Distinguish syntax, logic and run-time errors and how each is found.
    • Choose test data of three kinds — normal, boundary and erroneous — and give an example of each for the stated range.
    • Distinguish the types of maintenance (corrective, adaptive, perfective).
  • 13 Data Representation
    13.1

    User-defined data types

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of why user-defined types are necessary
    Define and use non-composite types Including enumerated, pointer
    Define and use composite data types Including set, record and class/object
    Choose and design an appropriate user-defined data type for a given problem

    Source: Cambridge International syllabus

    The built-in types (INTEGER, REAL, STRING, CHAR, BOOLEAN) cover the simplest cases. For richer problems you can define user-defined types 用户定义类型, making the code clearer and the compiler stricter.

    Why they are needed

    A built-in STRING lets you store nonsense in a field that should hold one of a few legal values; a user-defined type can restrict it. Real entities are usually a collection of values of different types. And DECLARE Taxi : Vehicle is clearer (self-documenting) than DECLARE Taxi : STRING.

    Non-composite types

    Enumerated type

    An enumerated type 枚举类型 has values that are a fixed list of named constants:

    TYPE Vehicle = (M100, M230, T101, T102, T120, T150)
    DECLARE MyTaxi : Vehicle
    MyTaxi ← T102
    

    The names are values of the new type (stored internally as small integers); you cannot assign anything outside the list. Uses: days of the week, colours, status codes.

    An enumerated type Vehicle with the fixed named values M100, M230, T101, T102, T120 and T150; a variable of this type may only hold one of them
    An enumerated type is a fixed list of named values

    Pointer type

    A pointer 指针 holds the memory address of another variable (or NULL for "no target"). Pointers build dynamic structures (linked lists, trees) and pass references without copying.

    TYPE PNode = ^TNode    // pointer to a TNode
    DECLARE p : PNode
    p ← NEW TNode
    p^.Value ← 42          // dereference to reach the fields
    

    To dereference 解引用 (p^) means to reach the variable it points to.

    A pointer p holds an address and points to a TNode holding Value = 42 and a Next field; p^ dereferences to reach the node's fields, such as p^.Value
    A pointer holds an address; p^ dereferences it to reach the node's fields

    Composite types

    A composite type 复合类型 (one of the composite data types) groups several values under one name.

    A set: an unordered collection where every value is unique
    A set is an unordered collection of unique values
    A record Student with fields Name, Age, Grade and Enrolled, each of a different type
    A record groups fields of different types under one name
    • record 记录 (Topic 10) — fields of different types in a TYPE ... ENDTYPE block.
    • set 集合 — an unordered collection of unique values, with operations add, remove, membership test, union, intersection:
    DECLARE Available : SET OF Colour
    Available ← {Red, Blue}
    IF Green IN Available THEN ...
    
    • class / object 对象 — the OOP composite type, combining data fields (attributes 属性) with operations on them (methods 方法). An object is an instance of a class:
    CLASS Taxi
        PRIVATE Capacity : INTEGER
        PUBLIC FUNCTION GetCapacity() RETURNS INTEGER
            RETURN Capacity
        ENDFUNCTION
    ENDCLASS
    

    Choosing a type

    Use enumerated for a value from a fixed list, pointer for indirection, record for a group of fields, set for an unordered unique collection, and class when you need state and behaviour together.

    Explore

    Programming concept lab

    Connect examples to the programming idea they show.

    Vocabulary Train
    English Chinese Pinyin
    user-defined type 用户定义类型 yòng hù dìng yì lèi xíng
    enumerated type 枚举类型 méi jǔ lèi xíng
    pointer 指针 zhǐ zhēn
    dereference 解引用 jiě yǐn yòng
    composite type 复合类型 fù hé lèi xíng
    record 记录 jì lù
    set 集合 jí hé
    class lèi
    object 对象 duì xiàng
    attributes 属性 shǔ xìng
    methods 方法 fāng fǎ
    13.2

    File organisation and access

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of the methods of file organisation and select an appropriate method of file organisation and file access for a given problem Including serial, sequential (using a key field), random (using a record key)
    Show understanding of methods of file access Including Sequential access for serial and sequential files Direct access for sequential and random files
    Show understanding of hashing algorithms Describe and use different hashing algorithms to read from and write data to a random/sequential file

    Source: Cambridge International syllabus

    File organisation 文件组织 is how the data is laid out; file access is how the program reaches a record.

    • serial file 串行文件 — records in the order added, no sorting. Access is sequential only; appending is fast; searching is slow. Used for logs and audit trails.
    • sequential file 顺序文件 — records sorted by a key. Searching is faster (you can stop early or binary-search); inserting is slow (records must shift). Used for master files updated in batch.
    • random (direct-access) file 随机文件 — records at positions computed from the key (often by a hash). Direct access by key is very fast; reading in key order is harder. Used for large lookup tables and customer accounts.
    A row of record boxes from first to sixth in the order they were added, with an append arrow and a Start of file marker
    Serial file: records are kept in the order they were added
    A row of customer record boxes with ascending key values, showing the records sorted into key order
    Sequential file: records are sorted by a key field
    A record key passing through a hash function to compute a slot number, with the record placed in that slot of the file
    Random file: records sit at positions computed from the key

    The two access methods are sequential access 顺序存取 (read from start to end) and direct access 直接存取 (jump straight to a known position). Match the structure to the dominant operation: single-key lookups favour random; in-order reports favour sequential.

    Explore

    File access route

    Follow a file from storage to program and back safely.

    Vocabulary Train
    English Chinese Pinyin
    file organisation 文件组织 wén jiàn zǔ zhī
    serial file 串行文件 chuàn xíng wén jiàn
    sequential file 顺序文件 shùn xù wén jiàn
    random (direct-access) file 随机文件 suí jī wén jiàn
    sequential access 顺序存取 shùn xù cún qǔ
    direct access 直接存取 zhí jiē cún qǔ
    13.2

    Hashing

    A hash function 散列函数 (a hashing algorithm) takes a record key and produces an address where the record is stored. A good one is fast, deterministic 确定性, and spreads keys evenly.

    Common hashing algorithms for $N$ slots: modulo hash address ← key MOD N; folding (split the key, add the pieces, MOD N); a string hash (sum the character codes, MOD N).

    A collision 冲突 is when two keys hash to the same address. Three ways to resolve it:

    Strategy How it works Trade-off
    linear probing 线性探测 use the next free slot (wrapping around) simple, but keys cluster
    chaining 链接法 each slot points to a linked list 链表 of records no clustering, but uses more memory
    rehashing apply a second hash function spreads keys, but more work
    Resolving a collision where keys A and B both hash to slot 2. Linear probing puts B in the next free slot (3); chaining keeps slot 2 pointing to a linked list of A then B
    Resolving a hash collision: linear probing uses the next free slot; chaining keeps a linked list per slot

    To search: hash the key, read that slot; if the keys match you are done, else follow the resolution strategy until a match or an empty slot. To insert: hash the key, write to that slot or the next free one. Keep the load factor 装填因子 (records ÷ slots) below about 70% for near-O(1) lookups.

    Explore

    A hash table

    Watch each key get hashed to a bucket. A good hash spreads keys out so lookups stay fast.

    Vocabulary Train
    English Chinese Pinyin
    deterministic 确定性 què dìng xìng
    hash function 散列函数 sàn liè hán shù
    collision 冲突 chōng tū
    linear probing 线性探测 xiàn xìng tàn cè
    chaining 链接法 liàn jiē fǎ
    linked list 链表 liàn biǎo
    load factor 装填因子 zhuāng tián yīn zi
    13.3

    Floating-point numbers

    Syllabus
    Candidates should be able to: Notes and guidance
    Describe the format of binary floating-point real numbers Use two's complement form Understand of the effects of changing the allocation of bits to mantissa and exponent in a floating-point representation
    Convert binary floating-point real numbers into denary and vice versa
    Normalise floating-point numbers Understand the reasons for normalisation
    Show understanding of the consequences of a binary representation only being an approximation to the real number it represents (in certain cases) Understand how underflow and overflow can occur
    Show understanding that binary representations can give rise to rounding errors

    Source: Cambridge International syllabus

    To store real numbers of very different sizes, computers use a floating-point 浮点 format — a binary form of scientific notation, with two fields:

    • a mantissa 尾数 — the significant digits.
    • an exponent 指数 — the power of 2 to multiply by.

    Both are stored as two's complement 补码 integers. The value is

    $$\text{number} = \text{mantissa} \times 2^{\text{exponent}}.$$

    Read the mantissa as a binary fraction — the first bit after the point is worth $1/2$, the next $1/4$, then $1/8$, and so on. So 0.1010000 is $1/2 + 1/8 = 0.625$; with exponent 00000010 (= 2) the value is $0.625 \times 2^{2} = 2.5$.

    Two bytes of place values: an 8-bit mantissa with a sign bit and fractions from one half to one over 128, and an 8-bit two's-complement exponent from minus 128 to 1
    The place values of an 8-bit mantissa and an 8-bit exponent

    Converting

    • binary → denary: read the mantissa (use two's-complement rules if negative) as a fraction, read the exponent as a signed integer, then multiply mantissa by $2^{\text{exponent}}$.
    • denary → binary: write the number as a binary fraction × a power of 2, then store the mantissa and exponent in the agreed formats.

    Worked example. A number has mantissa 10110000 and exponent 00000011. Find its denary value.

    The exponent 00000011 is $+3$. The mantissa begins with a 1, so it is negative. Read as 1.0110000 in two's complement, the sign bit is worth $-1$ and the fraction bits add $\tfrac{1}{4} + \tfrac{1}{8} = 0.375$, so the mantissa is $-1 + 0.375 = -0.625$. Then

    $$\text{number} = -0.625 \times 2^{3} = -5.0.$$

    Worked example. Store $+2.5$ in this format.

    In binary $2.5 = 10.1$. Written as a normalised fraction, $2.5 = 0.101 \times 2^{2}$. So the mantissa is 01010000 (sign bit 0, then .101) and the exponent is 00000010 ($= 2$).

    Normalisation

    A number is normalised 规格化 when the first significant bit is immediately after the binary point (no wasted leading zeros). This maximises precision, because every mantissa bit carries information. To normalise, shift the mantissa left and decrease the exponent (or shift right and increase it) until the first significant bit is in place; the value is unchanged. For negative (two's-complement) mantissas, the sign bit (1) is followed immediately by a 0.

    Normalising 0.0011010 with exponent 4: shift the mantissa left two places and decrease the exponent by 2, giving 0.1101000 with exponent 2 — the same value, with no wasted leading zeros
    Normalising: shift the mantissa left to remove leading zeros, lowering the exponent by the same amount

    Approximation and rounding errors

    Many denary reals cannot be stored exactly in binary — e.g. $0.1_{10}$ is the repeating binary fraction $0.000110011\ldots_{2}$, which must be truncated. Consequences:

    • rounding errors 舍入误差 build up over many operations (0.1 + 0.2 is not exactly 0.3).
    • comparisons fail — test ABS(x - 0.3) < 1e-9 instead of x = 0.3.
    • subtracting two nearly-equal values loses precision.
    • overflow 溢出 (a result too large for the exponent's range) and underflow 下溢 (a result too small, rounding to zero) occur when the exponent runs out of range.

    For exact needs (currency), use fixed-point 定点 or BCD 二进码十进数 instead of floating-point.

    Explore

    Build a floating-point number

    Flip the mantissa and exponent bits to make a value, and check whether it is normalised.

    Explore

    Normalising a floating-point number

    Step through normalisation. Shifting the mantissa to remove wasted leading zeros — and adjusting the exponent to match — keeps the value the same but spends every bit on precision.

    Vocabulary Train
    English Chinese Pinyin
    floating-point 浮点 fú diǎn
    mantissa 尾数 wěi shù
    exponent 指数 zhǐ shù
    two's complement 补码 bǔ mǎ
    normalised 规格化 guī gé huà
    rounding errors 舍入误差 shě rù wù chā
    fixed-point 定点 dìng diǎn
    BCD 二进码十进数 èr jìn mǎ shí jìn shù
    overflow 溢出 yì chū
    underflow 下溢 xià yì
    13.3

    Exam tips

    • For floating-point binary → denary, read the mantissa as a fraction and the exponent as a signed integer, then multiply; a negative mantissa follows two's-complement rules.
    • Normalise by shifting until the first digit after the point differs from the sign bit — this maximises precision.
    • Explain rounding, overflow and underflow errors and why $0.1$ cannot be stored exactly.
    • Compare file organisation (serial, sequential, direct) and how hashing finds a record quickly.
  • 14 Communication and internet technologies
    14.1

    Why protocols are needed

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of why a protocol is essential for communication between computers
    Show understanding of how protocol implementation can be viewed as a stack, where each layer has its own functionality
    Show understanding of the TCP/IP protocol suite Four Layers (Application, Transport, Internet, Link) Purpose and function of each layer Application when a message is sent from one host to another on the internet
    Show understanding of protocols (HTTP, FTP, POP3, IMAP, SMTP, BitTorrent) and their purposes BitTorrent protocol provides peer-to-peer file sharing

    Source: Cambridge International syllabus

    A protocol 协议 is a set of rules for how devices communicate. Both ends must follow the same rules, or one side's signals are meaningless to the other. Protocols define the format of the data (where addresses and payload sit), the order of messages (who speaks first, when to acknowledge), the meaning of each message, the timing (timeouts, retransmits), and what to do on error. Without an agreed protocol, communication fails — like two people speaking different languages with no translator.

    Two devices following the same rules: format, order, timing and what to do on error
    A protocol is the shared rules: format, order, timing and errors
    Vocabulary Train
    English Chinese Pinyin
    protocol 协议 xié yì
    14.1

    Layered protocols

    Networking is complex, so it is split into layers, each with one focused job, talking only to the layer above and below. Benefits: modularity 模块化 (replace one layer — say Ethernet with Wi-Fi — without touching the others), standardisation (vendors interoperate), and abstraction 抽象 (you ignore details handled elsewhere). The internet uses the TCP/IP protocol suite 协议栈 (4 layers).

    Vocabulary Train
    English Chinese Pinyin
    layers céng
    modularity 模块化 mó kuài huà
    abstraction 抽象 chōu xiàng
    protocol suite 协议栈 xié yì zhàn
    14.1

    TCP/IP protocol suite

    Layer Purpose Examples
    Application what the user program does HTTP, FTP, SMTP, IMAP
    Transport end-to-end delivery between processes TCP, UDP
    Internet routing packets between networks IP
    Link sending bits over the physical medium Ethernet, Wi-Fi
    A four-row stack: Application, Transport, Internet, Link, with sending going down the left and receiving going up the right, and example protocols on each layer
    The four layers of the TCP/IP protocol suite

    Application layer

    The application layer 应用层 gives services to user programs and defines the protocols they speak (HTTP for web, SMTP for email). This is where a programmer most often works.

    Transport layer

    The transport layer 传输层 delivers data end-to-end between processes, identified by port numbers 端口号. Two protocols:

    TCP sets up a connection and delivers all data in order; UDP sends and forgets
    TCP connects and delivers in order; UDP sends and forgets
    • TCP 传输控制协议connection-oriented 面向连接: sets up a connection, ensures all data arrives in order, retransmits lost packets 数据包, controls flow. Reliable but with overhead. Used by HTTP, HTTPS, SMTP, FTP.
    • UDP 用户数据报协议connectionless 无连接: sends and forgets, with no acknowledgements or ordering. Low overhead, no guarantees. Used for streaming, DNS and gaming, where speed beats reliability.

    Internet layer

    The internet layer 网络层 carries packets between hosts using IP. Each packet has a source and destination IP address IP地址, and routers 路由器 forward it onward. It does not guarantee delivery — that is TCP's job.

    A home router does this job for your house: it reads each packet's destination address and sends it on towards the internet, and back to the right device.

    A black home Wi-Fi router with four upright antennas and a row of status lights along the front
    A home Wi-Fi router: it forwards packets between your devices and the internet

    Before the router reaches the wider internet, a modem 调制解调器 connects the home to the internet provider over the provider's cable or phone line. Its lights show the link is up and online.

    A tall black cable modem standing upright on a plain background, with a column of status lights down its front
    A cable modem connects a home network to the internet provider

    Link layer

    The link layer 链路层 sends bits over one physical link (Ethernet, Wi-Fi). It adds a frame header with MAC addresses MAC地址 and handles medium access (e.g. CSMA/CD 载波侦听多路访问/冲突检测 on Ethernet).

    An Ethernet frame split into preamble, start of frame, Ethernet data and interpacket gap, with the data part expanded into destination and source MAC addresses, type/length, payload message and frame check sequence, each with its size in bytes
    The parts of a typical Ethernet frame

    On a wired local network, a switch 交换机 joins many devices together. Each device plugs into a port with an Ethernet cable (an RJ45 plug), and the switch uses the MAC addresses in each frame to send it only to the correct port.

    A small black 8-port Gigabit Ethernet switch on a plain background, its numbered RJ45 ports in a row along the front, each with a status light
    A network switch connects many wired devices on a local network

    The physical link can be a copper wire, a radio signal (Wi-Fi), or a fibre-optic cable 光纤. In a fibre-optic cable, the bits travel as flashes of light through very thin strands of glass, which is fast and carries data a long way.

    A bundle of fibre-optic strands fanning out against a dark background, each thin glass strand glowing with a point of blue-white light at its tip
    A fibre-optic cable: data travels as light through thin glass strands

    A radio link can reach much further. A satellite dish 卫星天线 sends and receives radio signals to and from a satellite, carrying data to places that wired links cannot easily reach.

    A round grey home satellite dish mounted on a house wall beside a window, with its feed arm reaching out to the front
    A satellite dish sends and receives data by radio over a long distance
    Explore

    Tap the four layers of the TCP/IP model

    Explore each layer. Data travels DOWN the stack as it's sent (each layer adds its header) and back UP as it's received — and any layer can be swapped without touching the others.

    Vocabulary Train
    English Chinese Pinyin
    application layer 应用层 yìng yòng céng
    transport layer 传输层 chuán shū céng
    port numbers 端口号 duān kǒu hào
    TCP 传输控制协议 chuán shū kòng zhì xié yì
    connection-oriented 面向连接 miàn xiàng lián jiē
    packets 数据包 shù jù bāo
    UDP 用户数据报协议 yòng hù shù jù bào xié yì
    connectionless 无连接 wú lián jiē
    internet layer 网络层 wǎng luò céng
    IP address IP地址 IP dì zhǐ
    routers 路由器 lù yóu qì
    modem 调制解调器 tiáo zhì jiě tiáo qì
    link layer 链路层 liàn lù céng
    MAC addresses MAC地址 MAC dì zhǐ
    CSMA/CD 载波侦听多路访问/冲突检测 zài bō zhēn tīng duō lù fǎng wèn chōng tū jiǎn cè
    switch 交换机 jiāo huàn jī
    fibre-optic 光纤 guāng xiān
    satellite dish 卫星天线 wèi xīng tiān xiàn
    14.1

    Common application-layer protocols

    • HTTP 超文本传输协议 — browsers fetch web pages from servers (over TCP, port 80). HTTPS is HTTP over TLS — encrypted, port 443.
    • FTP 文件传输协议 — transfer files between client and server.
    • SMTP 简单邮件传输协议send email between client and server, and between servers. Receiving uses POP3 or IMAP.
    • POP3 — downloads email and usually deletes it from the server. IMAP — leaves email on the server and syncs across devices, so the same inbox appears everywhere.
    • BitTorrent — a peer-to-peer 对等网络 protocol; a file is split into pieces downloaded from many peers in parallel, so no single server carries all the load.
    A tracker in the centre with peers around it — seeds, leeches and new peers — exchanging file pieces, with a key
    BitTorrent: a tracker helps peers find each other, then they share file pieces directly
    Explore

    Network route lab

    Follow data from a device through network hardware and protocols.

    Vocabulary Train
    English Chinese Pinyin
    HTTP 超文本传输协议 chāo wén běn chuán shū xié yì
    FTP 文件传输协议 wén jiàn chuán shū xié yì
    SMTP 简单邮件传输协议 jiǎn dān yóu jiàn chuán shū xié yì
    peer-to-peer 对等网络 duì děng wǎng luò
    14.2

    Circuit switching vs packet switching

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of circuit switching Benefits, drawbacks and where it is applicable
    Show understanding of packet switching Benefits, drawbacks and where it is applicable Show understanding of the function of a router in packet switching Explain how packet switching is used to pass messages across a network, including the internet

    Source: Cambridge International syllabus

    Circuit switching

    A dedicated path is set up between the two ends before any data is sent (circuit switching 电路交换), reserved for the whole conversation, then released. It gives reserved bandwidth 带宽 and in-order delivery, but is inefficient during silences and slow to set up. Classic example: the traditional telephone network.

    A mesh of routers between device A and device B, with one path highlighted and reserved end-to-end for the whole call
    Circuit switching: one dedicated path is reserved end to end

    Packet switching

    The data is split into packets, each sent independently (packet switching 分组交换). Each packet carries the destination address; routers make per-packet decisions, so packets may take different routes and arrive out of order, and the destination reassembles them. It is efficient (one link is multiplexed 多路复用 across many conversations), robust (reroute around a failure), but has variable latency 延迟 and possible loss (TCP handles reliability). Used by the internet.

    The same router mesh with packets shown as numbered coloured squares taking different routes from computer A to computer B, then reassembled in order at B
    Packet switching: packets travel independently and may take different routes
    Aspect Circuit switching Packet switching
    Path dedicated, reserved shared, per-packet
    Setup time slow none
    Bandwidth use inefficient efficient
    Order in order may be out of order
    Robustness one failure cuts the circuit reroute around failures
    Suits constant-rate flows (voice) bursty flows (web, email)

    Modern networks use packet switching for its efficiency and resilience.

    Describing packet switching in a few sentences

    A good exam answer: "The message is broken into small packets. Each packet carries the destination and source addresses and a sequence number. Each packet travels through the network independently, with routers choosing the next hop per packet. Packets may take different paths and arrive out of order. The destination uses the sequence numbers to reassemble the message, and missing packets can be requested again."

    Worked example. A phone call and a large file download share a network. Which switching method suits each, and why? A phone call needs a steady stream with low delay, and it would suffer badly if pieces arrived late or out of order - so circuit switching suits it: a dedicated path is set up for the whole call and its capacity is reserved for the duration. A file download does not care about timing or arrival order, because the receiver reassembles it, and it benefits from using whatever capacity happens to be spare - so packet switching suits it: the file is split into packets that travel independently, each carrying source and destination addresses and a sequence number, with routers choosing a next hop per packet. Name the property of the traffic that decides it: reserved capacity and low delay for the call, efficiency and resilience for the download.

    Explore

    A packet's journey across the internet

    Step through packet switching. The message is split up, each packet finds its own way, and the destination puts them back together — which is why the internet is so efficient and hard to break.

    Vocabulary Train
    English Chinese Pinyin
    circuit switching 电路交换 diàn lù jiāo huàn
    bandwidth 带宽 dài kuān
    packet switching 分组交换 fēn zǔ jiāo huàn
    multiplexed 多路复用 duō lù fù yòng
    latency 延迟 yán chí
    14.2

    Exam tips

    • Explain why protocols and layers are used: each layer has one job and can change independently.
    • Place common protocols in the TCP/IP stack (HTTP/FTP/SMTP application; TCP/UDP transport; IP internet).
    • Compare circuit switching vs packet switching (a dedicated path vs independent packets) with a use for each.
  • 15 Hardware and Virtual Machines
    15.1

    RISC vs CISC processors

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of Reduced Instruction Set Computers (RISC) and Complex Instruction Set Computers (CISC) processors Differences between RISC and CISC Understand interrupt handling on CISC and RISC processors
    Show understanding of the importance/use of pipelining and registers in RISC processors
    Show understanding of the four basic computer architectures SISD, SIMD, MISD, MIMD
    Show understanding of the characteristics of massively parallel computers
    Show understanding of the concept of a virtual machine Give examples of the role of virtual machines Understand the benefits and limitations of virtual machines

    Source: Cambridge International syllabus

    Two styles of CPU design. The CPU itself plugs into the motherboard 主板, the main board that links the processor, the memory and every other part of the computer together.

    CISC has many complex variable-length instructions; RISC has few simple fixed-length ones
    CISC has many complex instructions; RISC has few simple ones
    A computer motherboard on a white background, showing the square CPU socket in the middle, the long memory slots, several expansion slots and the rows of I/O ports along one edge
    A motherboard links the CPU, memory and other parts together

    CISC

    A CISC 复杂指令集 (Complex Instruction Set Computers) has many, often complex instructions (one may do several memory accesses and operations), of variable length, so decoding is intricate. It does more per instruction in hardware. Examples: Intel x86.

    RISC

    A RISC 精简指令集 (Reduced Instruction Set Computers) has a small set of simple instructions, each doing one basic operation, all of fixed length (fast to decode). Only load and store touch memory; everything else is register 寄存器-to-register. Programs are longer but each instruction is quick and predictable, which suits pipelining. Examples: ARM, RISC-V.

    Feature CISC RISC
    Instruction set many few
    Instruction length variable fixed
    Memory access many instructions only load/store
    Pipeline-friendly harder naturally
    Per-instruction cycles varies usually 1

    The trade-off is doing more per instruction (CISC) vs doing each instruction faster and more predictably (RISC). Modern Intel chips translate CISC instructions into simpler RISC-like micro-ops internally.

    Vocabulary Train
    English Chinese Pinyin
    motherboard 主板 zhǔ bǎn
    CISC 复杂指令集 fù zá zhǐ lìng jí
    RISC 精简指令集 jīng jiǎn zhǐ lìng jí
    register 寄存器 jì cún qì
    15.1

    Pipelining

    A pipeline 流水线 processes instructions in overlapping stages, like an assembly line: Fetch → Decode → Execute (in the ALU 算术逻辑单元) → Memory access → Write back. Each stage works on a different instruction at once, so once the pipeline is full, one instruction completes per cycle. RISC's fixed-length, simple instructions make every stage take the same time. A pipeline can stall on a hazard 冒险 — a data hazard (an instruction needs a result not ready yet) or a control hazard (a branch makes the next address unknown).

    A Gantt chart of the five pipeline stages IF, ID, EX, MEM, WB across ten clock cycles, with six instructions A to F each shifted one cycle later so they overlap diagonally
    Pipelining overlaps the stages of six instructions, so one finishes each cycle

    RISC chips keep data in many registers because memory is slow and registers are fast; the compiler allocates values to registers wisely.

    A processor running this fast gives off a lot of heat, so a heat-sink 散热器 and fan sit on top of it. The metal fins spread the heat and the fan blows it away, keeping the CPU cool enough to work.

    A tower CPU cooler with a black fan in front, a tall stack of thin metal cooling fins, and copper heat-pipes running up from the flat base that touches the processor
    A CPU heat-sink and fan carry heat away from the processor
    Explore

    How pipelining fills up

    Step through the clock cycles. Once the pipeline is full, a new instruction finishes every cycle — even though each one still takes several stages — because the stages of different instructions overlap.

    Vocabulary Train
    English Chinese Pinyin
    pipeline 流水线 liú shuǐ xiàn
    ALU 算术逻辑单元 suàn shù luó jí dān yuán
    hazard 冒险 mào xiǎn
    heat-sink 散热器 sàn rè qì
    15.1

    Flynn's taxonomy

    Flynn's taxonomy 弗林分类 sorts computers by the number of instruction and data streams:

    • SISD — one instruction, one data stream (a traditional single core).
    • SIMD 单指令多数据 — one instruction works on many data items at once (GPUs, CPU vector extensions). Great for images, video, scientific arrays.
    • MISD — several operations on the same data; rare, mostly theoretical.
    • MIMD 多指令多数据 — many processors run different instructions on different data (multi-core CPUs, clusters). The most general.
    A single control unit broadcasting one instruction stream to four processing units, each of which works on its own data item
    SIMD: many processors run the same instruction on different data

    A graphics card 显卡 (with its GPU) is a real example of SIMD hardware: it has thousands of small cores that run the same instruction on many pixels or numbers at once, which is why GPUs are so fast for images, video and machine learning.

    A graphics card on a white background, showing the large cooling fan over the GPU and the gold edge connector that plugs into the motherboard
    A graphics card: its GPU runs the same instruction on many data items at once (SIMD)
    Four independent processors, each fed by its own separate instruction stream from above and its own data item from below
    MIMD: each processor runs its own instructions on its own data
    Vocabulary Train
    English Chinese Pinyin
    Flynn's taxonomy 弗林分类 fú lín fēn lèi
    SIMD 单指令多数据 dān zhǐ lìng duō shù jù
    MIMD 多指令多数据 duō zhǐ lìng duō shù jù
    graphics card 显卡 xiǎn kǎ
    15.1

    Massively parallel computers

    A massively parallel 大规模并行 system uses thousands of processors on a fast network, each with its own memory (distributed memory 分布式内存), exchanging data by messages. It is MIMD, needs specially-written software (MPI, CUDA), and suits climate simulation, large machine learning 机器学习 training, and astrophysics. The largest supercomputers 超级计算机 are massively parallel.

    The processors live in tall server 服务器 racks, often filling a whole room (a data centre 数据中心), wired together so they can work on one big problem at the same time.

    A long row of black server racks on a raised white floor in a data centre, packed with equipment and cables
    Rows of servers in a data centre, like those used for massively parallel computing
    Vocabulary Train
    English Chinese Pinyin
    massively parallel 大规模并行 dà guī mó bìng xíng
    distributed memory 分布式内存 fēn bù shì nèi cún
    machine learning 机器学习 jī qì xué xí
    supercomputers 超级计算机 chāo jí jì suàn jī
    server 服务器 fú wù qì
    data centre 数据中心 shù jù zhōng xīn
    15.1

    Virtual machines

    A virtual machine 虚拟机 (VM) is a software emulation of a whole computer — the software inside sees a CPU, memory and disks that look real but are managed by host software.

    • a system VM runs a complete OS. A hypervisor 虚拟机监控器 creates and manages VMs, each booting its own guest OS. Uses: run different OSes on one machine; server consolidation; sandboxing 沙箱 (risky software runs isolated); snapshots.
    • a process (language) VM runs one program in portable bytecode 字节码 — the JVM (Java), the CLR (.NET), CPython. Benefits: portability ("write once, run anywhere"), runtime safety checks, and just-in-time compilation 即时编译 for near-native speed. The cost is an extra layer and needing the VM installed.
    Explore

    Computing concept lab

    Classify concrete examples by the computing idea they demonstrate.

    Vocabulary Train
    English Chinese Pinyin
    virtual machine 虚拟机 xū nǐ jī
    hypervisor 虚拟机监控器 xū nǐ jī jiān kòng qì
    sandboxing 沙箱 shā xiāng
    bytecode 字节码 zì jié mǎ
    just-in-time compilation 即时编译 jí shí biān yì
    15.2

    Boolean algebra

    Syllabus
    Candidates should be able to: Notes and guidance
    Produce truth tables for logic circuits including half adders and full adders May include logic gates with more than two inputs
    Show understanding of a flip-flop (SR, JK) Draw a logic circuit and derive a truth table for a flip-flop Understand of the role of flip-flops as data storage elements
    Show understanding of Boolean algebra Understand De Morgan’s laws Perform Boolean algebra using De Morgan’s laws Simplify a logic circuit/expression using Boolean algebra
    Show understanding of Karnaugh maps (K-map) Understand of the benefits of using Karnaugh maps Solve logic problems using Karnaugh maps

    Source: Cambridge International syllabus

    The half adder: XOR + AND add two bits

    Boolean algebra 布尔代数 simplifies Boolean 布尔 expressions, which can equally be described by truth tables 真值表. Symbols: + for OR, · for AND (often omitted), an overbar for NOT.

    Key laws include commutative, associative and distributive (as in ordinary algebra), plus:

    • identity $A + 0 = A$, $A \cdot 1 = A$; null $A + 1 = 1$, $A \cdot 0 = 0$.
    • idempotent $A + A = A$; inverse $A + \overline{A} = 1$, $A \cdot \overline{A} = 0$.
    • De Morgan's laws 德摩根定律: $(A + B)' = A' \cdot B'$; $(A \cdot B)' = A' + B'$ — negate the whole, swap AND/OR, negate each operand.
    • absorption 吸收律: $A + AB = A$.

    Simplifying reduces the number of terms, so the resulting logic circuit has fewer gates. Example: $Z = AB + A\overline{B} = A(B + \overline{B}) = A$.

    Explore

    Boolean algebra

    A·B, A+B, Ā …

    Boolean algebra is just these gates written as expressions — compare the truth tables.

    Explore

    Boolean truth tables

    Pick an operator and the inputs to build its truth table — the algebra behind logic circuits.

    Vocabulary Train
    English Chinese Pinyin
    Boolean algebra 布尔代数 bù ěr dài shù
    Boolean 布尔 bù ěr
    De Morgan's laws 德摩根定律 dé mó gēn dìng lǜ
    absorption 吸收律 xī shōu lǜ
    truth table 真值表 zhēn zhí biǎo
    15.2

    Karnaugh maps

    A Karnaugh map 卡诺图 (K-map) simplifies a Boolean expression by grouping adjacent 1s from a truth table. Columns and rows use Gray code 格雷码 order (00, 01, 11, 10) so adjacent cells differ in one variable.

    Place a 1 in each cell where the output is 1. Find rectangular groups of 1s whose sides are powers of 2 (1, 2, 4, 8), wrapping around edges if it makes a bigger group. The larger the group, the simpler the term: a group of 2 drops one variable, a group of 4 drops two, and so on — variables that change within the group disappear. OR the group terms together for the simplified expression. Cover every 1 using as few, as large, groups as possible.

    Worked example. A Karnaugh map for $A$ and $B$ has 1s in the cells $\overline{A}B$ and $AB$. Simplify. The two 1s are adjacent - they share the $B=1$ column - so group them as a rectangle of 2. Inside that group $B$ stays 1 throughout while $A$ changes from 0 to 1, and any variable that changes within a group disappears. So the group leaves simply $X = B$. Compare that with the sum of products read straight off the table, $\overline{A}B + AB$: the same circuit, two gates fewer. Two rules do most of the work - make each group as large as possible (a group of 2 drops one variable, 4 drops two, 8 drops three), and remember the map wraps around its edges, so the leftmost and rightmost columns are adjacent. That wrap is the grouping most candidates miss.

    Vocabulary Train
    English Chinese Pinyin
    Karnaugh map 卡诺图 kǎ nuò tú
    Gray code 格雷码 gé léi mǎ
    15.2

    Half adder and full adder

    A half adder 半加器 adds two single bits $A$ and $B$, giving a sum $S$ and a carry 进位 $C$:

    A B S C
    0 0 0 0
    0 1 1 0
    1 0 1 0
    1 1 0 1

    So $S = A \text{ XOR } B$ and $C = A \text{ AND } B$. It ignores any carry-in — hence "half".

    A half adder block with inputs A and B and outputs sum and carry, beside its circuit where A and B feed an XOR gate giving the sum and an AND gate giving the carry
    A half adder, as a block and as a circuit of an XOR and an AND gate

    A full adder 全加器 adds three bits ($A$, $B$, carry-in), giving a sum and a carry-out: $S = A \text{ XOR } B \text{ XOR } C_{\text{in}}$. It can be built from two half adders plus an OR gate. Chaining full adders (each carry-out feeding the next carry-in) makes a multi-bit "ripple-carry" adder.

    Two half adders chained with an OR gate to add A, B and a carry-in: the first half adder takes A and B, the second adds the carry-in, and the OR gate combines the two carries into the carry-out
    A full adder is built from two half adders and an OR gate
    Explore

    The gates inside an adder

    A half-adder's sum bit is an XOR gate and its carry is an AND gate — toggle A and B and watch the truth-table row light up.

    Vocabulary Train
    English Chinese Pinyin
    half adder 半加器 bàn jiā qì
    carry 进位 jìn wèi
    full adder 全加器 quán jiā qì
    15.2

    Flip-flops

    A flip-flop 触发器 is a bistable 双稳态 circuit — two stable states (0 and 1) — that remembers its state. It stores one bit and is the basic element of registers and SRAM.

    SR flip-flop

    An SR flip-flop SR触发器 has inputs S (set) and R (reset) and outputs Q and $\overline{Q}$. S=1,R=0 sets Q to 1; S=0,R=1 resets it to 0; S=0,R=0 holds; S=1,R=1 is invalid. Built from two cross-coupled NOR gates.

    JK flip-flop

    A JK flip-flop JK触发器 improves on it by using the previously-invalid 1,1 input as a toggle 翻转 (the output flips). This makes it ideal for building counters 计数器 (a chain of toggling flip-flops). It is usually clocked — inputs act only on a clock edge, keeping flip-flops synchronised.

    A JK flip-flop block symbol with J, K and clock inputs and outputs Q and Q-bar, beside its build from four cross-coupled NAND gates with the Q and Q-bar outputs fed back to the input gates
    A JK flip-flop: its symbol and a build from NAND gates

    Flip-flops are the building blocks of registers (n bits = n flip-flops), counters, and SRAM 静态RAM cells.

    Vocabulary Train
    English Chinese Pinyin
    flip-flop 触发器 chù fā qì
    bistable 双稳态 shuāng wěn tài
    SR flip-flop SR触发器 SR chù fā qì
    JK flip-flop JK触发器 JK chù fā qì
    toggle 翻转 fān zhuǎn
    counters 计数器 jì shù qì
    SRAM 静态RAM jìng tài RAM
    15.2

    Exam tips

    • Compare RISC vs CISC (simple, fast, uniform instructions vs complex ones) and why RISC suits pipelining.
    • Simplify logic with Boolean algebra / Karnaugh maps — group the 1s in powers of two.
    • Explain a half adder vs full adder (the full adder handles a carry-in) and what a flip-flop stores.
    • Place a machine in Flynn's taxonomy (SISD, SIMD, MISD, MIMD).
  • 16 System Software
    16.1

    How an OS maximises use of resources

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of how an OS can maximise the use of resources
    Describe the ways in which the user interface hides the complexities of the hardware from the user
    Show understanding of process management The concept of multi-tasking and a process The process states: running, ready and blocked The need for scheduling and the function and benefits of different scheduling routines (including round robin, shortest job first, first come first served, shortest remaining time) How the kernel of the OS acts as an interrupt handler and how interrupt handling is used to manage low-level scheduling
    Show understanding of virtual memory, paging and segmentation for memory management The concepts of paging, virtual memory and segmentation The difference between paging and segmentation How pages can be replaced How disk thrashing can occur

    Source: Cambridge International syllabus

    A computer has many resources (CPU time, memory, disk, I/O) and many programs competing for them. The OS shares them fairly and efficiently so each is well used and the system stays responsive:

    The OS shares CPU time, memory, disk and input/output between programs
    The OS shares the CPU, memory, disk and I/O between programs
    • multi-tasking 多任务 — switch the CPU quickly between processes so several seem to run at once.
    • memory management — give each process the memory it needs; use disk paging 分页 when RAM runs out.
    • spooling 假脱机 and buffering — print jobs queue on disk so the CPU never waits for the printer.
    • caching — keep recently-used disk data in cache 高速缓存 / RAM.
    A CPU (central processing unit) chip
    The processor is a key resource the OS shares between competing tasks
    Memory modules (RAM)
    The OS also manages memory (RAM), deciding what to keep in it and what to page out to disk
    Vocabulary Train
    English Chinese Pinyin
    multi-tasking 多任务 duō rèn wù
    paging 分页 fēn yè
    spooling 假脱机 jiǎ tuō jī
    cache 高速缓存 gāo sù huǎn cún
    16.1

    The user interface

    The user interface hides the hardware behind friendly abstractions: the user sees windows, menus and folders, not addresses or sectors. One click on an icon makes the OS find the program on disk, allocate memory, load it and start it. A CLI (command line) is powerful and scriptable for experts; a GUI (graphical) is easier to learn. Most systems offer both.

    16.1

    Process management

    A process 进程 is a program in execution — its code, current state, memory and open files.

    Scheduling

    The scheduler 调度器 chooses which ready process runs next, and for how long:

    • round robin 轮转 — each process gets a fixed time slice 时间片, then goes to the back of the queue.
    • first-come-first-served; shortest job first; shortest remaining time (run the job with the least work left); priority; multilevel feedback queues.

    The trade-off is responsiveness vs throughput vs fairness.

    A Gantt timeline showing P1 then P2, P3, P4 run one after another from time 0 to 39, with a key giving each process's CPU burst time
    First-come-first-served scheduling of four processes
    Round-robin scheduling shown as a timeline: P1, P2, P3 each get a fixed time slice in turn, then the cycle repeats, sharing the CPU between them
    Round-robin: each process gets a fixed time slice in turn, then the next runs (unlike first-come-first-served)

    Process states

    A process is new, ready (waiting for the CPU), running, blocked 阻塞 (waiting for I/O or a lock), or terminated. When its time slice ends it goes running → ready; when it requests I/O it goes running → blocked; when the I/O finishes it goes blocked → ready.

    A state diagram: new to ready (admit), ready to running (dispatch by the scheduler), running to ready (interrupt or time-out), running to blocked (request I/O), blocked back to ready (I/O complete), running to terminated (exit)
    A process moves between the new, ready, running, blocked and terminated states

    Process control block and context switch

    For each process the OS keeps a process control block 进程控制块 (PCB) — the saved program counter, registers, state and memory info.

    A context switch saves process A's state (its PCB) and loads process B's
    A context switch saves one process's state and loads another's
    • a context switch 上下文切换 suspends one process and starts another: it saves the state into one PCB and restores it from another. This small cost is paid on every switch.
    • the kernel 内核 (the core of the OS) acts as an interrupt handler 中断处理程序. When a device or the timer raises an interrupt, interrupt handling 中断处理 saves the running process and runs the right routine — this is what drives low-level scheduling.

    Inter-process communication

    Processes are isolated, so the OS provides inter-process communication 进程间通信: pipes 管道 (one program's output feeds another's input), shared memory 共享内存 (a region several processes can use), and message passing.

    Explore

    The life of a process

    Tap round the loop a process travels. It only runs when the scheduler picks it; needing I/O sends it to blocked, and finishing its time slice sends it back to ready — round and round until it's done.

    Vocabulary Train
    English Chinese Pinyin
    process 进程 jìn chéng
    scheduler 调度器 diào dù qì
    round robin 轮转 lún zhuàn
    time slice 时间片 shí jiān piàn
    blocked 阻塞 zǔ sè
    process control block 进程控制块 jìn chéng kòng zhì kuài
    context switch 上下文切换 shàng xià wén qiè huàn
    inter-process communication 进程间通信 jìn chéng jiān tōng xìn
    pipes 管道 guǎn dào
    shared memory 共享内存 gòng xiǎng nèi cún
    kernel 内核 nèi hé
    interrupt handler 中断处理程序 zhōng duàn chǔ lǐ chéng xù
    interrupt handling 中断处理 zhōng duàn chǔ lǐ
    16.1

    Virtual memory, paging, segmentation

    Each process gets its own virtual address space 虚拟地址空间 — a clean, contiguous range of addresses the OS maps to physical memory. This gives each process a simple space, protects processes from each other, and lets the total memory exceed physical RAM.

    In paging, the virtual space is split into fixed-size pages and physical memory into same-sized frames 页框. A page table maps each page to a frame. If an accessed page is not in RAM — a page fault 缺页 — the OS reads it from the swap file 交换文件 into a frame, evicting another page if RAM is full. Frequent faults cause thrashing 抖动 (disk thrashing), where the OS spends most of its time swapping pages instead of doing useful work.

    Logical-memory pages mapped through a page table to non-contiguous physical-memory frames
    Paging maps each page of logical memory to a frame of physical memory

    In segmentation 分段, memory is split into variable-sized logical segments (code, stack, heap), each with its own permissions. Many systems use paging within segments.

    Variable-sized logical segments (code, heap, stack) mapped through a segment table of sizes and start addresses to physical memory
    Segmentation maps variable-sized segments using a segment map table
    Explore

    What happens on a page fault

    Step through a page fault. When the program touches a page that isn't in RAM, the OS quietly fetches it from disk and updates the page table — so the program sees more memory than physically exists.

    Vocabulary Train
    English Chinese Pinyin
    virtual address space 虚拟地址空间 xū nǐ dì zhǐ kōng jiān
    pages
    frames 页框 yè kuāng
    page fault 缺页 quē yè
    swap file 交换文件 jiāo huàn wén jiàn
    thrashing 抖动 dǒu dòng
    segmentation 分段 fēn duàn
    16.2

    How an interpreter runs a program

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of how an interpreter can execute programs without producing a translated version
    Show understanding of the various stages in the compilation of a program Including lexical analysis, syntax analysis, code generation and optimisation
    Show understanding of how the grammar of a language can be expressed using syntax diagrams or Backus-Naur Form (BNF) notation
    Show understanding of how Reverse Polish Notation (RPN) can be used to carry out the evaluation of expressions

    Source: Cambridge International syllabus

    An interpreter 解释器 translates and runs the source at the same time. For each statement it reads the line, does lexical and syntax analysis, checks types, then executes the action, and moves on. Errors are reported immediately and it usually stops; no executable is produced. The translation is redone every run (slower), but it gives fast development feedback and is portable.

    Vocabulary Train
    English Chinese Pinyin
    interpreter 解释器 jiě shì qì
    16.2

    Stages of compilation

    A compiler 编译器 turns source into machine code 机器码 in phases:

    1. lexical analysis 词法分析 — the lexer groups characters into tokens 词法单元 (keywords, identifiers, operators, literals), discarding whitespace and comments.
    2. syntax analysis (parsing) 语法分析 — check the tokens fit the grammar and build an abstract syntax tree 抽象语法树. A missing bracket gives a syntax error 语法错误.
    3. semantic analysis 语义分析 — check the program makes sense (variables declared, types match).
    4. code generation 代码生成 — walk the tree and emit target code, choosing registers and layouts.
    5. code optimisation 代码优化 — remove redundant work, fold constants, reorder for the pipeline.

    The output is an executable.

    The phases of compilation: source code passes through lexical analysis (tokens), syntax analysis (AST), semantic analysis (checks), code generation and optimisation to produce an executable
    The phases of compilation, from source code to an optimised executable
    Explore

    The phases of compilation

    Step through what a compiler does to your source. Each phase hands its output to the next — characters become tokens, tokens become a tree, the tree becomes optimised machine code.

    Vocabulary Train
    English Chinese Pinyin
    compiler 编译器 biān yì qì
    machine code 机器码 jī qì mǎ
    lexical analysis 词法分析 cí fǎ fēn xī
    tokens 词法单元 cí fǎ dān yuán
    syntax analysis (parsing) 语法分析 yǔ fǎ fēn xī
    abstract syntax tree 抽象语法树 chōu xiàng yǔ fǎ shù
    syntax error 语法错误 yǔ fǎ cuò wù
    semantic analysis 语义分析 yǔ yì fēn xī
    code generation 代码生成 dài mǎ shēng chéng
    code optimisation 代码优化 dài mǎ yōu huà
    16.2

    Grammar: BNF and syntax diagrams

    A grammar 文法 says which token sequences are valid programs.

    Backus-Naur Form 巴科斯-诺尔范式 (BNF) is textual. A production rule 产生式 has the form:

    <symbol> ::= alternative1 | alternative2 | ...
    

    Each alternative is a sequence of terminal 终结符 symbols (literal text) and non-terminal 非终结符 symbols (other rule names):

    <digit>      ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
    <identifier> ::= <letter> | <identifier> <letter> | <identifier> <digit>
    

    The recursive third rule expresses "a letter followed by any number of letters or digits". An IF statement:

    <if-statement> ::= IF <condition> THEN <statement> ENDIF
                     | IF <condition> THEN <statement> ELSE <statement> ENDIF
    

    A syntax diagram 语法图 (railroad diagram) shows the same thing graphically: boxes for non-terminals, rounded boxes for terminals, arrows for valid paths, loops for repetition. The two notations are equivalent. The parser uses the grammar to decide whether a program is valid.

    A railroad diagram for an assignment: a rectangular identifier box, a rounded assignment-symbol box, then a rectangular expression box, connected left to right
    A syntax (railroad) diagram for an assignment statement
    Vocabulary Train
    English Chinese Pinyin
    grammar 文法 wén fǎ
    Backus-Naur Form 巴科斯-诺尔范式 bā kē sī - nuò ěr fàn shì
    production rule 产生式 chǎn shēng shì
    terminal 终结符 zhōng jié fú
    non-terminal 非终结符 fēi zhōng jié fú
    syntax diagram 语法图 yǔ fǎ tú
    16.2

    Reverse Polish Notation (RPN)

    In infix 中缀 notation the operator sits between its operands (3 + 4 * 2), needing brackets and precedence rules. In Reverse Polish Notation 逆波兰表示法 (RPN, postfix 后缀) the operator follows its operands (3 4 2 * +), needing no brackets.

    Converting infix to RPN

    Use an operator stack. Scan left to right: output an operand; for an operator, first pop any stacked operators of higher or equal precedence 优先级 to the output, then push it; push (; on ) pop to output until the matching (. At the end, pop all operators. Example: (3 + 4) * 23 4 + 2 *.

    Evaluating RPN

    Use a stack of operands. Scan left to right: push each operand; on an operator, pop the top two, apply it, and push the result. Evaluating 3 4 2 * +:

    Token Stack
    3 3
    4 3, 4
    2 3, 4, 2
    * 3, 8
    + 11

    Result: 11. RPN needs no brackets at evaluation time and suits a stack machine — which is how the JVM and many bytecode 字节码 interpreters work.

    Worked example. Convert $(A + B) \times (C - D)$ to RPN, then evaluate $(3 + 4) \times (5 - 2)$. Scan left to right using an operator stack. Push (; output A; push +; output B; on ) pop back to the matching (, giving A B + so far. Push ×, and the second bracket behaves the same way, giving C D -. At the end pop the ×. Result: A B + C D - ×. To evaluate the numbers, use a stack of operands: push 3, push 4; + pops both and pushes 7; push 5, push 2; - pops both and pushes 3; × pops 7 and 3 and pushes 21. Two things make these reliable: the operands keep their original order through the conversion (only the operators move), and every operator acts on the two values immediately below it on the stack.

    Explore

    Operator precedence — what RPN removes

    In ordinary infix maths × and ÷ bind tighter than + and −, so you must apply rules in the right order. Reverse Polish Notation writes the operands first (3 4 2 × + 1 −), fixing the order so no precedence rules are needed.

    Vocabulary Train
    English Chinese Pinyin
    infix 中缀 zhōng zhuì
    Reverse Polish Notation 逆波兰表示法 nì bō lán biǎo shì fǎ
    postfix 后缀 hòu zhuì
    stack zhàn
    precedence 优先级 yōu xiān jí
    bytecode 字节码 zì jié mǎ
    16.2

    Exam tips

    • List the stages of compilation (lexical, syntax and semantic analysis, code generation, optimisation) and what each does.
    • Explain virtual memory and paging (disk used as extra RAM) and its cost (disk thrashing).
    • Evaluate Reverse Polish Notation with a stack — no brackets are needed.
    • Use BNF or a syntax diagram to test whether a string is valid.
  • 17 Security
    17.1

    How encryption works

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of how encryption works Including the use of public key, private key, plain text, cipher text, encryption, symmetric key cryptography and asymmetric key cryptography How the keys can be used to send a private message from the public to an individual/organisation How the keys can be used to send a verified message to the public How data is encrypted and decrypted, using symmetric and asymmetric cryptography Purpose, benefits and drawbacks of quantum cryptography
    Show awareness of the Secure Socket Layer (SSL) / Transport Layer Security (TLS) Purpose of SSL/TLS Use of SSL/TLS in client-server communication Situations where the use of SSL/TLS would be appropriate
    Show understanding of digital certification How a digital certificate is acquired How a digital certificate is used to produce digital signatures

    Source: Cambridge International syllabus

    Encryption 加密 turns readable plaintext 明文 (plain text) into unreadable ciphertext 密文 (cipher text) using a maths operation that depends on a key. Only someone with the right key can reverse it — decryption 解密 — to get the plaintext back. An attacker who intercepts the ciphertext without the key sees only meaningless data, because trying every possible key would take far too long. A newer approach, quantum cryptography 量子密码学, uses quantum physics to share a key in a way that reveals any eavesdropper.

    The Enigma cipher machine with its keyboard and rotors
    The Enigma machine encrypted messages in the Second World War — an early, mechanical cipher device
    Plaintext goes through an encryption algorithm with an encryption key to ciphertext, across the internet, then a decryption algorithm with a decryption key back to plaintext
    Encryption scrambles plaintext with a key; decryption reverses it

    Symmetric encryption

    Symmetric encryption 对称加密 (symmetric key cryptography) uses the same key for both encryption and decryption, so sender and receiver must both hold the secret key. It is fast and good for bulk data (a whole disk, a video stream). Its problem is key distribution 密钥分发: how do you share the key safely in the first place? Asymmetric encryption solves this.

    Symmetric encryption uses the same key at both ends, which must be shared secretly
    Symmetric encryption uses the same secret key at both ends

    Asymmetric encryption (public-key)

    Asymmetric encryption 非对称加密 (asymmetric key cryptography) gives each user a pair of related keys: a public key 公钥 they publish, and a private key 私钥 they keep secret. Data encrypted with the public key can be decrypted only with the matching private key, and vice versa.

    Tom and Meera each have a public key to share and a private key kept secret; Meera sends Tom her public key
    Each user has a public key to share and a private key to keep secret

    To send a secret message to Alice: get her published public key, encrypt with it, and send. Only Alice — holding the matching private key — can decrypt. No prior key exchange is needed. The trade-off is that it is much slower than symmetric, so it is not used for large data.

    A private key must stay secret, so it is sometimes kept on a small hardware security key 硬件安全密钥. You plug it in or tap it to prove who you are, and the secret key never leaves the device.

    A black hardware security key on a white background, with a round gold touch sensor in the middle and a gold USB connector at one end
    A hardware security key stores a secret key to prove who you are

    Hybrid approach (used by almost every real system)

    Use asymmetric encryption to exchange a fresh session key 会话密钥, then use that symmetric key for the data:

    1. the client makes a random session key.
    2. it encrypts the session key with the server's public key.
    3. the server decrypts it with its private key.
    4. both ends now share the session key and use fast symmetric encryption for the rest.

    This is how HTTPS and SSH work.

    The client encrypts a session key with the server's public key and sends it; only the server's private key can open it; then both ends use fast symmetric encryption with the shared session key
    The hybrid approach: asymmetric crypto shares a session key once, then fast symmetric encryption protects the data

    Hashing (related, not encryption)

    A cryptographic hash 密码散列 function takes any input and gives a fixed-size digest 摘要 such that the same input always gives the same digest, it is infeasible to find two inputs with the same digest, and a tiny change in input changes the digest completely. Hashing is one-way — you cannot get the input back. It is used for storing password checks, integrity 完整性 checks, and digital signatures.

    A cryptographic hash maps the input hello to one digest and the input hellp, with one letter changed, to a completely different digest; hashing cannot be reversed
    A cryptographic hash gives a fixed digest; a tiny input change changes it completely, and it cannot be reversed
    Explore

    Hashing and the avalanche effect

    A hash is one-way: easy to compute, practically impossible to reverse. A tiny change in the input flips a large, unpredictable part of the output — the avalanche effect that makes hashes good for passwords.

    Explore

    The Caesar cipher

    Shift each letter to encrypt the message. A simple cipher shows the idea of a key — and why a small key is easy to break.

    Vocabulary Train
    English Chinese Pinyin
    encryption 加密 jiā mì
    plaintext 明文 míng wén
    ciphertext 密文 mì wén
    decryption 解密 jiě mì
    symmetric encryption 对称加密 duì chèn jiā mì
    key distribution 密钥分发 mì yào fēn fā
    asymmetric encryption 非对称加密 fēi duì chèn jiā mì
    public key 公钥 gōng yào
    private key 私钥 sī yào
    hardware security key 硬件安全密钥 yìng jiàn ān quán mì yào
    session key 会话密钥 huì huà mì yào
    cryptographic hash 密码散列 mì mǎ sàn liè
    digest 摘要 zhāi yào
    integrity 完整性 wán zhěng xìng
    quantum cryptography 量子密码学 liàng zǐ mì mǎ xué
    17.1

    SSL / TLS

    TLS 传输层安全 (Transport Layer Security, the successor to the Secure Socket Layer, SSL) is a protocol that gives encryption and authentication for data sent over a network. It encrypts the data in transit, authenticates the server with a certificate, and provides integrity (detecting tampering).

    Outline of a TLS handshake:

    1. the client connects and proposes cipher options.
    2. the server picks one and sends its digital certificate (with its public key) — issuing and validating these certificates is digital certification.
    3. the client checks the certificate.
    4. the two ends exchange a fresh session key using asymmetric crypto.
    5. all later traffic uses fast symmetric encryption with the session key.

    The result is an encrypted, authenticated, integrity-checked tunnel for higher-level protocols (HTTP, SMTP). It is appropriate wherever sensitive information is sent: HTTPS web browsing, online banking and payments, secure email, and VPNs.

    Explore

    The TLS handshake

    Step through what happens before a padlock appears. The slow public-key crypto is used only to agree a shared key; the actual page then travels under fast symmetric encryption.

    Vocabulary Train
    English Chinese Pinyin
    TLS 传输层安全 chuán shū céng ān quán
    17.1

    Digital certificates

    A digital certificate 数字证书 binds an identity (a domain, an organisation) to a public key, and is signed by a trusted Certificate Authority 证书颁发机构 (CA). It contains the subject (who it identifies), the subject's public key, the issuer (the CA), a validity period, and the CA's signature over all of it.

    A user sends a request with their identity and public key to a Certificate Authority, which verifies the identity and issues a signed digital certificate containing the public key, CA identification, user id, digital signature and other information
    A Certificate Authority issues a digital certificate binding an identity to a public key

    To verify one, the client (which holds a list of trusted root CAs):

    1. checks the expiry dates.
    2. checks the subject name matches the URL.
    3. checks it is signed by a trusted CA, using the CA's public key to verify the signature.
    4. follows the certificate chain up to a trusted root.

    If anything fails, the browser shows the "Your connection is not private" warning. When it verifies cleanly, the client knows the identity was vetted by a trusted CA, the public key really belongs to that identity, and the certificate is current.

    Vocabulary Train
    English Chinese Pinyin
    digital certificate 数字证书 shù zì zhèng shū
    Certificate Authority 证书颁发机构 zhèng shū bān fā jī gòu
    17.1

    Digital signatures

    A digital signature 数字签名 proves who signed a message and that it was not changed. To sign:

    1. compute a cryptographic hash of the message.
    2. encrypt the hash with the sender's private key — that is the signature.
    3. send the message and the signature.

    To verify: compute the hash of the received message; decrypt the signature with the sender's public key to get the sender's hash; compare. If they match, the message was signed by the holder of the private key (authentication 身份验证) and was not changed (integrity). A signature does not hide the message — for confidentiality as well, encrypt and sign.

    The sender hashes the message to a digest and encrypts it with their private key to form the signature; the receiver re-hashes the message and decrypts the signature with the sender's public key, then compares the two digests
    Signing hashes the message and encrypts the digest with the private key; the receiver checks it with the public key

    Putting it together

    A secure request to https://www.bank.com: the server sends its certificate; the client verifies it against trusted CAs; the client uses the server's public key to exchange a session key; then data flows encrypted with that key. Encryption stops eavesdroppers, the certificate proves the server's identity, and integrity checks stop a man-in-the-middle 中间人攻击 altering the data.

    Worked example. Alice sends Bob a contract. She wants Bob to be certain it came from her and was not altered, and she wants nobody else to be able to read it. Which keys does she use, and in which direction? These are two different jobs needing two different key pairs. For the signature (authentication and integrity): Alice hashes the contract and encrypts that hash with her own private key; Bob decrypts it with Alice's public key and compares it against his own hash of the message. Only Alice holds her private key, so only she could have produced it. For confidentiality: Alice encrypts the contract itself with Bob's public key, so only Bob's private key can open it. One rule keeps all four straight: you sign with your own private key and encrypt with the recipient's public key. A signature on its own does not hide the message.

    Vocabulary Train
    English Chinese Pinyin
    digital signature 数字签名 shù zì qiān míng
    authentication 身份验证 shēn fèn yàn zhèng
    man-in-the-middle 中间人攻击 zhōng jiān rén gōng jī
    17.1

    Exam tips

    • Distinguish symmetric encryption (one shared key, fast) from asymmetric (a public/private key pair).
    • Explain the TLS handshake and why a digital certificate from a CA proves identity.
    • Explain a digital signature: hash the message, then encrypt the hash with the private key — it proves integrity and origin.
  • 18 Artificial Intelligence (AI)
    18.1

    What AI is

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of how graphs can be used to aid Artificial Intelligence (AI) Purpose and structure of a graph Use A algorithm* and Dijkstra’s algorithm to perform searches on a graph Candidates will not be required to write algorithms to set up, access, or perform searches on graphs
    Show understanding of how artificial neural networks have helped with machine learning
    Show understanding of Deep Learning, Machine Learning and Reinforcement Learning and the reasons for using these methods. Understand machine learning categories, including supervised learning, unsupervised learning
    Show understanding of back propagation of errors and regression methods in machine learning

    Source: Cambridge International syllabus

    Artificial intelligence 人工智能 (AI) builds systems that do tasks normally needing human intelligence — recognising speech and images, translating, playing games, driving, generating text. Most modern AI uses machine learning 机器学习 — algorithms that learn patterns from data instead of being programmed step by step. Within it, deep learning 深度学习, using neural networks 神经网络 with many layers, has been dominant since the 2010s.

    A humanoid robot 人形机器人 puts many of these abilities into one body: it uses AI to see faces, understand speech and move its face and arms in a lifelike way.

    A grey humanoid robot with a lifelike face looking upward, its mechanical neck, chest and arms exposed, on a white background
    A humanoid robot uses AI to see, listen and respond like a person
    Three nested rounded boxes: Artificial Intelligence contains Machine Learning, which contains Deep Learning, each with a short note
    Deep learning is part of machine learning, which is part of AI
    Explore

    AI learning type lab

    Classify AI examples by the type of learning or concern involved.

    Vocabulary Train
    English Chinese Pinyin
    artificial intelligence 人工智能 rén gōng zhì néng
    machine learning 机器学习 jī qì xué xí
    deep learning 深度学习 shēn dù xué xí
    neural networks 神经网络 shén jīng wǎng luò
    humanoid robot 人形机器人 rén xíng jī qì rén
    18.1

    Graphs in AI

    Many AI problems sit on a graphnodes 节点 (states, places) joined by edges (moves, relationships).

    • pathfinding: roads form a graph; the shortest route is a graph search (Dijkstra's algorithm, the A* algorithm).
    • game playing: each board position is a node, each move an edge; minimax 极小化极大 with alpha-beta pruning searches the game tree.
    • state-space search: a planning problem is moving between states by applying operators to reach a goal.
    • knowledge representation: a semantic network 语义网络 has concepts as nodes and relationships as edges ("dog IS-A animal"); a knowledge graph 知识图谱 stores facts about the world for search engines and assistants.
    A weighted graph of nodes A to G; the shortest path from A to G via B and E is highlighted in orange
    AI problems often sit on a graph; here the shortest path is highlighted

    Standard tools for navigating graphs include breadth-first search 广度优先搜索 and depth-first search 深度优先搜索.

    Vocabulary Train
    English Chinese Pinyin
    graph
    nodes 节点 jié diǎn
    edges biān
    minimax 极小化极大 jí xiǎo huà jí dà
    semantic network 语义网络 yǔ yì wǎng luò
    knowledge graph 知识图谱 zhī shí tú pǔ
    breadth-first search 广度优先搜索 guǎng dù yōu xiān sōu suǒ
    depth-first search 深度优先搜索 shēn dù yōu xiān sōu suǒ
    18.1

    Artificial neural networks (ANNs)

    An ANN is inspired by the brain's neurons. An artificial neuron 人工神经元:

    • takes several input values, multiplies each by a weight 权重, and adds them up with a bias term 偏置项.
    • applies an activation function 激活函数 (a non-linear function such as ReLU) to the sum.
    • outputs the result, which feeds neurons further on.
    A single artificial neuron: three inputs each multiplied by a weight, summed with a bias, passed through an activation function, giving one output value
    A single neuron: each input times its weight, summed with a bias, then an activation function

    Neurons sit in layers: an input layer, one or more hidden layers 隐藏层 (where useful internal patterns are learned), and an output layer. With many hidden layers it is a deep neural network 深度神经网络, and training it is deep learning.

    Circles in four columns: an input layer of three nodes, two hidden layers of five nodes each, and one output node, all connected
    A neural network with an input layer, two hidden layers and an output layer

    ANNs let models learn complex patterns straight from raw data (pixels, audio, text) without hand-designed features — driving breakthroughs in image recognition 图像识别, speech recognition 语音识别, machine translation 机器翻译, and game playing. They do well with large amounts of data, noisy or very complex input, and patterns too hard to capture with explicit rules.

    Explore

    Tap the parts of a neural network

    Explore the layers. Data flows left to right: the input layer takes the features, the hidden layers learn patterns, and the output layer gives the answer — with every connection carrying a weight that training adjusts.

    Vocabulary Train
    English Chinese Pinyin
    artificial neuron 人工神经元 rén gōng shén jīng yuán
    weight 权重 quán zhòng
    bias term 偏置项 piān zhì xiàng
    activation function 激活函数 jī huó hán shù
    hidden layers 隐藏层 yǐn cáng céng
    deep neural network 深度神经网络 shēn dù shén jīng wǎng luò
    image recognition 图像识别 tú xiàng shí bié
    speech recognition 语音识别 yǔ yīn shí bié
    machine translation 机器翻译 jī qì fān yì
    18.1

    Machine learning, deep learning, reinforcement learning

    Machine learning

    The umbrella term — any algorithm that learns from data. Three paradigms:

    • supervised learning 监督学习 — the data has labels 标签 (images tagged "cat"/"dog"); the algorithm learns input → label. Used for classification 分类 (a category) and regression.
    • unsupervised learning 无监督学习 — no labels; the algorithm finds structure, e.g. a cluster 聚类 of similar customers.
    • reinforcement learning (below).

    Use ML when explicit rules would be impractical (spam filters, recommendations, fraud detection).

    A pipeline: labelled training data trains a model, the trained model classifies new unlabelled data, and outputs how many of each type were found
    Supervised learning: a model is trained on labelled data, then recognises new data

    Deep learning

    A subset of ML using deep neural networks. Lower layers learn simple patterns (edges, phonemes), higher layers combine them into abstract concepts. It needs lots of data and lots of compute (GPUs); for small datasets, simpler ML methods often do better.

    Reinforcement learning

    In reinforcement learning 强化学习, an agent 智能体 acts in an environment; each action changes the state and returns a reward 奖励. The agent learns a policy 策略 (a strategy) that maximises the total reward over time, by trial and error with no labels up front. Used for sequential-decision problems — games, robot control, autonomous driving.

    A loop between two boxes: the agent sends an action to the environment, which returns a new state and a reward back to the agent
    Reinforcement learning: the agent acts, the environment returns a new state and a reward, and the agent learns from it

    A self-driving car 自动驾驶汽车 is a real example. Lidar 激光雷达 and camera sensors (the spinning unit on the roof) build a live picture of the road, and a learned policy decides how to steer, speed up and brake safely.

    A white Waymo self-driving car on a city street, with a spinning lidar sensor unit on its roof and extra cameras at the front corners
    A self-driving car uses cameras and lidar sensors to see the road around it
    Several orange industrial robot arms welding a car body as it moves along a factory production line
    Industrial robot arms on a production line: reinforcement learning can teach a robot to control its movements
    Vocabulary Train
    English Chinese Pinyin
    supervised learning 监督学习 jiān dū xué xí
    labels 标签 biāo qiān
    classification 分类 fēn lèi
    unsupervised learning 无监督学习 wú jiān dū xué xí
    cluster 聚类 jù lèi
    reinforcement learning 强化学习 qiáng huà xué xí
    agent 智能体 zhì néng tǐ
    reward 奖励 jiǎng lì
    policy 策略 cè lüè
    self-driving car 自动驾驶汽车 zì dòng jià shǐ qì chē
    lidar 激光雷达 jī guāng léi dá
    18.1

    Training an ANN: backpropagation

    Training adjusts the weights so outputs match the targets. The standard method is backpropagation 反向传播 (back propagation of errors) with gradient descent 梯度下降. For each training example:

    1. forward pass — feed the input through to the output.
    2. compute the error with a loss function 损失函数 (a single number for how wrong the output is).
    3. backward pass — propagate the error backwards, finding each weight's gradient (how much it contributed to the error) using the chain rule.
    4. update the weights by a small step (set by the learning rate 学习率) that reduces the error.

    Repeat over many examples and many passes (epochs 训练轮次) until the error stops shrinking. The name "back" comes from step 3: the error flows from the output back towards the input, so every weight's gradient is found in one sweep. After training, a new input needs only one forward pass to get a prediction.

    A U-shaped curve of squared error against weight, with steps moving downhill towards the minimum error
    Training adjusts the weights to reach the minimum error
    Vocabulary Train
    English Chinese Pinyin
    backpropagation 反向传播 fǎn xiàng chuán bō
    gradient descent 梯度下降 tī dù xià jiàng
    loss function 损失函数 sǔn shī hán shù
    learning rate 学习率 xué xí lǜ
    epochs 训练轮次 xùn liàn lún cì
    18.1

    Regression

    Some tasks predict a number (a house price, tomorrow's temperature) — regression 回归, as opposed to classification (a category).

    Linear regression 线性回归 fits a straight line (or hyperplane):

    $$y = m_{1} x_{1} + m_{2} x_{2} + \ldots + m_{n} x_{n} + c.$$

    Choose the coefficients to minimise the sum of squared errors against the training data. Use it when the relationship looks roughly linear and you want an interpretable model. For curved data, use polynomial, decision-tree, or neural-network regression methods — same idea: define a model, define a loss, and adjust the parameters to minimise it. Regression and classification are both supervised; the choice depends on whether the answer is a number or a category.

    A scatter of points with a straight best-fit line through them; dashed vertical lines show the error between each point and the line
    Linear regression fits the line that makes the total squared error (the dashed gaps) as small as possible
    Explore

    Fitting a regression line

    Drag the controls. Linear regression draws the straight line that makes the squared distances to the data points as small as possible — then it predicts a number for any new input.

    Vocabulary Train
    English Chinese Pinyin
    regression 回归 huí guī
    linear regression 线性回归 xiàn xìng huí guī
    18.1

    How AI is used in a real scenario

    Many exam scenarios use the same pattern — a deep-learning model trained on labelled data, often several combined into a pipeline:

    • customer identification at an automated shop: the system is trained on labelled face images; a camera captures a face; image recognition extracts a representation; it is matched against registered customers; the closest match identifies the person.
    • reading text from images: image recognition finds text regions; optical character recognition 光学字符识别 extracts the characters; machine translation converts them; text-to-speech 文本转语音 reads them aloud.
    • checkout item-detection: object-detection AI, trained on labelled product images, sees which items go into a basket and charges the account.

    By the time a user interacts with the system, the model is fast — it only does forward-pass inference; the intelligence is in the patterns learned during training.

    Worked example. For each task, say whether it needs regression or classification, and what the output layer of an ANN would look like: (a) predict tomorrow's temperature; (b) decide whether an email is spam. Ask what kind of thing is being predicted. (a) A temperature is a number on a continuous scale, so this is regression, and the output layer is a single neuron holding that value. (b) Spam or not-spam is a category, so this is classification, and the output gives a probability per class. Both are supervised learning: each needs labelled examples to train on, and training adjusts the weights by backpropagation to reduce the error. The deciding question is simply number-or-category - not how difficult the task feels.

    Vocabulary Train
    English Chinese Pinyin
    optical character recognition 光学字符识别 guāng xué zì fú shí bié
    text-to-speech 文本转语音 wén běn zhuǎn yǔ yīn
    18.1

    Exam tips

    • Distinguish machine learning, deep learning and reinforcement learning with an example of each.
    • Describe an ANN (input, hidden and output layers; weighted connections) and how backpropagation adjusts weights to cut error.
    • Distinguish supervised vs unsupervised learning; regression predicts a continuous value.
  • 19 Computational thinking and Problem-solving
    19.1

    Searching algorithms

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of linear search and binary search methods Write an algorithm to implement a linear search Write an algorithm to implement a binary search The conditions necessary for the use of a binary search How the performance of a binary search varies according to the number of data items
    Show understanding of insertion sort and bubble sort methods Write an algorithm to implement an insertion sort Write an algorithm to implement a bubble sort Performance of a sorting routine may depend on the initial order of the data and the number of data items
    Show understanding of and use Abstract Data Types (ADT) Write algorithms to find an item in each of the following: linked list, binary tree Write algorithms to insert an item into each of the following: stack, queue, linked list, binary tree Write algorithms to delete an item from each of the following: stack, queue, linked list Show understanding that a graph is an example of an ADT. Describe the key features of a graph and justify its use for a given situation. Candidates will not be required to write code for a graph structure
    Show how it is possible for ADTs to be implemented from another ADT Describe the following ADTs and demonstrate how they can be implemented from appropriate built-in types or other ADTs: stack, queue, linked list, dictionary, binary tree
    Show understanding that different algorithms which perform the same task can be compared by using criteria (e.g. time taken to complete the task and memory used) Including use of Big O notation to specify time and space complexity

    Source: Cambridge International syllabus

    Big O: how algorithms scale
    Insertion sort: slide each card into place
    Bubble sort, pass by pass
    Binary search: halve and conquer

    A search finds a target value in a collection (often an array 数组) and returns its position, or "not found".

    An open telephone directory
    Searching a sorted list, like a phone book, is far faster than checking every entry one by one

    Linear search

    A linear search 线性查找 walks from start to end, comparing each element with the target:

    FOR i ← 1 TO n
        IF A[i] = target THEN RETURN i
    NEXT i
    RETURN -1   // not found
    

    No preparation is needed, so it works on any list. Worst case O($n$) (target at the end or absent); best case 1 comparison. Use it on unsorted data or small lists. (The returned -1 is a sentinel value — an impossible position that means "not found"; the caller tests IF result = -1.)

    A row of alphabet cells A to Z; cells A to V are shaded as checked and W is highlighted as the match, with a pointer below W
    Linear search checks every letter in turn — 23 comparisons to find W

    Binary search

    A binary search 二分查找 needs the data sorted. Look at the middle element; if it is the target, done; if the target is smaller, search the left half, else the right half — halving the range each time:

    low ← 1
    high ← n
    WHILE low <= high DO
        mid ← (low + high) DIV 2
        IF A[mid] = target THEN RETURN mid
        IF A[mid] < target THEN
            low ← mid + 1
        ELSE
            high ← mid - 1
        ENDIF
    ENDWHILE
    RETURN -1
    

    Worst case O($\log_{2} n$) — for a million items, about 20 comparisons. Much faster than linear search on large sorted arrays, but you must sort first (a one-off O($n \log n$) cost), worth it if you search many times.

    Three rows showing binary search on the sorted alphabet; the active low-to-high range halves each step as the middle letter M, then T, then W is compared with W
    Binary search halves the range each step (low / mid / high) — just 3 comparisons to find W
    Explore

    Linear vs binary search

    Search for a value. Binary search halves the list each step (only on sorted data); linear search checks one by one.

    Vocabulary Train
    English Chinese Pinyin
    array 数组 shù zǔ
    linear search 线性查找 xiàn xìng chá zhǎo
    binary search 二分查找 èr fēn chá zhǎo
    19.1

    Sorting algorithms

    Bubble sort

    A bubble sort 冒泡排序 repeatedly walks the array, swapping adjacent pairs that are out of order, so the largest "bubbles" to the end each pass:

    FOR pass ← 1 TO n - 1
        swapped ← FALSE
        FOR i ← 1 TO n - pass
            IF A[i] > A[i + 1] THEN
                temp ← A[i]
                A[i] ← A[i + 1]
                A[i + 1] ← temp
                swapped ← TRUE
            ENDIF
        NEXT i
        IF swapped = FALSE THEN EXIT FOR   // already sorted
    NEXT pass
    

    Best case O($n$) (already sorted, with the early exit); average/worst O($n^{2}$). Simple but slow for large $n$.

    Insertion sort

    An insertion sort 插入排序 builds a sorted prefix from the left, inserting each new element into place by shifting larger ones right:

    FOR i ← 2 TO n
        key ← A[i]
        j ← i - 1
        WHILE j >= 1 AND A[j] > key DO
            A[j + 1] ← A[j]
            j ← j - 1
        ENDWHILE
        A[j + 1] ← key
    NEXT i
    

    Best case O($n$) (already sorted); worst O($n^{2}$). Good for small or nearly-sorted arrays. It sorts in place 原地 and is stable 稳定 (keeps the order of equal elements).

    Tracing a sort

    A common task is to show the array after each outer pass. For [D, T, H, R] with insertion sort: pass 1 (key T) no change; pass 2 (key H) → [D, H, T, R]; pass 3 (key R) → [D, H, R, T].

    Rows tracing an insertion sort of D, T, H, R across three passes; the sorted prefix is shaded and arrows show each larger element shifting right to let the key drop in
    An insertion sort of [D, T, H, R], shifting each key into its place pass by pass
    Explore

    Watch a sort run

    Step through a sort and watch the bars settle into order — how a sorting algorithm works pass by pass.

    Vocabulary Train
    English Chinese Pinyin
    bubble sort 冒泡排序 mào pào pái xù
    insertion sort 插入排序 chā rù pái xù
    in place 原地 yuán dì
    stable 稳定 wěn dìng
    19.1

    ADTs in algorithms

    The Abstract Data Types (ADTs) from Topic 10 appear inside many algorithms: a stack drives depth-first traversal and undo; a queue 队列 drives breadth-first traversal and print ordering; a linked list 链表 lets data grow and shrink.

    ADTs can be built from other ADTs, not just from arrays: a queue from two stacks; a stack from a linked list (push = prepend a head node 节点); a queue from a linked list with head and tail pointers 指针; a binary tree 二叉树 from nodes with two child pointers; a dictionary 字典 stores key→value pairs (often on a hash table). Layering this way separates concerns — the algorithm using the ADT need not know how it is built.

    A binary tree with root 27, a left subtree of 19, 16, 21 and 17, and a right subtree of 36, 42, 89 and 55, with the root, the left and right pointers, and a leaf node labelled
    A binary tree: each node has up to two child nodes
    A binary search tree with root 4 (left subtree 2 over 1 and 3, right subtree 6 over 5 and 7); pre-order visits 4 2 1 3 6 5 7, in-order 1 2 3 4 5 6 7 (sorted), post-order 1 3 2 5 7 6 4
    Three depth-first traversals of a binary tree: pre-order, in-order (sorted order) and post-order
    Vocabulary Train
    English Chinese Pinyin
    stack zhàn
    queue 队列 duì liè
    linked list 链表 liàn biǎo
    node 节点 jié diǎn
    pointers 指针 zhǐ zhēn
    binary tree 二叉树 èr chā shù
    dictionary 字典 zì diǎn
    19.1

    Comparing algorithms

    Time complexity

    Time complexity 时间复杂度 is how the running time grows with input size $n$, written in Big-O notationO表示法 (the dominant term): O(1) constant, O($\log n$) binary search, O($n$) linear search, O($n \log n$) good sorts, O($n^{2}$) bubble/insertion sort. A smaller order is better at scale, even if another algorithm is faster for small $n$.

    To make that concrete: to sort a million items, an $O(n \log n)$ sort finishes in a fraction of a second, while an $O(n^{2})$ sort can take minutes.

    Worked example. A sorted list holds $1000$ items. How many comparisons does each search need in the worst case?

    A linear search checks items one at a time, so it may need up to $1000$ comparisons — this is $O(n)$. A binary search halves the list each step, so it needs at most $\lceil \log_2 1000 \rceil = 10$ comparisons — this is $O(\log n)$. Doubling the list to $2000$ items adds only one comparison to the binary search, but up to another $1000$ to the linear search — which is why the order of growth, not raw speed, decides the winner at scale.

    A graph of running time against input size n for the common orders: O(1) and O(log n) stay almost flat, O(n) rises gently, O(n log n) more steeply, and O(n squared) climbs away fastest
    How the common orders of growth compare: a smaller order wins at scale
    A line graph of running time against the number of elements n: bubble sort and insertion sort rise steeply as O(n squared), while quick sort stays low as O(n log n)
    How sorting time grows with the number of elements $n$: $O(n^2)$ sorts climb away from an $O(n\log n)$ sort

    Space complexity

    Space complexity 空间复杂度 is the extra memory needed. Bubble and insertion sort use O(1) extra (in place); merge sort uses O($n$); recursion uses stack memory proportional to its depth. There is often a time–memory trade-off.

    Other criteria

    Simplicity (easier to code and maintain), stability, and adaptiveness (faster on nearly-sorted data). The right algorithm depends on the data and the constraints.

    Explore

    How running time grows with n

    Slide n upward and compare the curves: O(1) and O(log n) stay almost flat, O(n) rises steadily, O(n²) explodes. This is why Big-O — not a stopwatch — is how we compare algorithms on large inputs.

    Explore

    Big-O growth

    Change the input size n and compare how fast each algorithm's work grows — the idea behind time complexity.

    Vocabulary Train
    English Chinese Pinyin
    time complexity 时间复杂度 shí jiān fù zá dù
    Big-O notation 大O表示法 dà O biǎo shì fǎ
    space complexity 空间复杂度 kōng jiān fù zá dù
    19.2

    Recursion

    Syllabus
    Candidates should be able to: Notes and guidance
    Show understanding of recursion Essential features of recursion How recursion is expressed in a programming language Write and trace recursive algorithms When the use of recursion is beneficial
    Show awareness of what a compiler has to do to translate recursive programming code Use of stacks and unwinding

    Source: Cambridge International syllabus

    Recursion: the call stack winds up and unwinds

    Recursive algorithms use recursion 递归: the routine calls itself with a smaller version of the same problem, until a base case 基本情形 ends the chain. It has two parts: the base case (small enough to solve directly — without it the recursion never stops) and the recursive case 递归情形 (reduce the input and call itself).

    Factorial 阶乘:

    FUNCTION Factorial(n : INTEGER) RETURNS INTEGER
        IF n = 0 OR n = 1 THEN
            RETURN 1
        ELSE
            RETURN n * Factorial(n - 1)
        ENDIF
    ENDFUNCTION
    

    Recursion is natural for self-similar problems: trees, divide-and-conquer 分治 (binary search, merge sort), and nested data. When it is a poor fit, a loop is usually cleaner.

    Tracing a recursive call

    For Factorial(4): the calls go down to Factorial(1)=1, then unwinding multiplies back up: 2*1=2, 3*2=6, 4*6=24. Final result 24. Track each pending call on a stack.

    The call stack for Factorial(4): each call pushes a frame down to the base case Factorial(1)=1, then the stack unwinds, returning 2 = 2 times 1, 6 = 3 times 2 and 24 = 4 times 6
    Recursion uses the call stack: calls push frames down to the base case, then returns unwind back up

    Risks

    • infinite recursion if the base case is missed — crashes with a stack overflow 栈溢出.
    • high memory use for deep recursion.
    • slow if it repeats work (naive Fibonacci is exponential — use a loop or memoisation 记忆化).
    Explore

    Recursion unwinds from the leaves up

    Step through fib(4) in the order the calls actually finish: the leaves (base cases) resolve first, then each parent combines its children. Notice fib(2) is computed twice — that repeated work is why naive recursion is slow.

    Vocabulary Train
    English Chinese Pinyin
    recursion 递归 dì guī
    base case 基本情形 jī běn qíng xíng
    recursive case 递归情形 dì guī qíng xíng
    factorial 阶乘 jiē chéng
    divide-and-conquer 分治 fēn zhì
    stack overflow 栈溢出 zhàn yì chū
    memoisation 记忆化 jì yì huà
    19.2

    What the compiler does for recursive code

    Recursion needs each call to have its own copy of its parameters 参数 and local variables 局部变量. The compiler keeps these on the call stack 调用栈. For each call it pushes a stack frame 栈帧 holding the parameters, the local variables, and the return address 返回地址 (where to resume in the caller). When the function returns, the return value is handed back, the frame is popped, and control resumes at the return address.

    Because each call has its own frame, recursive calls don't trample each other's variables. The stack can grow large for deep recursion, which is why very deep recursion may overflow it. This is the same call-and-return mechanism used for ordinary (non-recursive) calls — there is no special "recursion mechanism".

    Vocabulary Train
    English Chinese Pinyin
    parameters 参数 cān shù
    local variables 局部变量 jú bù biàn liàng
    call stack 调用栈 diào yòng zhàn
    stack frame 栈帧 zhàn zhēn
    return address 返回地址 fǎn huí dì zhǐ
    19.2

    Exam tips

    • Match each algorithm to its Big-O: linear search $O(n)$, binary search $O(\log n)$, bubble/insertion $O(n^2)$, good sorts $O(n \log n)$.
    • Binary search needs a sorted list and halves the search space each step.
    • A recursive routine needs a base case and a call to itself; explain how deep recursion overflows the call stack.
    • Trace a sort or search with a table when asked, showing each pass.
  • 20 Further Programming
    20.1

    Programming paradigms

    Syllabus
    Candidates should be able to: Notes and guidance
    Understanding what is meant by a programming paradigm
    Show understanding of the characteristics of a number of programming paradigms:
    Low-level Low-level Programming: • understanding of and ability to write low-level code that uses various addressing modes: immediate, direct, indirect, indexed and relative
    Imperative (Procedural) Imperative (Procedural) programming: • Assumed knowledge and understanding of Structural Programming (see details in AS content section 11.3) • understanding of and ability to write imperative (procedural) programming code that uses variables, constructs, procedures and functions. See details in AS content
    Object Oriented Object-Oriented Programming (OOP): • understanding of the terminology associated with OOP (including objects, properties/attributes, methods, classes, inheritance, polymorphism, containment (aggregation), encapsulation, getters, setters, instances) • understanding of how to solve a problem by designing appropriate classes • understanding of and ability to write code that demonstrates the use of OOP
    Declarative Declarative programming: • understanding of and ability to solve a problem by writing appropriate facts and rules based on supplied information • understanding of and ability to write code that can satisfy a goal using facts and rules

    Source: Cambridge International syllabus

    A programming paradigm 编程范式 is a style of programming — a way of structuring programs, with its own ideas and language features. Four programming paradigms are in this syllabus.

    Four paradigms: low-level, imperative, object-oriented and declarative
    Four paradigms: low-level, imperative, object-oriented and declarative

    Low-level programming

    Programming close to the hardware in machine code 机器码 or assembly language 汇编语言, where each instruction maps to what the CPU runs. It gives direct access to registers 寄存器 and memory addresses 内存地址, using different addressing modes 寻址方式 (immediate, direct, indirect, indexed and relative). It is very fast and compact, but architecture-specific, tedious, and hard to maintain. This is low-level 低级 programming, used for device drivers, firmware and bootloaders.

    Imperative (procedural) programming

    In imperative programming 命令式编程 the programmer writes a sequence of commands that change the program's state — assignments, conditionals, loops, function calls. Variables 变量 hold state; statements change it; code is organised into procedures and functions (also called structured or structural programming). This is the style of Topics 9 and 11 (Python, C). Strong when the algorithm has clear sequential steps.

    Object-oriented programming (OOP)

    In object-oriented programming 面向对象编程 programs are built from objects 对象 — units combining data (attributes 属性) and operations (methods 方法). Objects are instances 实例 of classes. The four pillars:

    • encapsulation 封装 — an object's data is hidden behind its methods; outside code uses the public methods only, not the data directly. This protects the object and lets its internals change without breaking callers. For example, a BankAccount hides its balance; you change it only through deposit() and withdraw(), which can enforce a rule like "never go below zero".
    • inheritance 继承 — a subclass 子类 specialises a superclass 父类, inheriting its attributes and methods and adding or overriding 重写 them. Models "is-a" ("a Manager is an Employee").
    • polymorphism 多态 — different objects respond to the same method call differently; the caller need not know the exact type. Every Shape has Area(), and a Circle and a Rectangle each implement it their own way.
    • abstraction 抽象 — show a simple interface and hide the implementation.

    Other terms:

    • a constructor 构造函数 is a special method run when an object is created, to set up its attributes.
    • getters and setters read and write an object's attributes (its properties) through methods.
    • aggregation 聚合 and containment 包含 build an object from other objects (a "has-a" relationship).

    OOP is used for large systems, GUIs, simulations and games.

    The same call shape.Area() runs different code for each object: a Circle computes pi r squared, a Rectangle computes width times height
    Polymorphism: the same method call runs each object's own code
    A UML class diagram for Shape: a three-part box with the class name, private attributes (Name, Area, Perimeter, marked with minus) and public methods (SetShape, calculateArea, calculatePerimeter, marked with plus)
    A class diagram for a Shape: private attributes and public methods
    A UML inheritance diagram: the employee superclass at the top, with partTime and fullTime subclasses below, each joined to the superclass by a hollow-triangle generalisation arrow and adding its own attributes and methods
    Inheritance: partTime and fullTime are subclasses of employee
    A BankAccount object with a private balance reached only through the public methods deposit() and withdraw(); outside code cannot touch the data directly
    Encapsulation: an object's data is private, reached only through its public methods

    Declarative programming

    In declarative programming 声明式编程 you say what to compute, not how — the runtime works out the steps. Two kinds:

    • functional programming 函数式编程 — built from pure functions 纯函数 (no side effects 副作用; same input always gives the same output) composed together. Examples: Haskell, Lisp.
    • logic programming 逻辑编程 — state facts and rules; the engine answers a goal (query) by inference. Example: Prolog.

    A familiar declarative example is SQL 结构化查询语言: SELECT * FROM Customer WHERE Country = 'UK' says what you want, not how to walk the records.

    Comparing paradigms

    Paradigm Strength Typical languages
    Low-level maximum control, speed assembly
    Imperative direct, intuitive C, Python
    Object-oriented modular, models entities Java, C#, Python
    Functional clear, no side effects Haskell, F#
    Logic inference, rules Prolog
    Database data queries SQL

    Modern languages often mix paradigms — Python supports all of procedural, OOP and functional. The right one depends on the problem.

    Explore

    Programming concept lab

    Connect examples to the programming idea they show.

    Vocabulary Train
    English Chinese Pinyin
    programming paradigm 编程范式 biān chéng fàn shì
    machine code 机器码 jī qì mǎ
    assembly language 汇编语言 huì biān yǔ yán
    registers 寄存器 jì cún qì
    memory addresses 内存地址 nèi cún dì zhǐ
    low-level 低级 dī jí
    imperative programming 命令式编程 mìng lìng shì biān chéng
    variables 变量 biàn liàng
    object-oriented programming 面向对象编程 miàn xiàng duì xiàng biān chéng
    objects 对象 duì xiàng
    attributes 属性 shǔ xìng
    methods 方法 fāng fǎ
    instances 实例 shí lì
    classes lèi
    encapsulation 封装 fēng zhuāng
    inheritance 继承 jì chéng
    subclass 子类 zi lèi
    superclass 父类 fù lèi
    overriding 重写 zhòng xiě
    polymorphism 多态 duō tài
    abstraction 抽象 chōu xiàng
    constructor 构造函数 gòu zào hán shù
    declarative programming 声明式编程 shēng míng shì biān chéng
    functional programming 函数式编程 hán shù shì biān chéng
    pure functions 纯函数 chún hán shù
    side effects 副作用 fù zuò yòng
    logic programming 逻辑编程 luó jí biān chéng
    SQL 结构化查询语言 jié gòu huà chá xún yǔ yán
    addressing modes 寻址方式 xún zhǐ fāng shì
    aggregation 聚合 jù hé
    containment 包含 bāo hán
    20.2

    File processing

    Syllabus
    Candidates should be able to: Notes and guidance
    Write code to perform file-processing operations Open (in read, write, append mode) and close a file Read a record from a file and write a record to a file Perform file-processing operations on serial, sequential, random files
    Show understanding of an exception and the importance of exception handling Know when it is appropriate to use exception handling Write program code to use exception handling

    Source: Cambridge International syllabus

    This extends the file 文件 handling from Topic 10, processing serial, sequential and random (direct-access) files. Pseudocode operations: OPENFILE name FOR READ | WRITE | APPEND (READ opens an existing file, WRITE creates/overwrites, APPEND adds to the end); READFILE name, line; WRITEFILE name, value; CLOSEFILE name; and EOF(name) which is TRUE at the end.

    Read a whole file:

    OPENFILE "names.txt" FOR READ
    WHILE NOT EOF("names.txt") DO
        READFILE "names.txt", thisName
        OUTPUT thisName
    ENDWHILE
    CLOSEFILE "names.txt"
    

    Search a file (stop when found):

    found ← FALSE
    OPENFILE "people.txt" FOR READ
    WHILE NOT EOF("people.txt") AND NOT found DO
        READFILE "people.txt", line
        IF line = target THEN found ← TRUE
    ENDWHILE
    CLOSEFILE "people.txt"
    

    Updating a file in place

    Most languages can't edit a text file in place. Instead: open the original for READ and a temporary file for WRITE; for each line, write the new version if it should change, else the original; close both; then replace the original with the temp file. The same pattern handles deleting lines (skip them) and inserting lines.

    Updating a file in place: read the original file, write the changed lines to a temp file, then replace the original with the temp file
    Updating a file in place: read the original, write changes to a temp file, then replace the original

    Pitfalls

    Forgetting to close a file (data may be lost); opening for WRITE when you meant APPEND (overwrites everything); reading past EOF; hard-coded paths — a path like /Users/Admin/data.txt breaks on another machine, so use a relative constant such as DataFile = "./data/scores.txt".

    Explore

    File access route

    Follow a file from storage to program and back safely.

    Vocabulary Train
    English Chinese Pinyin
    file 文件 wén jiàn
    20.2

    Exception handling

    An exception 异常 is an error or unexpected condition during execution — divide by zero, file not found, network failure, an array 数组 index out of range. Exception handling 异常处理 lets a program detect it and respond gracefully instead of crashing.

    It matters because real programs face errors that cannot be prevented up front (files moved, networks down, bad input); without it, every operation needs its own IF check; and it separates the normal flow from the error handling, so the main path reads cleanly. For example, a file may be deleted by another user between your program checking it exists and actually opening it — you cannot prevent that, only handle the failure when it happens.

    Pattern

    TRY
        OPENFILE "data.txt" FOR READ
        READFILE "data.txt", line
        OUTPUT line
        CLOSEFILE "data.txt"
    EXCEPT FileNotFound
        OUTPUT "Sorry, the file does not exist."
    EXCEPT ReadError
        OUTPUT "Sorry, error reading the file."
    ENDTRY
    

    The TRY block holds the code that might fail; the first matching EXCEPT block runs. Real languages also have a catch-all EXCEPT and a FINALLY block that runs whether or not an exception happened — useful for cleanup (closing files).

    Exception flow: if the TRY block raises an exception, control jumps to the matching EXCEPT; with no exception it is skipped. Either way the FINALLY block runs, then the program continues
    Exception flow: an exception jumps to the matching EXCEPT; FINALLY always runs before the program continues

    Raising an exception

    A subroutine that detects an error can raise 抛出 an exception so the caller handles it:

    PROCEDURE Divide(a : INTEGER, b : INTEGER) RETURNS INTEGER
        IF b = 0 THEN
            RAISE DivideByZero
        ENDIF
        RETURN a DIV b
    ENDPROCEDURE
    

    Where to handle exceptions

    Handle them close to the error if the response is simple (a message, a retry), or higher up the call stack 调用栈 if only the outer code knows what to do (a top-level GUI loop logs the error and shows a friendly dialog). Don't swallow exceptions silently — at least log them, or debugging becomes impossible.

    Common exceptions: FileNotFound, IOError, DivisionByZero, IndexOutOfRange, InvalidArgument, NullReference, OutOfMemory. Wrapping each failing operation in a TRY with the right EXCEPT handlers gives a program that degrades gracefully instead of crashing.

    Worked example. A text file of members needs one member's phone number changed. Why can the program not simply overwrite that line, and what is the pattern? A text file's lines are different lengths, and the file has no gaps to absorb a difference: a longer replacement would run into the next record, and a shorter one would leave part of the old line behind. So the pattern is to open the original for READ and a temporary file for WRITE, read every line in turn, writing the new version for the line that changes and the original line for all the others, close both, then replace the original with the temporary file. The same shape handles deleting (skip the line) and inserting (write the extra line). Note that every line gets written, not only the changed one - writing just the new record and losing the rest of the file is the classic slip.

    Explore

    How exception handling flows

    Step through what happens when code fails. The exception jumps out of the normal flow to a handler, FINALLY cleans up either way, and the program carries on instead of crashing.

    Vocabulary Train
    English Chinese Pinyin
    array 数组 shù zǔ
    exception 异常 yì cháng
    exception handling 异常处理 yì cháng chǔ lǐ
    raise 抛出 pāo chū
    call stack 调用栈 diào yòng zhàn
    20.2

    Exam tips

    • Distinguish the paradigms (procedural, object-oriented, declarative, low-level) and when each suits a problem.
    • For OOP, define class, object, inheritance, encapsulation and polymorphism with a short example.
    • Explain exception handling (try/catch) and why it beats letting the program crash.

Log in or create account

IGCSE & A-Level