跳到主要内容

数据

AP 计算机科学原理 · 知识点 2

本主题的视频课程 打开视频页面
8:13

数据

播放一首歌。到达你耳朵的是波——平滑、连续,从不从一个值跳到下一个值。但你的手机无法存储波。它只能…

英语旁白 · 英中内嵌字幕

2.1

二进制数

教学大纲

持久理解 (DAT-1): 计算机在内部表示数据的方式与向用户解释和显示数据的方式不同。程序用于将数据转换为人们更容易理解的表示形式。

学习目标 DAT-1.A: 解释如何使用位(bits)来表示数据。[技能 3.C]

  • DAT-1.A.1 数据值可以存储在变量、项目列表或独立常量中,并可以作为输入传递给过程(或从过程中输出)。
  • DAT-1.A.2 计算设备以数字方式表示数据,这意味着任何值的最低级组件都是位(bit)。
  • DAT-1.A.3 位(Bit) 是 二进制位(binary digit) 的缩写,其值为 0 或 1。
  • DAT-1.A.4 字节(byte) 由 8 个位组成。
  • DAT-1.A.5 抽象(Abstraction) 是通过聚焦核心思想来降低复杂性的过程。通过隐藏与当前问题无关的细节,并将相关且有用的细节结合起来,抽象降低了复杂性,使人们能够专注于核心概念。
  • DAT-1.A.6 位被分组以表示抽象概念。这些抽象概念包括但不限于数字、字符和颜色。
  • DAT-1.A.7 相同的位序列在不同上下文中可能代表不同类型的数据。
  • DAT-1.A.8 模拟数据的值随时间平滑变化,而非呈离散间隔变化。模拟数据的一些示例包括音乐的音调和音量、画作的颜色,或短跑运动员在比赛中的位置。
  • DAT-1.A.9 使用数字数据来近似现实世界的模拟数据是抽象的一个例子。
  • DAT-1.A.10 可以使用 采样技术(sampling technique) 对模拟数据进行精确的数字近似,即按照称为 样本(samples) 的固定间隔测量模拟信号的值。通过测量样本来确定存储每个样本所需的精确位。

学习目标 DAT-1.B: 解释使用位来表示数据的后果。[技能 1.D]

  • DAT-1.B.1 在许多编程语言中,整数由固定数量的位表示,这限制了整数值及其数学运算的范围。这种限制可能导致溢出或其他错误。
  • DAT-1.B.2 其他编程语言提供了一种抽象机制,使得可表示的整数大小仅受限于计算机内存的大小;考试参考表中所定义的语言即属于这种情况。
  • DAT-1.B.3 在编程语言中,用于表示实数的固定位数限制了这些值的范围及其数学运算;这种限制可能导致舍入误差或其他错误。某些实数在计算机存储中以近似值的形式表示。
    • 排除说明: 实数的具体范围限制不属于本课程及 AP 考试的考查范围。

学习目标 DAT-1.C: 关于二进制数: a. 计算正整数(十进制,基数 10)的二进制(基数 2)等价形式,反之亦然。[技能 2.B] b. 比较和排序二进制数。[技能 2.B]

  • DAT-1.C.1 数制(包括二进制和十进制)用于表示数据。
  • DAT-1.C.2 二进制(基数 2)仅使用零和一的组合。
  • DAT-1.C.3 十进制(基数 10)仅使用数字 $0 - 9$ 的组合。
  • DAT-1.C.4 与十进制类似,位序列中某一位的位置决定了其数值。该数值等于该位的值(0 或 1)乘以其所在位置的位权值。
  • DAT-1.C.5 每个位置的位权值由基数对该位置编号求幂得出。位置编号从最右侧开始为 0,向左每增加一个位置,编号加 1。

来源:College Board AP 课程与考试说明

English
Binary digits on a display — all digital data is ultimately stored as 0s and 1s
Binary digits on a display — all digital data is ultimately stored as 0s and 1s

Computers store everything as bits 位 – each a 0 or 1. A group of 8 bits is a byte 字节. Numbers are stored in binary 二进制 (base 2), where each place is a power of two ($1, 2, 4, 8, 16, \dots$) instead of the powers of ten in decimal 十进制. For example, binary 1011 is $8+2+1=11$.

An 8-bit place-value chart: the 1s sit under the values that add to the number
An 8-bit place-value chart: the 1s sit under the values that add to the number

