AP Computer Science Principles · 鼎睿学苑

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%。

17–22% of AP Exam MCQ占 AP 选择题 17–22%Big Idea 2 · DAT大概念 2 · DAT4 Topics4 个小节

Binary Numbers

二进制数

Must know
  • 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 的幂。比较二进制数时,将最右位对齐后从左向右比较,或先把两数都转换为十进制。

Worked Example: Convert and compare例题:转换与比较

Convert decimal 13 to binary. Then order binary 1011, 1101, and 01111 from least to greatest.

将十进制 13 转换为二进制。然后将二进制数 1011、1101 和 01111 从小到大排列。

  1. 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.
  2. Convert 1011: 8 + 2 + 1 = 11. Convert 1101: 8 + 4 + 1 = 13.
  3. Convert 01111: its leading 0 contributes nothing, so 8 + 4 + 2 + 1 = 15.
  4. Answer: 1011 < 1101 < 01111.
  1. 8、4 和 1 相加得到 13。在 8、4、2、1 这几个位值上,数字依次是 1、1、0、1。因此十进制 13 是二进制 1101。
  2. 转换 1011:8 + 2 + 1 = 11。转换 1101:8 + 4 + 1 = 13。
  3. 转换 01111:开头的 0 不贡献数值,因此 8 + 4 + 2 + 1 = 15。
  4. 答案:1011 < 1101 < 01111。
Exam trap

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 当作十进制的一千零一十一,也不要认为写出的位数更多的二进制数一定更大。要使用二进制位值;前导零不会改变数值。

Going deeper

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

数据压缩

Must know
  • 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.

无损压缩保留足够的信息,能够精确还原原始数据。有损压缩放弃精确还原,以获得可能更大的压缩幅度。考试中,先确定题目最重视什么,再比较各方案的数据大小和还原能力是否符合需求。

Worked Example: Choosing a compression method例题:选择压缩方法

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 位。一个存档需要精确副本;一个预览要求传输的数据尽可能小,且可以接受近似图像。

  1. For the archive, exact reconstruction is required. The lossless method guarantees it; the lossy method does not.
  2. For the preview, compare sizes: 300 bits is smaller than 700 bits. The preview can tolerate the lossy approximation.
  3. Answer: use lossless for the archive and lossy for the preview.
  1. 存档要求精确还原。无损方法能保证这一点,有损方法则不能。
  2. 预览需要比较大小:300 位小于 700 位。预览可以接受有损压缩产生的近似结果。
  3. 答案:存档使用无损压缩,预览使用有损压缩。
Exam trap

“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.

考试陷阱

“结果最小的方案总是最好”是错误的。有损结果可能更小,但不能保证精确还原。要检查任务是否要求找回原始数据。

Going deeper

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

从数据中提取信息

Must know
  • 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.

数据集的大小会影响可获得的信息,但仅增加数据量无法消除由数据类型或来源造成的偏差。能处理哪些数据也取决于使用者和工具。单台计算机可能难以处理大型数据集,因此可能需要并行系统。可扩展的系统需要有足够的计算能力,以应对数据需求变化时的处理和存储。

Worked Example: Connecting two data sources例题:连接两个数据来源

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”表示同一个地点。

  1. Combine the sources by date. The resulting pairs are (20, 10), (25, 15), and (30, 20).
  2. Make the equivalent location entries uniform, for example by replacing “NORTH” with “North.” This cleaning does not change their meaning.
  3. In these records, higher temperatures appear with higher sales. This is a correlation, not proof that temperature caused the sales changes.
  4. Answer: The combined data show a relationship in these records. More research is needed before claiming a causal relationship.
  1. 按日期合并两个来源。得到的数据对为 (20, 10)、(25, 15) 和 (30, 20)。
  2. 将含义相同的位置条目统一,例如把“NORTH”替换为“North”。这种清洗不会改变其含义。
  3. 在这些记录中,较高的气温对应较高的销量。这是相关性,并不能证明气温导致了销量变化。
  4. 答案:合并后的数据表明这些记录中存在关联。要声称存在因果关系,还需要进一步研究。
