Unit 2: Data
单元 2:数据
Explore how computers represent and compress data, then use programs to turn data into information. Big Idea 2 accounts for 17–22% of the MCQ exam.
学习计算机如何表示和压缩数据,再用程序从数据中提取信息。大概念 2 约占选择题考试的 17–22%。
Binary Numbers
二进制数
- Data values can be stored in variables, lists, or standalone constants and passed into or out of procedures. At the lowest level, digital data consists of bits, each 0 or 1; 8 bits make a byte. (DAT-1.A.1, DAT-1.A.2, DAT-1.A.3, DAT-1.A.4)
- Abstraction reduces complexity by hiding irrelevant details and grouping useful ones. Groups of bits can represent numbers, characters, or colors, and the same bits can mean different things in different contexts. (DAT-1.A.5, DAT-1.A.6, DAT-1.A.7)
- Analog data changes smoothly. Digital sampling measures it at regular intervals and stores an approximation using bits. (DAT-1.A.8, DAT-1.A.9, DAT-1.A.10)
- Fixed-bit integers have a limited range and can overflow. In the exam reference sheet language, integer size is limited by available memory rather than a fixed bit count. (DAT-1.B.1, DAT-1.B.2)
- Fixed-bit real number representations have limited range and precision, so calculations can produce round-off or other errors. (DAT-1.B.3)
- Binary uses 0 and 1; decimal uses 0 through 9. To convert or compare binary numbers, use place values: from right to left, the positions are powers of 2 starting with 2 to the power 0. (DAT-1.C.1, DAT-1.C.2, DAT-1.C.3, DAT-1.C.4, DAT-1.C.5)
- 数据值可以存储在变量、列表或独立常量中,也可以作为输入传给过程,或从过程输出。数字数据在最底层由位(bit)组成,每位是 0 或 1;8 位组成一个字节(byte)。(DAT-1.A.1, DAT-1.A.2, DAT-1.A.3, DAT-1.A.4)
- 抽象(abstraction)通过隐藏无关细节、组合有用细节来降低复杂度。位组可以表示数字、字符或颜色;相同的位在不同语境中可以有不同含义。(DAT-1.A.5, DAT-1.A.6, DAT-1.A.7)
- 模拟数据(analog data)平滑变化。数字采样(sampling)按固定间隔测量它,并用位存储近似值。(DAT-1.A.8, DAT-1.A.9, DAT-1.A.10)
- 固定位数的整数取值范围有限,可能发生溢出(overflow)。考试参考表语言中的整数大小则受可用内存限制,而非固定位数限制。(DAT-1.B.1, DAT-1.B.2)
- 固定位数的实数表示,其范围和精度有限,因此计算可能产生舍入误差(round-off error)或其他错误。(DAT-1.B.3)
- 二进制只用 0 和 1;十进制使用 0 到 9。转换或比较二进制数时要看位值(place value):从右往左依次是 2 的幂,最右位从 2 的 0 次方开始。(DAT-1.C.1, DAT-1.C.2, DAT-1.C.3, DAT-1.C.4, DAT-1.C.5)
Bits, meaning, and abstraction
位、含义与抽象
A bit is a binary digit. A program can work with a value in a variable, list, or constant, or pass it into or out of a procedure without dealing with its individual bits. This is abstraction: focus on the useful idea while hiding details that do not matter for the task.
位是二进制数字。程序可以使用变量、列表或常量中的值,也可以将值传入或传出过程,而不必处理其中的每一位。这就是抽象:关注有用的概念,隐藏与当前任务无关的细节。
Computing devices group bits to represent data such as numbers, characters, and colors. The bit sequence alone does not determine its meaning. The context tells us how to interpret it, and a program can translate the internal representation into a form people understand.
计算设备将位组合起来表示数字、字符和颜色等数据。仅凭位序列本身无法确定其含义,需要根据语境解释;程序可以将内部表示转换成人们易于理解的形式。
Analog and digital data
模拟数据与数字数据
Analog values change smoothly over time rather than in discrete intervals. Examples include the pitch or volume of music and a sprinter's position during a race. Sampling measures an analog signal at regular intervals; each measurement is represented using bits. The resulting digital data approximates the analog data, which is an example of abstraction.
模拟值随时间平滑变化,而不是按离散间隔变化。例如,音乐的音高或音量,以及短跑运动员在比赛中的位置。采样按固定间隔测量模拟信号,并用位表示每次测量值。得到的数字数据是对模拟数据的近似,这也是抽象的例子。
Number bases and place value
数制与位值
Decimal is base 10 and uses digits 0 through 9. Binary is base 2 and uses only 0 and 1. In either base, number positions start at 0 on the right. A digit contributes its value multiplied by the base raised to that position. Binary place values from right to left are 1, 2, 4, 8, and so on.
十进制是以 10 为底的数制,使用数字 0 到 9。二进制是以 2 为底的数制,只使用 0 和 1。在这两种数制中,位置都从右边的 0 开始编号。每位对数值的贡献等于该位数字乘以底数的相应位置次幂。二进制从右到左的位值依次为 1、2、4、8,等等。
For an exam conversion, multiply each binary digit by its place value and add. To convert a positive decimal integer to binary, select powers of 2 that add to the integer. To compare binary numbers, align their rightmost digits and compare from the left, or convert both to decimal.
考试中转换二进制数时,将每位数字乘以其位值再相加。将正十进制整数转换为二进制时,选择相加后等于该整数的 2 的幂。比较二进制数时,将最右位对齐后从左向右比较,或先把两数都转换为十进制。
Convert decimal 13 to binary. Then order binary 1011, 1101, and 01111 from least to greatest.
将十进制 13 转换为二进制。然后将二进制数 1011、1101 和 01111 从小到大排列。
- The powers 8, 4, and 1 add to 13. In the 8, 4, 2, and 1 places, the bits are 1, 1, 0, and 1. So decimal 13 is binary 1101.
- Convert 1011: 8 + 2 + 1 = 11. Convert 1101: 8 + 4 + 1 = 13.
- Convert 01111: its leading 0 contributes nothing, so 8 + 4 + 2 + 1 = 15.
- Answer: 1011 < 1101 < 01111.
- 8、4 和 1 相加得到 13。在 8、4、2、1 这几个位值上,数字依次是 1、1、0、1。因此十进制 13 是二进制 1101。
- 转换 1011:8 + 2 + 1 = 11。转换 1101:8 + 4 + 1 = 13。
- 转换 01111:开头的 0 不贡献数值,因此 8 + 4 + 2 + 1 = 15。
- 答案:1011 < 1101 < 01111。
Do not read 1011 as decimal one thousand eleven, and do not assume the binary number with more written digits is always larger. Use binary place values; leading zeros do not change the value.
不要把二进制 1011 当作十进制的一千零一十一,也不要认为写出的位数更多的二进制数一定更大。要使用二进制位值;前导零不会改变数值。
In many languages, fixed-bit integers have a limited range, so an operation can overflow. The exam reference sheet language instead limits integer size by the computer's memory. Real numbers also have limits: some are stored only approximately, so even a valid calculation can have round-off error. Do not assume that every stored real value is exact.
在许多语言中,固定位数的整数取值范围有限,因此运算可能溢出。考试参考表语言中的整数大小则受计算机内存限制。实数也有表示限制:有些实数只能近似存储,因此即使运算本身有效,也可能产生舍入误差。不要假设存储的每个实数值都精确无误。
Data Compression
数据压缩
- Compression can reduce the bits stored or transmitted; fewer bits do not necessarily mean less information. (DAT-1.D.1, DAT-1.D.2)
- The size reduction depends on redundancy in the original representation and on the algorithm used. (DAT-1.D.3)
- Lossless compression usually reduces the number of bits and guarantees exact reconstruction. Lossy compression can reduce bits significantly but reconstructs only an approximation. (DAT-1.D.4, DAT-1.D.5)
- Lossy compression usually reduces size more than lossless compression. (DAT-1.D.6)
- Choose lossless when exact reconstruction or quality is most important; choose lossy when minimizing size or transmission time is most important. (DAT-1.D.7, DAT-1.D.8)
- 数据压缩(data compression)可以减少存储或传输的位数;位数更少不一定意味着信息更少。(DAT-1.D.1, DAT-1.D.2)
- 压缩后缩小的程度取决于原始表示中的冗余(redundancy)和所用算法。(DAT-1.D.3)
- 无损压缩(lossless compression)通常能减少位数,并保证精确还原原始数据。有损压缩(lossy compression)可以大幅减少位数,但只能还原出原始数据的近似版本。(DAT-1.D.4, DAT-1.D.5)
- 有损压缩通常比无损压缩更能缩小数据大小。(DAT-1.D.6)
- 最重视精确还原或质量时,选择无损压缩;最重视缩小数据大小或缩短传输时间时,选择有损压缩。(DAT-1.D.7, DAT-1.D.8)
How compression saves space
压缩如何节省空间
A representation can contain redundancy, such as repeated data. A compression algorithm can use that redundancy to represent the data with fewer bits. The result depends on both the original data and the algorithm.
一种数据表示可能包含冗余,例如重复的数据。压缩算法可以利用这些冗余,用更少的位表示数据。压缩结果既取决于原始数据,也取决于算法。
Compare the options
比较压缩方案
Lossless compression preserves enough information to reconstruct the original exactly. Lossy compression gives up exact reconstruction to achieve a potentially greater reduction. On an exam, identify what the situation values most, then compare that need with the size and reconstruction offered by each option.
无损压缩保留足够的信息,能够精确还原原始数据。有损压缩放弃精确还原,以获得可能更大的压缩幅度。考试中,先确定题目最重视什么,再比较各方案的数据大小和还原能力是否符合需求。
An image contains 1,000 bits. For this image, a lossless method produces 700 bits and a lossy method produces 300 bits. An archive needs an exact copy. A preview needs the smallest transmission and can tolerate an approximation.
一张图像包含 1,000 位。对这张图像,无损方法生成 700 位,有损方法生成 300 位。一个存档需要精确副本;一个预览要求传输的数据尽可能小,且可以接受近似图像。
- For the archive, exact reconstruction is required. The lossless method guarantees it; the lossy method does not.
- For the preview, compare sizes: 300 bits is smaller than 700 bits. The preview can tolerate the lossy approximation.
- Answer: use lossless for the archive and lossy for the preview.
- 存档要求精确还原。无损方法能保证这一点,有损方法则不能。
- 预览需要比较大小:300 位小于 700 位。预览可以接受有损压缩产生的近似结果。
- 答案:存档使用无损压缩,预览使用有损压缩。
“The smallest result is always best” is wrong. A lossy result may be smaller, but it cannot guarantee exact reconstruction. Check whether the task requires the original data back.
“结果最小的方案总是最好”是错误的。有损结果可能更小,但不能保证精确还原。要检查任务是否要求找回原始数据。
Lossless does not mean “no compression.” It can use fewer bits while preserving all the information needed to reconstruct the original. Also, do not assume a fixed reduction: different data and algorithms can produce different results, and lossless compression does not always make data smaller.
无损不等于“没有压缩”。无损压缩可以减少位数,同时保留还原原始数据所需的全部信息。也不要假设压缩幅度固定:不同的数据和算法可能产生不同结果,而且无损压缩并非总能缩小数据。
Extracting Information from Data
从数据中提取信息
- Information consists of facts and patterns extracted from data. Data can reveal trends and connections and help address problems. (DAT-2.A.1, DAT-2.A.2)
- Correlation does not necessarily mean causation. Further research may be needed, and a conclusion may require data from multiple sources. (DAT-2.A.3, DAT-2.A.4)
- Metadata are data about data, such as an image’s creation date or file size. Changing or deleting metadata does not change the primary data. Metadata help structure, organize, find, manage, and use data. (DAT-2.B.1, DAT-2.B.2, DAT-2.B.3, DAT-2.B.4, DAT-2.B.5)
- Processing depends on users and tools. Any size data set can have missing, invalid, or nonuniform data and may need cleaning or combining with other sources. Cleaning makes data uniform without changing meaning. (DAT-2.C.1, DAT-2.C.2, DAT-2.C.3, DAT-2.C.4)
- The type or source of data can introduce bias. Collecting more data alone does not eliminate it. (DAT-2.C.5)
- Data set size affects what information can be extracted. Large data sets may require parallel systems; scalability and computational capacity affect processing and storage. (DAT-2.C.6, DAT-2.C.7, DAT-2.C.8)
- 信息(information)是从数据中提取的事实和模式。数据可以揭示趋势和联系,并帮助解决问题。(DAT-2.A.1, DAT-2.A.2)
- 相关性(correlation)不一定意味着因果关系(causation)。可能需要进一步研究,得出结论也可能需要结合多个来源的数据。(DAT-2.A.3, DAT-2.A.4)
- 元数据(metadata)是关于数据的数据,例如图像的创建日期或文件大小。修改或删除元数据不会改变原始数据(primary data)。元数据有助于构建数据结构,以及组织、查找、管理和使用数据。(DAT-2.B.1, DAT-2.B.2, DAT-2.B.3, DAT-2.B.4, DAT-2.B.5)
- 处理数据的能力取决于使用者和工具。任何规模的数据集都可能存在缺失、无效或不统一的数据,也可能需要清洗或与其他来源的数据合并。数据清洗(cleaning)使数据统一,但不改变其含义。(DAT-2.C.1, DAT-2.C.2, DAT-2.C.3, DAT-2.C.4)
- 数据的类型或来源可能引入偏差(bias)。仅增加数据量不能消除偏差。(DAT-2.C.5)
- 数据集的大小会影响可提取的信息。大型数据集可能需要并行系统(parallel systems);系统的可扩展性(scalability)和计算能力会影响数据的处理和存储。(DAT-2.C.6, DAT-2.C.7, DAT-2.C.8)
From data to information
从数据到信息
Processing data can reveal facts and patterns that become information. People can use those patterns to identify trends, connect observations, address problems, and create new knowledge. A single source may not contain everything needed for a conclusion, so combining sources can help.
处理数据可以揭示事实和模式,从而形成信息。人们可以利用这些模式识别趋势、联系观察结果、解决问题并创造新知识。单一来源可能不包含得出结论所需的全部数据,因此合并多个来源可能有帮助。
A correlation is a pattern in which variables are related. Even if digitally processed data show that two variables change together, the pattern alone does not establish that one causes the other. Further research is needed to understand the relationship.
相关性是变量之间存在联系的模式。即使数字化处理后的数据表明两个变量一起变化,这一模式本身也不能证明其中一个导致了另一个。需要进一步研究才能理解它们之间的关系。
What metadata tell us
元数据能告诉我们什么
For an image, the image itself is the primary data. Its creation date and file size are examples of metadata. Metadata provide context that can make a data set more useful: for example, creation dates can help organize and find images. Changing or deleting a creation date in the metadata does not change the image itself.
对于一张图像,图像本身是原始数据,创建日期和文件大小则是元数据的例子。元数据提供背景信息,使数据集更有效地被使用:例如,创建日期可以帮助组织和查找图像。修改或删除元数据中的创建日期不会改变图像本身。
Processing challenges
数据处理的挑战
Any data set can contain incomplete or invalid entries. Open fields can also produce different abbreviations, spellings, or capitalization for the same thing. Cleaning can replace equivalent forms with one consistent form without changing their meaning. Data from different sources may also need to be combined.
任何数据集都可能包含不完整或无效的条目。开放输入字段(open field)还可能让用户对同一事物使用不同的缩写、拼写或大小写。清洗时可以用统一形式替换含义相同的写法,而不改变其含义。来自不同来源的数据也可能需要合并。
The size of a data set affects the information available, but more data alone cannot fix bias caused by the type or source of the data. What can be processed also depends on users and their tools. A large data set may be difficult for one computer to process and may require parallel systems. A scalable system must have enough computational capacity for the processing and storage needed as data demands change.
数据集的大小会影响可获得的信息,但仅增加数据量无法消除由数据类型或来源造成的偏差。能处理哪些数据也取决于使用者和工具。单台计算机可能难以处理大型数据集,因此可能需要并行系统。可扩展的系统需要有足够的计算能力,以应对数据需求变化时的处理和存储。
A student wants to investigate whether temperature is related to cold-drink sales. A weather source records temperatures of 20, 25, and 30 degrees on three dates. A store source records sales of 10, 15, and 20 drinks on those same dates. The store’s location field uses both “North” and “NORTH” for the same location.
一名学生想研究气温是否与冷饮销量有关。天气数据源记录了三个日期的气温,分别为 20、25 和 30 度。商店数据源记录了相同日期的销量,分别为 10、15 和 20 杯。商店的位置字段用“North”和“NORTH”表示同一个地点。
- Combine the sources by date. The resulting pairs are (20, 10), (25, 15), and (30, 20).
- Make the equivalent location entries uniform, for example by replacing “NORTH” with “North.” This cleaning does not change their meaning.
- In these records, higher temperatures appear with higher sales. This is a correlation, not proof that temperature caused the sales changes.
- Answer: The combined data show a relationship in these records. More research is needed before claiming a causal relationship.
- 按日期合并两个来源。得到的数据对为 (20, 10)、(25, 15) 和 (30, 20)。
- 将含义相同的位置条目统一,例如把“NORTH”替换为“North”。这种清洗不会改变其含义。
- 在这些记录中,较高的气温对应较高的销量。这是相关性,并不能证明气温导致了销量变化。
- 答案:合并后的数据表明这些记录中存在关联。要声称存在因果关系,还需要进一步研究。
Using Programs with Data
用程序处理数据
- Programs process data to acquire information. Search tools efficiently find information; filtering helps find information and recognize patterns. (DAT-2.D.1, DAT-2.D.3, DAT-2.D.4)
- Spreadsheets help organize information and find trends. Tables, diagrams, text, and other visuals communicate insights from data. (DAT-2.D.2, DAT-2.D.5)
- Programs can transform every element, filter data, combine or compare values, and visualize a data set. (DAT-2.D.6)
- Users interact with programs and repeat processing to gain insight. Filtering and cleaning digital data can support this process. (DAT-2.E.1, DAT-2.E.2)
- Combining sources, clustering, and classifying data are parts of gaining knowledge. Translating or transforming digital information can reveal patterns. (DAT-2.E.3, DAT-2.E.4, DAT-2.E.5)
- 程序处理数据以获取信息。搜索工具(search tools)可高效查找信息;筛选(filtering)有助于查找信息和识别模式。 (DAT-2.D.1, DAT-2.D.3, DAT-2.D.4)
- 电子表格(spreadsheet)有助于整理信息和发现趋势。表格、图示、文字及其他可视化工具可以传达从数据中获得的洞见。 (DAT-2.D.2, DAT-2.D.5)
- 程序可以转换数据集中的每个元素、筛选数据、合并或比较数值,以及可视化数据集。 (DAT-2.D.6)
- 用户与程序交互并反复处理数据,以获得洞见。筛选和清洗(cleaning)数字数据可以帮助这一过程。 (DAT-2.E.1, DAT-2.E.2)
- 合并数据来源、聚类(clustering)和分类(classifying)是获取知识的过程中的一部分。转换数字化信息的表示形式或内容可以揭示模式。 (DAT-2.E.3, DAT-2.E.4, DAT-2.E.5)
From data to information
从数据到信息
A program can process a data set to extract information. Search tools help find information efficiently. Filtering keeps data that meet a condition, making relevant information and patterns easier to find. A spreadsheet can organize information and help reveal trends.
程序可以处理数据集,从中提取信息。搜索工具有助于高效查找信息。筛选保留符合条件的数据,使相关信息和模式更容易被发现。电子表格可以整理信息并帮助发现趋势。
On an exam, identify what each operation does to the data: transforming changes values, filtering selects values, and combining or comparing summarizes or contrasts them. A chart or graph displays results so people can communicate an insight.
考试时,要辨认每个操作对数据的作用:转换改变数值,筛选选出数值,合并或比较则汇总或对照数值。图表可以展示结果,帮助人们传达洞见。
Refining an investigation
逐步完善探究
Processing is often iterative and interactive: a user examines a result, changes a filter or transformation, and examines the new result. Cleaning data can make it more useful for the investigation. Combining data sources, clustering similar data, or classifying data into categories can also help users gain knowledge.
数据处理通常是迭代且交互的:用户查看结果,修改筛选条件或转换方式,再查看新结果。清洗数据可以使数据更适合当前探究。合并数据来源、将相似数据聚类,或将数据分入不同类别,也能帮助用户获得知识。
Translating or transforming digitally represented information can reveal patterns that were not obvious in the original representation. A table, diagram, text, or another visual tool can communicate the resulting insight.
转换数字化信息的表示形式或内容,可以揭示原始表示中不明显的模式。表格、图示、文字或其他可视化工具可以传达由此获得的洞见。
A program keeps the positive numbers in a list, doubles each one, and adds the doubled values. What are the resulting list and total?
程序保留列表中的正数,将每个正数加倍,然后把加倍后的数相加。结果列表和总和分别是什么?
numbers ← [-2, 3, 0, 5] doubled ← [] total ← 0 FOR EACH number IN numbers { IF (number > 0) { value ← number * 2 APPEND(doubled, value) total ← total + value } } DISPLAY(doubled) DISPLAY(total)
- The condition keeps 3 and 5. It excludes -2 and 0 because neither is greater than 0.
- The program doubles the kept values and appends them in order, producing [6, 10].
- It adds 6 and 10. DISPLAY(doubled) shows the list contents 6 and 10, then DISPLAY(total) shows 16. A table or chart could communicate these results.
- 条件保留 3 和 5,排除 -2 和 0,因为它们都不大于 0。
- 程序将保留的数加倍并按顺序添加,得到 [6, 10]。
- 程序将 6 和 10 相加。DISPLAY(doubled) 显示列表内容 6 和 10,随后 DISPLAY(total) 显示 16。可以用表格或图表传达这些结果。
Do not say the filter keeps 0 or that doubling alone is filtering. The condition number > 0 excludes 0; multiplying a kept value changes it rather than deciding whether to keep it.
不要误认为筛选会保留 0,也不要把加倍本身当作筛选。条件 number > 0 排除 0;对保留的数相乘是改变它,而不是决定是否保留它。
If no number is positive, the example produces an empty list and a total of 0. A user can change the condition and rerun the program to investigate a different question. Any pattern in the result applies to the data selected by that condition, not automatically to the entire original list.
如果没有正数,例题会得到空列表和总和 0。用户可以修改条件并重新运行程序,探究不同的问题。结果中的模式适用于该条件选出的数据,不能自动推广到整个原始列表。
Trace the pseudocode one line at a time
逐行追踪伪代码
Unit 2 MCQ Patterns That Show Up Every Year
单元 2 每年都会出现的选择题套路
Questions may ask you to convert binary numbers, choose a compression method, or evaluate a claim based on data. You may also trace a program that filters or combines values and identify what its results reveal.
选择题可能要求你转换二进制数(binary number)、选择压缩方法,或评价基于数据的结论。你还可能需要追踪筛选或合并数据的程序,并判断结果能说明什么。
Flashcards, Click to Flip
闪卡(点击翻面)
Unit 2, Practice Quiz
单元 2:练习小测
values ← [3, -2, 6, 0, 5] total ← 0 FOR EACH value IN values { IF(value > 0) { total ← total + value } } DISPLAY(total)
AP-Style Practice Problems
AP 风格练习题
Try the 15-question practice set to test binary reasoning, compression choices, and data analysis. Review each explanation before moving on.
完成 15 道题的练习集,检验二进制推理、压缩方法选择和数据分析能力。继续下一题前,请先查看解析。
鼎睿学苑 · Dingrui Scholars
AP Computer Science Principles, Unit 2: Data · 2026 Edition
AP 计算机科学原理,单元 2:数据 · 2026 版