Worked example. To convert binary 1101 to decimal, write the place values 8 4 2 1 under the bits 1 1 0 1 and add the ones that have a 1: $8+4+0+1=13$. Going the other way, convert 19 to binary by subtracting the largest power of two that fits: $19-16=3$, then $3-2=1$, then $1-1=0$, so the bits sit at the 16, 2, and 1 places $\rightarrow$ 10011 (check: $16+2+1=19$).

Because a computer has a finite number of bits, it can represent only a limited range of values. This causes two effects tested on the exam:

  • Overflow error 溢出错误: a number too large for the available bits cannot be stored correctly.
  • Round-off (rounding) error 舍入错误: many numbers with decimals (real numbers), such as 0.1, can only be approximated, because infinitely many real values must map onto finitely many bit patterns.

Worked example (how many bits?). With $n$ bits there are $2^n$ different patterns; each extra bit doubles the count.

Question Working Answer
Largest whole number in 4 bits 1111 is $8+4+2+1$ 15
Patterns in 3 bits $2^3$ 8
Bits to give 100 students different IDs $2^6 = 64$ is too few; $2^7 = 128$ 7 bits
Patterns gained from 6 bits to 7 bits $128 - 64$ 64 more, twice as many

In a 4-bit system, $15 + 1$ needs 10000, five bits; with only four, the result cannot be stored: an overflow error.

All data – text, images, sound – is ultimately encoded as binary. An image is a grid of pixels 像素, each stored as numbers for its colors; sound is stored as numbers sampled many times per second.

探索

在二进制和十进制之间进行转换

计算机使用二进制(2进制)存储数字。每个位是二的幂;将1位的位值相加即可读取十进制数。

词汇 训练
English 中文 拼音
bits/bɪts/ 位 wèi
byte/baɪt/ 字节 zì jié
binary/ˈbaɪnəri/ 二进制 èr jìn zhì
decimal/ˈdesɪml/ 十进制 shí jìn zhì
Overflow error/ˌəʊvəˈfləʊ ˈerə/ 溢出错误 yì chū cuò wù
Round-off (rounding) error/raʊnd ɒf ˈerə/ 舍入错误 shě rù cuò wù
pixels/ˈpɪkslz/ 像素 xiàng sù
2.2

数据压缩

教学大纲

持久理解 (DAT-1): 计算机在内部表示数据的方式与用户解读和显示数据的方式不同。程序被用来将数据转换为人们更容易理解的表示形式。

学习目标 DAT-1.D: 比较数据压缩算法,以确定在特定情境下哪种算法最佳。[技能 1.D]

  • DAT-1.D.1 数据压缩可以减少传输或存储数据的大小(即比特数)。
  • DAT-1.D.2 比特数较少并不一定意味着信息量减少。
  • DAT-1.D.3 压缩带来的大小缩减程度取决于原始数据表示中的冗余量以及所应用的压缩算法。
  • DAT-1.D.4 无损数据压缩算法通常可以在保证完全重建原始数据的前提下,减少存储或传输的比特数。
  • DAT-1.D.5 有损数据压缩算法可以显著减少存储或传输的比特数,但仅允许重建原始数据的近似值。
  • DAT-1.D.6 有损数据压缩算法通常比无损压缩算法能更大幅度地减少存储或传输的比特数。
  • DAT-1.D.7 在对质量或重建原始数据的能力要求最高的场景中,通常会选择无损压缩算法。
  • DAT-1.D.8 在对最小化数据大小或传输时间要求最高的场景中,通常会选择有损压缩算法。

来源:College Board AP 课程与考试说明

English
Hard-disk platters and head: data compressed and stored as magnetic patterns
Hard-disk platters and head: data compressed and stored as magnetic patterns

Compression 压缩 reduces the number of bits needed to store or send data. Two kinds:

Compression methods: lossless versus lossy, with common examples
Compression methods: lossless versus lossy, with common examples
  • Lossless compression 无损压缩 lets you restore the exact original data (used for text and programs, where every bit matters).
  • Lossy compression 有损压缩 throws away some data to shrink the size further (used for photos, music, video, where a small quality loss is acceptable).

Choosing between them trades size against fidelity: lossless keeps everything but saves less; lossy saves more but loses detail permanently. Prefer lossless when the data must be exact.

