First exams 2027 · SL & HL 2027 年首次开考 · SL 与 HL

A1.1.8 · Computer fundamentals

A1.1.8 · 计算机基础

The Concept of Compression

压缩的概念

A file usually contains more bits than it strictly needs: the same value repeated, or detail a person would never notice missing. Compression finds that slack and removes it, either in a way that can be undone exactly, or in a way that cannot.

一个文件通常包含比它严格需要的更多的位:重复的同一个值,或人根本不会察觉少了的细节。压缩找出这些"余量"并去掉它,要么以一种能被完全还原的方式,要么以一种不能还原的方式。

A1's guiding question asks what principles underpin how a computer works. Compression rests on one: real data has redundancy, and redundancy can be encoded more briefly.

A1 的引导性问题问的是支撑计算机运行的原理。压缩建立在一个原理之上:真实的数据存在冗余,而冗余可以用更简短的方式来编码。

Core for SL & HL SL 与 HL 核心内容 Typically 2–4 marks · AO2 通常 2–4 分 · AO2 Command term: describe 命令词:describe(描述)

Explainer

讲解

What compression is, and why

压缩是什么,以及为什么

Df

Compression is encoding a piece of data using fewer bits than its original representation. The two reasons to do it: the file takes up less storage space, and it is faster to send across a network.

压缩是用比原始表示更少的位来编码一段数据。这样做的两个原因:文件占用更少的存储空间,而且通过网络传输更快。

Explainer

讲解

Lossless vs lossy

无损与有损

Compared onLossless compressionLossy compression
Can the original be restored?Yes, exactly, bit for bitNo, some information is thrown away for good
What it removesOnly repeated or predictable information (redundancy), which is put back on decompressionDetail judged unimportant, such as fine detail a person is unlikely to notice missing
How much smallerModest reductionMuch larger reduction (often more than half)
Used forText, source code, databases, executables, anything where a single wrong bit mattersImages, audio and video, where a small quality drop is an acceptable trade for a much smaller file
比较项无损压缩有损压缩
能否还原出原始数据?能,一位不差地完全还原不能,一部分信息被永久丢弃
它去掉什么只去掉重复的或可预测的信息(冗余),解压时会把它放回去去掉被判断为不重要的细节,例如人不太可能察觉少了的精细细节
能小多少缩小幅度不大缩小幅度大得多(常常超过一半)
用于文本、源代码、数据库、可执行文件,以及任何一位出错都要命的数据图像、音频和视频,那里为了文件小得多,可以接受一点点质量下降

Try it yourself

动手试试

Run-length encoding

行程长度编码

Run-length encoding (RLE) is a lossless method for data with long runs of the same value. It replaces each run with a pair: how many times, then the value. Click the cells to paint a row of 40 pixels (black or white) and watch the encoding.

行程长度编码(RLE)是一种无损方法,适用于含有很长的同值行程的数据。它把每一段行程替换成一对:重复多少次,然后是那个值。点击格子来涂画一行 40 个像素(黑或白),看看编码结果。

RLE only helps when runs are long. Try the noisy pattern: with the colour changing almost every cell, the encoded version is bigger than the original, because every "1 white, 1 black" pair costs more than the single bit it replaces.

只有行程很长时 RLE 才有用。试试杂乱图案:颜色几乎每一格都在变,编码后的版本反而比原来更大,因为每一对"1 白、1 黑"都比它所替代的那 1 位花费更多。

Explainer

讲解

Transform coding (JPEG, MP3)

变换编码(JPEG、MP3)

Transform coding is a lossy method used in JPEG images and MP3 audio. It works in stages, using JPEG as the example:

变换编码是 JPEG 图像和 MP3 音频所用的一种有损方法。它分阶段进行,以 JPEG 为例:

StageWhat it does
Split into blocksThe image is cut into small square sub-images
TransformEach block is converted from pixel values into frequency values: low frequencies describe broad areas of colour, high frequencies describe fine detail and edges
QuantiseThe precision of the high-frequency values is reduced, because the eye barely notices small changes to fine detail. This is where information is actually lost, and where the compression level is set
EncodeThe reduced values are packed down further using lossless steps (including run-length encoding)
阶段它做什么
切成块图像被切成一个个小的正方形子图
变换每个块从像素值转换成频率值:低频描述大片的颜色区域,高频描述精细的细节和边缘
量化降低高频值的精度,因为人眼几乎察觉不到精细细节的微小变化。这一步才是真正丢失信息的地方,也是设定压缩程度的地方
编码把降低后的这些值用无损的步骤(包括行程长度编码)进一步压缩
Why it is lossy 它为什么是有损的