Exam trap The wrong answer is “the correlation proves that temperature caused sales to rise.” The data show a pattern, but they do not establish cause. Also, adding more records from the same biased source does not automatically remove bias.
考试陷阱 错误答案是“相关性证明气温导致销量上升”。数据展示了一个模式,但没有确立因果关系。另外,从同一个有偏差的来源增加记录,也不会自动消除偏差。
Going deeper Check what a change actually affects. Standardizing equivalent location labels cleans data without changing their meaning. Deleting an image’s creation-date metadata leaves the image unchanged, but removes information that could help organize or find it. Neither action fills missing values or makes invalid entries valid.
深入理解 要检查一项修改实际影响了什么。统一含义相同的地点标签是在不改变含义的情况下清洗数据。删除图像的创建日期元数据不会改变图像,却会移除有助于组织或查找图像的信息。这两种操作都不会填补缺失值,也不会使无效条目变为有效。

Using Programs with Data

用程序处理数据

Must know
  • 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.

转换数字化信息的表示形式或内容,可以揭示原始表示中不明显的模式。表格、图示、文字或其他可视化工具可以传达由此获得的洞见。

Worked Example: Filter and transform a list例题:筛选并转换列表

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)
  1. The condition keeps 3 and 5. It excludes -2 and 0 because neither is greater than 0.
  2. The program doubles the kept values and appends them in order, producing [6, 10].
  3. 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.
  1. 条件保留 3 和 5,排除 -2 和 0,因为它们都不大于 0。
  2. 程序将保留的数加倍并按顺序添加,得到 [6, 10]。
  3. 程序将 6 和 10 相加。DISPLAY(doubled) 显示列表内容 6 和 10,随后 DISPLAY(total) 显示 16。可以用表格或图表传达这些结果。
Exam trap

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;对保留的数相乘是改变它,而不是决定是否保留它。

Going deeper

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)、选择压缩方法,或评价基于数据的结论。你还可能需要追踪筛选或合并数据的程序,并判断结果能说明什么。

Pattern 1: Interpret bits For a binary value, add the place values with a 1. For a representation question, check the context: the same bits can represent different kinds of data. (See Topic 2.1.)
套路 1:解释位 遇到二进制数时,把值为 1 的各位对应的位权相加。遇到数据表示问题时,先看上下文:相同的位序列可以表示不同类型的数据。(参见主题 2.1。)
Pattern 2: Choose compression Identify the priority. If exact reconstruction is required, choose lossless compression; if a smaller file matters most and some detail can be lost, consider lossy compression. (See Topic 2.2.)
套路 2:选择压缩方式 先确定优先需求。如果必须完整还原原始数据,选择无损压缩(lossless compression);如果文件尽量小更重要,且可以损失部分细节,可考虑有损压缩(lossy compression)。(参见主题 2.2。)
Pattern 3: Check a data claim Look for a leap from correlation to causation or a biased source. More observations alone do not fix a biased collection method; check what additional data or research is needed. (See Topic 2.3.)
套路 3:检验数据结论 留意是否把相关关系(correlation)直接当成因果关系,或忽略了数据来源的偏差。单纯增加观测数量不能消除收集方法的偏差;应考虑还需要什么数据或研究。(参见主题 2.3。)
Pattern 4: Trace data processing Track which values pass a filter and how each passing value changes an accumulator. Distinguish filtering from transforming every value, then connect the result to the question asked. (See Topic 2.4.)
套路 4:追踪数据处理 逐个检查哪些值通过筛选(filtering),以及这些值如何改变累加变量。区分筛选和对每个值进行转换(transformation),再把结果与题目要求联系起来。(参见主题 2.4。)

Flashcards, Click to Flip

闪卡(点击翻面)