Worked example (run-length encoding). A row of image pixels reads WWWWWWBBBWWWW, 13 symbols. Run-length encoding 游程编码 stores each run as a count and a symbol: 6W3B4W, 6 symbols. Decoding gives back exactly WWWWWWBBBWWWW, so this is lossless. It saves space only when the data has long runs: WBWBWB becomes 1W1B1W1B1W1B, twice as long. No lossless method can shrink every possible input.

探索

压缩重复序列

游程编码是一种无损压缩技术:将连续出现的相同符号替换为符号及其计数,从而在不丢失任何信息的情况下缩小数据量。

词汇 训练
English 中文 拼音
Compression/kəmˈpreʃn/ 压缩 yā suō
Lossless compression/ˈlɒsləs kəmˈpreʃn/ 无损压缩 wú sǔn yā suō
Lossy compression/ˈlɒsi kəmˈpreʃn/ 有损压缩 yǒu sǔn yā suō
run-length encoding/rʌn leŋθ enˈkəʊdɪŋ/ 游程编码 yóu chéng biān mǎ
2.3

从数据中提取信息

教学大纲

持久理解 (DAT-2): 程序可用于处理数据,使用户能够发现信息并创造新知识。

学习目标 DAT-2.A: 描述可以从数据中提取什么信息。[技能 5.B]

  • DAT-2.A.1 信息是从数据中提取的事实和模式的集合。
  • DAT-2.A.2 数据提供了识别趋势、建立联系和解决问题的机会。
  • DAT-2.A.3 经过数字处理的数据可能显示变量之间的相关性。在数据中发现的相关性并不一定表明存在因果关系。需要进一步的研究来了解关系的确切性质。
  • DAT-2.A.4 通常,单一来源不包含得出结论所需的数据。可能需要结合多种来源的数据才能得出结论。

学习目标 DAT-2.B: 描述可以从元数据中提取什么信息。[技能 5.B]

  • DAT-2.B.1 元数据是关于数据的数据。例如,数据可能是一张图片,而元数据可能包括创建日期或图片的文件大小。
  • DAT-2.B.2 对元数据进行的更改或删除不会改变主要数据。
  • DAT-2.B.3 元数据用于查找、组织和管理信息。
  • DAT-2.B.4 通过提供附加信息,元数据可以提高数据或数据集的有效利用率。
  • DAT-2.B.5 元数据允许对数据进行结构化和组织。

学习目标 DAT-2.C: 识别与数据处理相关的挑战。[技能 5.D]

  • DAT-2.C.1 处理数据的能力取决于用户及其工具的功能。
  • DAT-2.C.2 无论规模大小,数据集都面临挑战,例如:
    • 需要清理数据
    • 数据不完整
    • 数据无效
    • 需要合并数据来源
  • DAT-2.C.3 根据数据的收集方式,它们可能不一致。例如,如果用户在开放字段中输入数据,他们选择缩写、拼写或大写的习惯可能会因用户而异。
  • DAT-2.C.4 清理数据是一个使数据保持一致而不改变其含义的过程(例如,将所有等效的缩写、拼写和大写形式替换为同一个单词)。
  • DAT-2.C.5 偏见问题通常是由正在收集的数据的类型或来源造成的。仅仅收集更多数据并不能消除偏见。
  • DAT-2.C.6 数据集的大小影响从中可以提取的信息量。
  • DAT-2.C.7 大型数据集难以使用单台计算机进行处理,可能需要并行系统。
  • DAT-2.C.8 当处理数据集时,系统的可扩展性是一个重要的考虑因素,因为系统的计算能力会影响如何处理和存储数据集。

来源:College Board AP 课程与考试说明

English