The quantise stage deliberately drops precision from the high-frequency detail and does not record it anywhere. Turn the quantisation up and the file gets smaller but the image gets blockier. That discarded detail cannot be recovered.

量化阶段故意舍弃高频细节的精度,并且不在任何地方记录它。把量化调大,文件更小,但图像更"块状"。那些被舍弃的细节无法恢复。

Check your understanding

检验你的理解

You need to compress a holiday photo and a spreadsheet of financial figures. Which should use lossless compression?

你需要压缩一张度假照片和一张财务数字的电子表格。哪一个应该用无损压缩?

Common mistake

常见错误

Recurring confusions about lossy compression and RLE 关于有损压缩和 RLE 的反复混淆

RecurringWeak answers say lossy compression "deletes random data" or "corrupts the file". It removes chosen detail, the parts judged least noticeable, so the result still looks or sounds almost the same. It is only a mistake to use it where exact data matters. A second slip: claiming RLE always makes a file smaller. It only helps when there are long runs of the same value; on data that changes constantly, the count-value pairs add up to more than the original.

反复出现薄弱的答案说有损压缩"随机删除数据"或"破坏文件"。它去掉的是被挑选出来的细节,即被判断为最不易察觉的部分,所以结果看起来或听起来仍然几乎一样。只有在需要精确数据的地方用它,才是错误。第二个错误:声称 RLE 总能让文件变小。只有当存在很长的同值行程时它才有用;对不断变化的数据,这些"计数-值"对加起来比原始数据还多。

✕

Misstates lossy: "Lossy compression randomly deletes bits, so the file is damaged and lower quality."

误解有损: "有损压缩随机删除位,所以文件被损坏、质量更低。"

✓

Right: "Lossy compression permanently removes detail that a person is unlikely to notice, so the file is much smaller and still looks or sounds close to the original. It cannot be restored exactly, so it suits images and audio but not data like text or spreadsheets."

正确: "有损压缩永久去掉人不太可能察觉的细节,所以文件小得多,而且看起来或听起来仍然接近原始。它无法被完全还原,所以适合图像和音频,而不适合文本或电子表格这类数据。"

Revision questions

复习题

Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.

采用样卷风格。写下答案,然后展开评分要点给自己打分。

Question 1 · 2 marks 第 1 题 · 2 分

[2]State the two main benefits of compressing a file.

[2]说出压缩一个文件的两个主要好处。

Question 2 · 3 marks 第 2 题 · 3 分

[3]Set out how lossless and lossy compression differ, and name one kind of file that suits each.

[3]解释无损压缩与有损压缩的区别,并各举一种适合的文件类型。

Question 3 · 4 marks 第 3 题 · 4 分

[4]Describe how run-length encoding works, and explain one type of data for which it is not effective.

[4]描述行程长度编码如何工作,并解释一种它效果不好的数据类型。

Question 4 · 5 marks 第 4 题 · 5 分

[5]Describe the stages of transform coding as used in JPEG, then state which stage makes the method lossy and why.

[5]描述 JPEG 压缩中变换编码的各个阶段,并解释它为什么是一种有损方法。

Question 5 · 3 marks 第 5 题 · 3 分

[3]A 12-character string "WWWWWWBBBWWW" is compressed with run-length encoding. State the encoded output and the size saving, assuming one byte per character.

[3]用行程长度编码压缩一个 12 字符的字符串 "WWWWWWBBBWWW"。假设每个字符占一个字节,写出编码后的输出以及节省的大小。

Flashcards

记忆卡片

Active recall for this statement’s key terms.

针对本条考纲陈述关键术语的主动回忆练习。

Prototype render · grounded in the IB CS 2027 subject guide and the Hodder and Oxford IB CS 2027 texts for A1.1.8 · not yet wired to live routes