What are a bit and a byte?什么是位和字节?
A bit is a 0 or 1; a byte is 8 bits. Groups of bits can represent numbers, characters, or colors.位(bit)是 0 或 1;字节(byte)由 8 位组成。位的组合可以表示数字、字符或颜色。
How do you interpret a binary number?如何解释一个二进制数?
Add the powers of 2 corresponding to its 1 bits, starting with 1 at the rightmost position.把值为 1 的各位对应的 2 的幂相加;最右位的位权是 1。
Why can the same bits have different meanings?为什么相同的位序列可以有不同含义?
Their interpretation depends on context, such as whether they encode a number, character, or color.位序列的解释取决于上下文,例如它编码的是数字、字符还是颜色。
How can analog data be represented digitally?如何用数字方式表示模拟数据?
Sampling measures a smoothly changing signal at regular intervals, producing a digital approximation.采样(sampling)以固定时间间隔测量连续变化的信号,得到数字近似表示。
What errors can limited numeric representations cause?数值表示范围有限可能导致什么错误?
Fixed-size integers can overflow; limited representations of real numbers can cause rounding errors. Exam reference sheet integers are limited by memory rather than a fixed bit count.固定位数的整数可能发生溢出(overflow);实数表示精度有限可能导致舍入误差(rounding error)。考试参考表中的整数不受固定的位数限制,而受内存限制。
How do lossless and lossy compression differ?无损压缩和有损压缩有什么区别?
Lossless compression permits exact reconstruction; lossy compression reconstructs an approximation and usually reduces size more.无损压缩(lossless compression)允许完整还原原始数据;有损压缩(lossy compression)只能还原近似数据,通常能更大幅度地减小文件。
What affects how much compression reduces data size?哪些因素影响压缩能减小多少数据量?
The original representation's redundancy and the algorithm both matter. Fewer bits do not necessarily mean less information.原始表示中的冗余程度和所用算法都会影响压缩效果。位数更少不一定意味着信息更少。
Does correlation establish causation?相关关系能证明因果关系吗?
No. A correlation identifies a relationship between variables, but further research is needed to investigate causation.不能。相关关系(correlation)表明变量之间存在联系,但需要进一步研究才能探究因果关系。
What is metadata used for?元数据有什么用途?
Metadata are data about data, such as an image's creation date. They help find and organize data; changing them does not change the primary data.元数据(metadata)是关于数据的数据,例如图像的创建日期。它有助于查找和组织数据;修改元数据不会改变主要数据。
What are common data-processing challenges?数据处理中有哪些常见挑战?
Data can be incomplete, invalid, inconsistent, or biased. Cleaning makes equivalent entries uniform without changing their meaning, but more data alone do not remove bias.数据可能不完整、无效、不一致或存在偏差。数据清洗(data cleaning)会统一含义相同的记录而不改变其含义,但单纯增加数据不能消除偏差。
Why do scalability and multiple data sources matter?为什么可扩展性和多个数据源很重要?
A conclusion may require combining sources. Large data sets may need scalable storage and processing, including parallel systems.得出结论可能需要合并多个数据源。大型数据集可能需要可扩展的存储和处理能力,包括并行系统(parallel systems)。
How can programs reveal patterns in data?程序如何揭示数据中的规律?
Programs can iteratively filter, transform, combine, cluster, classify, and visualize data. Spreadsheets and search tools also help users find information.程序可以反复筛选、转换、合并、聚类(clustering)、分类(classification)和可视化数据。电子表格和搜索工具也有助于查找信息。

Unit 2, Practice Quiz

单元 2:练习小测