Data 数据 becomes useful when we extract information 信息 from it – patterns, trends, and answers to questions. Large data sets can reveal correlations a small one cannot, but data must be cleaned (fixing errors and inconsistencies) and often transformed or filtered first. A correlation 相关性 between two things does not prove that one causes the other – a key caution. Metadata 元数据 (data about data, like a photo's date and location) helps organize and search large collections.

Worked example (correlation is not cause). A city's data shows that on days with more ice-cream sales, more people are treated for sunburn. Ice cream does not cause sunburn: both rise on hot, sunny days. The heat is a third factor behind both. To claim a cause you need more than a pattern in the data, such as an experiment that changes one thing and keeps the rest the same.

Filter the rows you need, then count, sum or average them
Filter the rows you need, then count, sum or average them
词汇 训练
English 中文 拼音
Data/ˈdeɪtə/ 数据 shù jù
information/ˌɪnfəˈmeɪʃn/ 信息 xìn xī
correlation/ˌkɒrɪˈleɪʃn/ 相关性 xiāng guān xìng
Metadata/ˌmetəˈdeɪtə/ 元数据 yuán shù jù
2.4

用程序处理数据

教学大纲

持久理解 (DAT-2): 程序可用于处理数据,这使用户能够发现信息并创造新知识。

学习目标 DAT-2.D: 使用程序从数据中提取信息。[技能 2.B]

  • DAT-2.D.1 可以使用程序来处理数据以获取信息。
  • DAT-2.D.2 表格、图表、文本和其他可视化工具可用于传达从数据中获得的见解和知识。
  • DAT-2.D.3 搜索工具对于高效查找信息非常有用。
  • DAT-2.D.4 数据过滤系统是查找信息和识别数据模式的重要工具。
  • DAT-2.D.5 电子表格等程序有助于高效地组织数据和查找趋势。
  • DAT-2.D.6 用于从数据中提取或修改信息的过程包括以下几种:
    • 转换数据集的每个元素,例如将列表中的每个元素翻倍,或将家长的电子邮件添加到每条学生记录中;
    • 筛选数据集,例如仅保留列表中的正数,或仅从所有学生记录中保留报名参加管乐队的学生;
    • 以某种方式组合或比较数据,例如对数字列表求和,或找出 GPA 最高的学生;
    • 通过图表、图形或其他可视化形式展示数据集。

学习目标 DAT-2.E: 解释如何使用程序从数据中获得洞察和知识。[技能 5.B]

  • DAT-2.E.1 在处理信息时,程序被以迭代和交互的方式使用,以便用户能够获得关于数据的洞察和知识。
  • DAT-2.E.2 程序员可以使用程序来筛选和清理数字数据,从而获得洞察和知识。
  • DAT-2.E.3 组合数据源、数据聚类和数据分类是使用程序从数据中获得洞察和知识过程的一部分。
  • DAT-2.E.4 通过翻译和转换数字化表示的信息可以获得洞察和知识。
  • DAT-2.E.5 当使用程序转换数据时,可能会出现模式。

来源:College Board AP 课程与考试说明

English

Programs process data at scales humans cannot. Common operations are filtering 过滤 (keeping only rows that meet a condition), cleaning (removing errors), and visualizing 可视化 (charts and graphs that make patterns visible). Combining data from multiple sources can reveal more, but raises privacy 隐私 concerns. Interactive tools and visualizations let people explore data and draw their own conclusions.

Worked example (what can the data answer?). A school stores one row per student:

Name Grade Transport Distance (km)
Ana 10 bus 6.5
Ben 11 bike 2.0
Chen 10 bus 8.0
  1. “What is the mean distance for students who come by bus?” Can be answered: filter Transport = bus, then average Distance: $\frac{6.5 + 8.0}{2} = 7.25$ km.
  2. “How many grade 10 students cycle?” Can be answered: filter on two columns, then count: 0.
  3. “Why do students choose the bus?” Cannot: no column records reasons.
  4. “How long is each journey in minutes?” Cannot: time is not stored, and distance alone does not give it.

Exam questions of this kind turn on one check: is every piece of information the question needs in a column?

Exam skill: be able to explain how a program helps find information in a large data set, and why correlation shown in the data does not establish causation.

Cleaning data makes entries consistent before a program processes them
Cleaning data makes entries consistent before a program processes them
词汇 训练
English 中文 拼音
filtering/ˈfɪltərɪŋ/ 过滤 guò lǜ
visualizing/ˈvɪʒuːəlaɪzɪŋ/ 可视化 kě shì huà
privacy/ˈprɪvəsi/ 隐私 yǐn sī
2.4

考试技巧

English
  • Convert confidently between binary, decimal, and (where asked) hexadecimal — practise until it is quick.
  • Remember a bit is one binary digit and a byte is 8 bits; $n$ bits represent $2^n$ values.
  • Explain that all data — numbers, text, images, sound — is stored as binary, and that finite bits cause overflow and round-off.
  • Distinguish lossless from lossy compression and when each is appropriate.
  • Show the analog-to-digital idea: sampling turns a continuous signal into discrete values.

该知识点的互动课程

逐步完成,配合即时检查练习。

历年真题

更多 AP 计算机科学原理 知识点

登录或创建账户

IGCSE, A-Level & AP