1. What decimal value is represented by the binary number 101101?1. 二进制数(binary number)101101 对应的十进制值是多少?
41
53
45
37
Correct! The 1 bits have place values 32, 8, 4, and 1, which add to 45.正确!值为 1 的各位对应的位权是 32、8、4 和 1,相加得到 45。
Start at the right with place value 1 and double each place as you move left. Add only the place values whose bits are 1.从最右位的位权 1 开始,每向左一位就翻倍。只将值为 1 的位对应的位权相加。
2. A hospital must compress records and later reconstruct every original bit exactly. Which method should it choose?2. 医院需要压缩记录,并在之后精确还原原始数据的每一位。应选择哪种方法?
Lossy compression有损压缩(lossy compression)
Sampling at longer intervals以更长的时间间隔采样
Deleting repeated records删除重复记录
Lossless compression无损压缩(lossless compression)
Correct! Lossless compression guarantees reconstruction of the original data.正确!无损压缩保证能够还原原始数据。
The requirement is exact reconstruction, not just a smaller file. Lossy compression permits only an approximation, and deleting records does not preserve the original.题目的要求是精确还原,而不只是缩小文件。有损压缩只能还原近似数据,删除记录也无法保留原始数据。
3. A study finds that students who sleep more tend to have higher grades. Which conclusion is supported by this finding alone?3. 一项研究发现,睡眠时间较长的学生往往成绩更高。仅凭这一发现,可以得出什么结论?
Sleep and grades are correlated in the study, but causation is not established.研究中的睡眠时间与成绩相关,但因果关系尚未得到证实。
More sleep definitely causes higher grades.睡眠时间增加一定会导致成绩提高。
Higher grades definitely cause more sleep.成绩提高一定会导致睡眠时间增加。
Sleep and grades are unrelated.睡眠时间与成绩没有关系。
Correct! The observed association is a correlation, not proof of a causal direction.正确!观察到的联系是相关关系(correlation),不能证明因果关系及其方向。
An observed association does not by itself establish that either variable causes the other. Additional research is needed.观察到两个变量有关联,并不能单独证明任何一个变量导致了另一个变量的变化。还需要进一步研究。
4. A school surveys only members of its chess club about which school club is most popular. What is the main concern if it wants to represent all students?4. 学校只调查国际象棋社团成员,以确定全校最受欢迎的社团。如果调查要代表全体学生,主要问题是什么?
The survey must be unbiased if every club member responds.只要所有社团成员都回答,调查就一定没有偏差。
The source is biased toward chess club members.数据来源偏向国际象棋社团成员。
Collecting more responses from the same club necessarily removes the bias.从同一社团收集更多回答必然能消除偏差。
Cleaning capitalization will make the sample representative.统一大小写就能使样本具有代表性。
Correct! Chess club members may not represent the preferences of all students.正确!国际象棋社团成员的偏好可能不能代表全体学生。
Consider who was excluded. More responses from the same biased source or cleaning the entries does not ensure a representative sample.要考虑哪些人被排除在调查之外。从同一个有偏差的数据来源收集更多回答,或清洗记录,都不能保证样本具有代表性。
5. What value does the program display?5. 程序显示什么值?
values ← [3, -2, 6, 0, 5]
total ← 0
FOR EACH value IN values {
  IF(value > 0) {
    total ← total + value
  }
}
DISPLAY(total)
12
14
15
5
Correct! The program adds the positive values 3, 6, and 5, giving 14.正确!程序将正数 3、6 和 5 相加,得到 14。
Check the condition for each list item. The negative value and zero do not pass the filter, so neither is added.逐项检查条件。负数和 0 都不满足筛选条件,因此不会被加到总和中。
6. A researcher wants to see how average daily temperature changes across months. Which approach best helps reveal the trend?6. 研究者想观察每日平均气温随月份的变化。哪种方法最有助于揭示趋势?
Delete the dates and display the temperatures in arbitrary order.删除日期,按任意顺序显示温度。
Keep only the highest temperature and discard the rest.只保留最高温度,丢弃其余数据。
Replace every reading with the same constant.将每个读数都替换成同一个常数。
Group the readings by month and graph each month's average.按月份分组,并绘制每个月平均值的图表。
Correct! Grouping and averaging by month, then graphing, makes changes over time easier to see.正确!按月份分组、计算平均值并绘图,可以更容易地看出随时间的变化。
The result must retain the month and summarize temperatures for each month. Deleting dates or discarding most readings prevents that comparison.结果必须保留月份信息,并汇总每个月的温度。删除日期或丢弃大部分读数会妨碍这种比较。

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 道题的练习集,检验二进制推理、压缩方法选择和数据分析能力。继续下一题前,请先查看解析。

Practice Problems →练习题 →

鼎睿学苑 · Dingrui Scholars

AP Computer Science Principles, Unit 2: Data · 2026 Edition

AP 计算机科学原理,单元 2:数据 · 2026 版