跳到主要内容
学科

AP 计算机科学原理

AP 计算机科学原理是一门"广度"课程而非编程课程:创造性开发、数据、算法与编程、计算机系统 与网络,以及计算的影响。它不绑定具体语言——考试使用 College Board 伪代码,因此不会因某种 语言的语法而失分。

评估分两部分:期末考试,以及 Create 实作任务——一个由你自己编写的程序,并附上关于它的书面 回答。实作任务在学年中提交,因此不能留到复习季再做;其书面回答考查的是你能否解释自己的代码, 尤其是你选择的算法与抽象。

"计算的影响"单元常被当作简单单元,结果答得过于笼统;回答需要指出对特定群体的特定影响。本站 笔记按 College Board 的单元编排,每单元一页,使用与考试相同的伪代码,所有算法也都能在本站 /code 课程中直接运行。

AP 计算机科学原理历年真题

训练全部词汇
  • 1

    创造性开发

    讲义 词汇表
    1.1

    协作

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CRD-1
    Incorporating multiple perspectives through collaboration improves computing innovations as they are developed.

    CRD-1.A
    Explain how computing innovations are improved through collaboration. [Skill 1.C]

    • CRD-1.A.1 A computing innovation includes a program as an integral part of its function.
    • CRD-1.A.2 A computing innovation can be physical (e.g., self-driving car), nonphysical computing software (e.g., picture editing software), or a nonphysical computing concept (e.g., e-commerce).
    • CRD-1.A.3 Effective collaboration produces a computing innovation that reflects the diversity of talents and perspectives of those who designed it.
    • CRD-1.A.4 Collaboration that includes diverse perspectives helps avoid bias in the development of computing innovations.
    • CRD-1.A.5 Consultation and communication with users are important aspects of the development of computing innovations.
    • CRD-1.A.6 Information gathered from potential users can be used to understand the purpose of a program from diverse perspectives and to develop a program that fully incorporates these perspectives.

    CRD-1.B
    Explain how computing innovations are developed by groups of people. [Skill 1.C]

    • CRD-1.B.1 Online tools support collaboration by allowing programmers to share and provide feedback on ideas and documents.
    • CRD-1.B.2 Common models such as pair programming exist to facilitate collaboration.

    CRD-1.C
    Demonstrate effective interpersonal skills during collaboration. [Skill 1.C]

    • CRD-1.C.1 Effective collaborative teams practice interpersonal skills, including but not limited to:
      • communication
      • consensus building
      • conflict resolution
      • negotiation

    来源:美国大学理事会 AP 课程与考试说明

    计算是一个协作(collaborative)活动。在一个团队里工作带来更多视角、捕捉更多错误,并产生比单独工作更好的程序。好的协作使用共识建立(consensus building)、清晰的沟通和每个成员的长处。结对编程(pair programming)——两个人在一台计算机前,一个打字一个审查——是一个常见的做法。在考试上,你应当能够解释协作如何改进了一个程序(更多想法、更少 bug、更广的测试)。

    词汇表 训练
    英文 中文 拼音
    collaborative 协作 xié zuò
    Pair programming 结对编程 jié duì biān chéng
    1.2

    程序的功能与目的

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CRD-2
    Developers create and innovate using an iterative design process that is user-focused, that incorporates implementation/feedback cycles, and that leaves ample room for experimentation and risk-taking.

    CRD-2.A
    Describe the purpose of a computing innovation. [Skill 1.A]

    • CRD-2.A.1 The purpose of computing innovations is to solve problems or to pursue interests through creative expression.
    • CRD-2.A.2 An understanding of the purpose of a computing innovation provides developers with an improved ability to develop that computing innovation.

    CRD-2.B
    Explain how a program or code segment functions. [Skill 4.A]

    • CRD-2.B.1 A program is a collection of program statements that performs a specific task when run by a computer. A program is often referred to as software.
    • CRD-2.B.2 A code segment is a collection of program statements that is part of a program.
    • CRD-2.B.3 A program needs to work for a variety of inputs and situations.
    • CRD-2.B.4 The behavior of a program is how a program functions during execution and is often described by how a user interacts with it.
    • CRD-2.B.5 A program can be described broadly by what it does, or in more detail by both what the program does and how the program statements accomplish this function.

    CRD-2.C
    Identify input(s) to a program. [Skill 3.A]

    • CRD-2.C.1 Program inputs are data sent to a computer for processing by a program. Input can come in a variety of forms, such as tactile, audio, visual, or text.
    • CRD-2.C.2 An event is associated with an action and supplies input data to a program.
    • CRD-2.C.3 Events can be generated when a key is pressed, a mouse is clicked, a program is started, or any other defined action occurs that affects the flow of execution.
    • CRD-2.C.4 Inputs usually affect the output produced by a program.
    • CRD-2.C.5 In event-driven programming, program statements are executed when triggered rather than through the sequential flow of control.
    • CRD-2.C.6 Input can come from a user or other programs.

    CRD-2.D
    Identify output(s) produced by a program. [Skill 3.A]

    • CRD-2.D.1 Program outputs are any data sent from a program to a device. Program output can come in a variety of forms, such as tactile, audio, visual, or text.
    • CRD-2.D.2 Program output is usually based on a program's input or prior state (e.g., internal values).

    来源:美国大学理事会 AP 课程与考试说明

    每个程序都为一个目的(purpose)而写——它解决一个问题或追求一个兴趣。一个程序接受输入(input)、处理它,并产生输出(output)。输入能来自一个用户、一个设备、一个文件,或另一个程序;输出能是视觉的、听觉的、文本的,或给一个设备的一个信号。能够陈述一个程序的目的,并清晰地描述它的输入和输出,是一项核心技能(以及创建性能任务的一部分)。

    每个程序分解成输入、处理和输出
    每个程序分解成输入、处理和输出
    每个程序遵循输入-处理-输出模型
    每个程序遵循输入-处理-输出模型
    探索

    Explore the input → processing → output model

    Step through the IPO model. Every program takes some input, performs processing on it by following its instructions, then produces output — trace one weather-app example along the pipeline.

    词汇表 训练
    英文 中文 拼音
    input 输入 shū rù
    output 输出 shū chū
    1.3

    程序设计与开发

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CRD-2
    Developers create and innovate using an iterative design process that is user-focused, that incorporates implementation/feedback cycles, and that leaves ample room for experimentation and risk-taking.

    CRD-2.E
    Develop a program using a development process. [Skill 1.B]

    • CRD-2.E.1 A development process can be ordered and intentional, or exploratory in nature.
    • CRD-2.E.2 There are multiple development processes. The following phases are commonly used when developing a program:
      • investigating and reflecting
      • designing
      • prototyping
      • testing
    • CRD-2.E.3 A development process that is iterative requires refinement and revision based on feedback, testing, or reflection throughout the process. This may require revisiting earlier phases of the process.
    • CRD-2.E.4 A development process that is incremental is one that breaks the problem into smaller pieces and makes sure each piece works before adding it to the whole.

    CRD-2.F
    Design a program and its user interface. [Skill 1.B]

    • CRD-2.F.1 The design of a program incorporates investigation to determine its requirements.
    • CRD-2.F.2 Investigation in a development process is useful for understanding and identifying the program constraints, as well as the concerns and interests of the people who will use the program.
    • CRD-2.F.3 Some ways investigation can be performed are as follows:
      • collecting data through surveys
      • user testing
      • interviews
      • direct observations
    • CRD-2.F.4 Program requirements describe how a program functions and may include a description of user interactions that a program must provide.
    • CRD-2.F.5 A program's specification defines the requirements for the program.
    • CRD-2.F.6 In a development process, the design phase outlines how to accomplish a given program specification.
    • CRD-2.F.7 The design phase of a program may include:
      • brainstorming
      • planning and storyboarding
      • organizing the program into modules and functional components
      • creation of diagrams that represent the layouts of the user interface
      • development of a testing strategy for the program

    CRD-2.G
    Describe the purpose of a code segment or program by writing documentation. [Skill 4.A]

    • CRD-2.G.1 Program documentation is a written description of the function of a code segment, event, procedure, or program and how it was developed.
    • CRD-2.G.2 Comments are a form of program documentation written into the program to be read by people and do not affect how a program runs.
    • CRD-2.G.3 Programmers should document a program throughout its development.
    • CRD-2.G.4 Program documentation helps in developing and maintaining correct programs when working individually or in collaborative programming environments.
    • CRD-2.G.5 Not all programming environments support comments, so other methods of documentation may be required.

    CRD-2.H
    Acknowledge code segments used from other sources. [Skill 1.C]

    • CRD-2.H.1 It is important to acknowledge any code segments that were developed collaboratively or by another source.
    • CRD-2.H.2 Acknowledgement of a code segment(s) written by someone else and used in a program can be in the program documentation. The acknowledgement should include the origin or original author's name.

    来源:美国大学理事会 AP 课程与考试说明

    程序通过一个迭代(iterative)过程构建,不是一条直线:调查问题和用户、设计(常常带一个(diagram)或书面计划)、以代码实现,并测试——然后重复。一个大问题被分解成更小的片段(分解(decomposition))。注释(comments)和清晰的命名记录设计,以便其他人(以及你未来的自己)能理解它。开发是增量(incremental)的——构建并测试一个小片段,然后添加下一个。

    程序开发的阶段,测试反馈以修复和精化
    程序开发的阶段,测试反馈以修复和精化
    软件由一个迭代的、增量的开发过程构建
    软件由一个迭代的、增量的开发过程构建
    探索

    Loop through the iterative development process

    Development is iterative — you repeat the stages, improving the program a little on each pass. Step around the loop and notice it returns to the start rather than ending after one run.

    词汇表 训练
    英文 中文 拼音
    iterative 迭代 dié dài
    decomposition 分解 fēn jiě
    Comments 注释 zhù shì
    1.4

    识别与纠正错误

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CRD-2
    Developers create and innovate using an iterative design process that is user-focused, that incorporates implementation/feedback cycles, and that leaves ample room for experimentation and risk-taking.

    CRD-2.I
    For errors in an algorithm or program:
    a. Identify the error. [Skill 4.C]
    b. Correct the error. [Skill 4.C]

    • CRD-2.I.1 A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly.
    • CRD-2.I.2 A syntax error is a mistake in the program where the rules of the programming language are not followed.
    • CRD-2.I.3 A run-time error is a mistake in the program that occurs during the execution of a program. Programming languages define their own run-time errors.
    • CRD-2.I.4 An overflow error is an error that occurs when a computer attempts to handle a number that is outside of the defined range of values.
    • CRD-2.I.5 The following are effective ways to find and correct errors:
      • test cases
      • hand tracing
      • visualizations
      • debuggers
      • adding extra output statement(s)

    CRD-2.J
    Identify inputs and corresponding expected outputs or behaviors that can be used to check the correctness of an algorithm or program. [Skill 4.C]

    • CRD-2.J.1 In the development process, testing uses defined inputs to ensure that an algorithm or program is producing the expected outcomes. Programmers use the results from testing to revise their algorithms or programs.
    • CRD-2.J.2 Defined inputs used to test a program should demonstrate the different expected outcomes that are at or just beyond the extremes (minimum and maximum) of input data.
    • CRD-2.J.3 Program requirements are needed to identify appropriate defined inputs for testing.

    来源:美国大学理事会 AP 课程与考试说明

    一个 bug 是一个程序里的错误;调试(debugging)是找到并修复它。三种:

    一张跟踪表在程序运行时记录每个变量的值,以找到 bug
    一张跟踪表在程序运行时记录每个变量的值,以找到 bug
    • 一个语法错误(syntax error)破坏语言的规则,所以程序不会运行;
    • 一个运行时错误(runtime error)在它运行时使程序崩溃(例如除以零);
    • 一个逻辑错误(logic error)让它运行但给出错误的结果。

    通过用不同的输入(包括边界情况)测试、添加打印语句(print statements)以看值,以及手工跟踪代码来找 bug。一次修复一个 bug 并重新测试是可靠的方法。

    考试技能: 能够命名一个错误的类型并描述一个会捕捉它的测试策略——一个反复出现的选择题和创建任务主题。

    三种编程错误:语法、逻辑和运行时
    三种编程错误:语法、逻辑和运行时

    Worked example. 一个本应打印两个数平均值的程序却运行了 avg = a + b / 2。追踪运算顺序,/+ 之前运行,所以它计算 $a+\tfrac{b}{2}$ 而不是平均值。加括号来修复:avg = (a + b) / 2。用已知输入 $a=4,\ b=6$ 测试确认修复——有错误的行给 $4+3=7$,修正后的行给 $\tfrac{10}{2}=5$。用已知输入测试正是你找到并确认一个逻辑错误的方法。

    探索

    Trace the guessing-game logic and spot a logic error

    Drag the guess and watch which branch runs. A logic error would send the same guess down the wrong branch — the program still runs, but gives the wrong message. The secret number here is 50.

    词汇表 训练
    英文 中文 拼音
    debugging 调试 tiáo shì
    syntax error 语法错误 yǔ fǎ cuò wù
    runtime error 运行时错误 yùn xíng shí cuò wù
    logic error 逻辑错误 luó jí cuò wù
    1.4

    考试技巧

    • CSP 的很多部分通过创建(Create)和书面性能任务评估——清晰地解释你的推理,不只是你的结果。
    • 知道协作的好处以及多样的视角如何减少一个程序里的偏见。
    • 当你描述一个设计过程时使用精确的词汇(迭代开发、程序需求)。
    • 建设性地给出和接受反馈;为协作者和来源署名。
    • 把一个大问题分解成一个团队能并行构建的更小的模块。
  • 2

    数据

    讲义 词汇表
    2.1

    二进制数

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    DAT-1
    The way a computer represents data internally is different from the way the data are interpreted and displayed for the user. Programs are used to translate data into a representation more easily understood by people.

    DAT-1.A
    Explain how data can be represented using bits. [Skill 3.C]

    • DAT-1.A.1 Data values can be stored in variables, lists of items, or standalone constants and can be passed as input to (or output from) procedures.
    • DAT-1.A.2 Computing devices represent data digitally, meaning that the lowest-level components of any value are bits.
    • DAT-1.A.3 Bit is shorthand for binary digit and is either 0 or 1.
    • DAT-1.A.4 A byte is 8 bits.
    • DAT-1.A.5 Abstraction is the process of reducing complexity by focusing on the main idea. By hiding details irrelevant to the question at hand and bringing together related and useful details, abstraction reduces complexity and allows one to focus on the idea.
    • DAT-1.A.6 Bits are grouped to represent abstractions. These abstractions include, but are not limited to, numbers, characters, and color.
    • DAT-1.A.7 The same sequence of bits may represent different types of data in different contexts.
    • DAT-1.A.8 Analog data have values that change smoothly, rather than in discrete intervals, over time. Some examples of analog data include pitch and volume of music, colors of a painting, or position of a sprinter during a race.
    • DAT-1.A.9 The use of digital data to approximate real-world analog data is an example of abstraction.
    • DAT-1.A.10 Analog data can be closely approximated digitally using a sampling technique, which means measuring values of the analog signal at regular intervals called samples. The samples are measured to figure out the exact bits required to store each sample.

    DAT-1.B
    Explain the consequences of using bits to represent data. [Skill 1.D]

    • DAT-1.B.1 In many programming languages, integers are represented by a fixed number of bits, which limits the range of integer values and mathematical operations on those values. This limitation can result in overflow or other errors.
    • DAT-1.B.2 Other programming languages provide an abstraction through which the size of representable integers is limited only by the size of the computer's memory; this is the case for the language defined in the exam reference sheet.
    • DAT-1.B.3 In programming languages, the fixed number of bits used to represent real numbers limits the range and mathematical operations on these values; this limitation can result in round-off and other errors. Some real numbers are represented as approximations in computer storage.
      • Exclusion statement: Specific range limitations for real numbers are outside the scope of this course and the AP Exam.

    DAT-1.C
    For binary numbers:
    a. Calculate the binary (base 2) equivalent of a positive integer (base 10) and vice versa. [Skill 2.B]
    b. Compare and order binary numbers. [Skill 2.B]

    • DAT-1.C.1 Number bases, including binary and decimal, are used to represent data.
    • DAT-1.C.2 Binary (base 2) uses only combinations of the digits zero and one.
    • DAT-1.C.3 Decimal (base 10) uses only combinations of the digits $0 - 9$.
    • DAT-1.C.4 As with decimal, a digit's position in the binary sequence determines its numeric value. The numeric value is equal to the bit's value (0 or 1) multiplied by the place value of its position.
    • DAT-1.C.5 The place value of each position is determined by the base raised to the power of the position. Positions are numbered starting at the rightmost position with 0 and increasing by 1 for each subsequent position to the left.

    来源:美国大学理事会 AP 课程与考试说明

    计算机把一切存储为(bits)——每个是一个 01。一组 8 位是一个字节(byte)。数字以二进制(binary)(基数 2)存储,其中每一位是二的一个幂($1, 2, 4, 8, 16, \dots$),而不是十进制(decimal)里十的幂。例如,二进制 1011$8+2+1=11$

    一个 8 位的位值图:1 坐在加起来等于这个数的值之下
    一个 8 位的位值图:1 坐在加起来等于这个数的值之下

    Worked example. 要把二进制 1101 转换成十进制,把位值 8 4 2 1 写在位 1 1 0 1 之下并加上有一个 1 的那些:$8+4+0+1=13$。反过来,通过减去合适的最大二的幂把 19 转换成二进制:$19-16=3$,然后 $3-2=1$,然后 $1-1=0$,所以位坐在 1621$\rightarrow$ 10011(检查:$16+2+1=19$)。

    因为一台计算机有有限数量的位,它只能表示一个有限范围的值。这造成考试上考查的两个效应:

    • 溢出错误(overflow error):一个对可用的位太大的数不能被正确地存储。
    • 舍入错误(round-off (rounding) error):带小数的数(实数)只能被近似,因为无穷多个实数值必须映射到有限多个位模式上。

    所有数据——文本、图像、声音——最终都被编码为二进制。一个图像是一个像素(pixels)网格,每个作为它颜色的数字存储;声音作为每秒采样许多次的数字存储。

    探索

    Convert between binary and decimal

    Computers store numbers in binary (base 2). Each bit is a power of two; add the place values of the 1-bits to read the decimal number.

    词汇表 训练
    英文 中文 拼音
    bits wèi
    byte 字节 zì jié
    binary 二进制 èr jìn zhì
    decimal 十进制 shí jìn zhì
    Overflow error 溢出错误 yì chū cuò wù
    Round-off (rounding) error 舍入错误 shě rù cuò wù
    pixels 像素 xiàng sù
    2.2

    数据压缩

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    DAT-1
    The way a computer represents data internally is different from the way the data are interpreted and displayed for the user. Programs are used to translate data into a representation more easily understood by people.

    DAT-1.D
    Compare data compression algorithms to determine which is best in a particular context. [Skill 1.D]

    • DAT-1.D.1 Data compression can reduce the size (number of bits) of transmitted or stored data.
    • DAT-1.D.2 Fewer bits does not necessarily mean less information.
    • DAT-1.D.3 The amount of size reduction from compression depends on both the amount of redundancy in the original data representation and the compression algorithm applied.
    • DAT-1.D.4 Lossless data compression algorithms can usually reduce the number of bits stored or transmitted while guaranteeing complete reconstruction of the original data.
    • DAT-1.D.5 Lossy data compression algorithms can significantly reduce the number of bits stored or transmitted but only allow reconstruction of an approximation of the original data.
    • DAT-1.D.6 Lossy data compression algorithms can usually reduce the number of bits stored or transmitted more than lossless compression algorithms.
    • DAT-1.D.7 In situations where quality or ability to reconstruct the original is maximally important, lossless compression algorithms are typically chosen.
    • DAT-1.D.8 In situations where minimizing data size or transmission time is maximally important, lossy compression algorithms are typically chosen.

    来源:美国大学理事会 AP 课程与考试说明

    压缩(compression)减少存储或发送数据所需的位数。两种:

    压缩方法:无损与有损,带常见例子
    压缩方法:无损与有损,带常见例子
    • 无损压缩(lossless compression)让你能恢复精确的原始数据(用于文本和程序,那里每一位都重要)。
    • 有损压缩(lossy compression)扔掉一些数据以进一步缩小大小(用于照片、音乐、视频,那里一个小的质量损失可接受)。

    在它们之间选择权衡大小与保真度:无损保留一切但节省更少;有损节省更多但永久地失去细节。当数据必须精确时偏好无损。

    探索

    Compress a run of repeats

    Run-length encoding is a lossless compression: a long run of the same symbol is replaced by the symbol and a count, shrinking the data with no information lost.

    词汇表 训练
    英文 中文 拼音
    Compression 压缩 yā suō
    Lossless compression 无损压缩 wú sǔn yā suō
    Lossy compression 有损压缩 yǒu sǔn yā suō
    2.3

    从数据中提取信息

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    DAT-2
    Programs can be used to process data, which allows users to discover information and create new knowledge.

    DAT-2.A
    Describe what information can be extracted from data. [Skill 5.B]

    • DAT-2.A.1 Information is the collection of facts and patterns extracted from data.
    • DAT-2.A.2 Data provide opportunities for identifying trends, making connections, and addressing problems.
    • DAT-2.A.3 Digitally processed data may show correlation between variables. A correlation found in data does not necessarily indicate that a causal relationship exists. Additional research is needed to understand the exact nature of the relationship.
    • DAT-2.A.4 Often, a single source does not contain the data needed to draw a conclusion. It may be necessary to combine data from a variety of sources to formulate a conclusion.

    DAT-2.B
    Describe what information can be extracted from metadata. [Skill 5.B]

    • DAT-2.B.1 Metadata are data about data. For example, the piece of data may be an image, while the metadata may include the date of creation or the file size of the image.
    • DAT-2.B.2 Changes and deletions made to metadata do not change the primary data.
    • DAT-2.B.3 Metadata are used for finding, organizing, and managing information.
    • DAT-2.B.4 Metadata can increase the effective use of data or data sets by providing additional information.
    • DAT-2.B.5 Metadata allow data to be structured and organized.

    DAT-2.C
    Identify the challenges associated with processing data. [Skill 5.D]

    • DAT-2.C.1 The ability to process data depends on the capabilities of the users and their tools.
    • DAT-2.C.2 Data sets pose challenges regardless of size, such as:
      • the need to clean data
      • incomplete data
      • invalid data
      • the need to combine data sources
    • DAT-2.C.3 Depending on how data were collected, they may not be uniform. For example, if users enter data into an open field, the way they choose to abbreviate, spell, or capitalize something may vary from user to user.
    • DAT-2.C.4 Cleaning data is a process that makes the data uniform without changing their meaning (e.g., replacing all equivalent abbreviations, spellings, and capitalizations with the same word).
    • DAT-2.C.5 Problems of bias are often created by the type or source of data being collected. Bias is not eliminated by simply collecting more data.
    • DAT-2.C.6 The size of a data set affects the amount of information that can be extracted from it.
    • DAT-2.C.7 Large data sets are difficult to process using a single computer and may require parallel systems.
    • DAT-2.C.8 Scalability of systems is an important consideration when working with data sets, as the computational capacity of a system affects how data sets can be processed and stored.

    来源:美国大学理事会 AP 课程与考试说明

    当我们从数据(data)提取信息(information)时它变得有用——模式、趋势,和问题的答案。大数据集能揭示一个小的不能揭示的相关性,但数据必须先被清洗(cleaned)(修复错误和不一致)并常常被变换(transformed)或过滤(filtered)。两样东西之间的一个相关性(correlation)不证明一个导致(causes)另一个——一个关键的警告。元数据(metadata)(关于数据的数据,像一张照片的日期和位置)帮助组织和搜索大搜集。

    词汇表 训练
    英文 中文 拼音
    Data 数据 shù jù
    information 信息 xìn xī
    correlation 相关性 xiāng guān xìng
    Metadata 元数据 yuán shù jù
    2.4

    用程序处理数据

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    DAT-2
    Programs can be used to process data, which allows users to discover information and create new knowledge.

    DAT-2.D
    Extract information from data using a program. [Skill 2.B]

    • DAT-2.D.1 Programs can be used to process data to acquire information.
    • DAT-2.D.2 Tables, diagrams, text, and other visual tools can be used to communicate insight and knowledge gained from data.
    • DAT-2.D.3 Search tools are useful for efficiently finding information.
    • DAT-2.D.4 Data filtering systems are important tools for finding information and recognizing patterns in data.
    • DAT-2.D.5 Programs such as spreadsheets help efficiently organize and find trends in information.
    • DAT-2.D.6 Some processes that can be used to extract or modify information from data include the following:
      • transforming every element of a data set, such as doubling every element in a list, or adding a parent's email to every student record
      • filtering a data set, such as keeping only the positive numbers from a list, or keeping only students who signed up for band from a record of all the students
      • combining or comparing data in some way, such as adding up a list of numbers, or finding the student who has the highest GPA
      • visualizing a data set through a chart, graph, or other visual representation

    DAT-2.E
    Explain how programs can be used to gain insight and knowledge from data. [Skill 5.B]

    • DAT-2.E.1 Programs are used in an iterative and interactive way when processing information to allow users to gain insight and knowledge about data.
    • DAT-2.E.2 Programmers can use programs to filter and clean digital data, thereby gaining insight and knowledge.
    • DAT-2.E.3 Combining data sources, clustering data, and classifying data are parts of the process of using programs to gain insight and knowledge from data.
    • DAT-2.E.4 Insight and knowledge can be obtained from translating and transforming digitally represented information.
    • DAT-2.E.5 Patterns can emerge when data are transformed using programs.

    来源:美国大学理事会 AP 课程与考试说明

    程序以人类不能的规模处理数据。常见的操作是过滤(filtering)(只保留满足一个条件的行)、清洗(cleaning)(移除错误),和可视化(visualizing)(使模式可见的图表)。组合来自多个来源的数据能揭示更多,但引发隐私(privacy)顾虑。交互式工具和可视化让人们探索数据并得出他们自己的结论。

    考试技能: 能够解释一个程序如何帮助在一个大数据集里找到信息,以及为什么数据里显示的相关性不建立因果关系。

    词汇表 训练
    英文 中文 拼音
    filtering 过滤 guò lǜ
    visualizing 可视化 kě shì huà
    privacy 隐私 yǐn sī
    2.4

    考试技巧

    • 自信地在二进制、十进制和(在被要求时)十六进制之间转换——练习直到它快速。
    • 记住一个位是一个二进制数字而一个字节是 8 位;$n$ 位表示 $2^n$ 个值。
    • 解释所有数据——数字、文本、图像、声音——都存储为二进制,而有限的位造成溢出舍入
    • 区分无损有损压缩以及每个何时合适。
    • 展示模拟到数字的思想:采样(sampling)把一个连续信号变成离散的值。
  • 3

    算法与编程

    讲义 词汇表

    下面的代码使用 AP CSP 伪代码(AP CSP pseudocode)——考试的语言中立参考。赋值写作 a ← expression,而列表索引从 1 开始。

    3.1

    变量与赋值

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-1
    To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.

    AAP-1.A
    Represent a value with a variable. [Skill 3.A]

    • AAP-1.A.1 A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.
    • AAP-1.A.2 Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.
    • AAP-1.A.3 Some programming languages provide types to represent data, which are referenced using variables. These types include numbers, Booleans, lists, and strings.
    • AAP-1.A.4 Some values are better suited to representation using one type of datum rather than another.

    AAP-1.B
    Determine the value of a variable as a result of an assignment. [Skill 4.B]

    • AAP-1.B.1 The assignment operator allows a program to change the value represented by a variable.

    • AAP-1.B.2 The exam reference sheet provides the "$\leftarrow$" operator to use for assignment. For example,

      Text:

      a ← expression

      Block:

      a ← expression

      evaluates expression and then assigns a copy of the result to the variable a.

    • AAP-1.B.3 The value stored in a variable will be the most recent value assigned. For example:

      a ← 1 b ← a a ← 2 display(b)

      still displays 1.

    来源:美国大学理事会 AP 课程与考试说明

    一个变量(variable)是一个持有一个值的命名的地方。赋值(assignment)运算符把右边的值存进左边的变量:

    一个变量是一个值能变化的命名的存储
    一个变量是一个值能变化的命名的存储
    a ← 5
    b ← a + 3      // b is now 8
    

    一个变量一次持有一个值;再次赋值替换它。变量让一个程序存储输入、记住结果,并重用它们。

    探索

    Watch a variable hold and change its value

    A variable is a named box that stores one value at a time. An assignment copies a value into the box; assigning again overwrites whatever was there.

    词汇表 训练
    英文 中文 拼音
    variable 变量 biàn liàng
    assignment 赋值 fù zhí
    3.2

    数据抽象

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-1
    To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.

    AAP-1.C
    Represent a list or string using a variable. [Skill 3.A]

    • AAP-1.C.1 A list is an ordered sequence of elements. For example,

      [value1, value2, value3, ...]

      describes a list where value1 is the first element, value2 is the second element, value3 is the third element, and so on.

    • AAP-1.C.2 An element is an individual value in a list that is assigned a unique index.

    • AAP-1.C.3 An index is a common method for referencing the elements in a list or string using natural numbers.

    • AAP-1.C.4 A string is an ordered sequence of characters.

    AAP-1.D
    For data abstraction:
    a. Develop data abstraction using lists to store multiple elements. [Skill 3.B]
    b. Explain how the use of data abstraction manages complexity in program code. [Skill 3.C]

    • AAP-1.D.1 Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation.

    • AAP-1.D.2 Data abstractions manage complexity in programs by giving a collection of data a name without referencing the specific details of the representation.

    • AAP-1.D.3 Data abstractions can be created using lists.

    • AAP-1.D.4 Developing a data abstraction to implement in a program can result in a program that is easier to develop and maintain.

    • AAP-1.D.5 Data abstractions often contain different types of elements.

    • AAP-1.D.6 The use of lists allows multiple related items to be treated as a single value. Lists are referred to by different names, such as array, depending on the programming language.

      • Exclusion statement (EK AAP-1.D.6): The use of linked lists is outside the scope of this course and the AP Exam.
    • AAP-1.D.7 The exam reference sheet provides the notation

      [value1, value2, value3, ...]

      to create a list with those values as the first, second, third, and so on items. For example,

      • Text:

        aList ← [value1, value2, value3, ...]

        Block:

        aList ← value1, value2, value3

        creates a new list that contains the values value1, value2, value3, and ... at indices 1, 2, 3, and ... respectively and assigns it to aList.

      • Text:

        aList ← []

        Block:

        aList ← (empty)

        creates a new empty list and assigns it to aList.

      • Text:

        aList ← bList

        Block:

        aList ← bList

        assigns a copy of the list bList to the list aList. For example, if bList contains [20, 40, 60], then aList will also contain [20, 40, 60] after the assignment.

    • AAP-1.D.8 The exam reference sheet describes a list structure whose index values are 1 through the number of elements in the list, inclusive. For all list operations, if a list index is less than 1 or greater than the length of the list, an error message is produced and the program will terminate.

    来源:美国大学理事会 AP 课程与考试说明

    数据抽象(data abstraction)让你通过给一个数据搜集一个单一的名字来管理复杂性——例如,一个列表而不是几十个分开的变量。它隐藏细节:你使用命名的搜集而不担心它如何被存储。列表(下面)是课程的主要数据抽象。

    词汇表 训练
    英文 中文 拼音
    Data abstraction 数据抽象 shù jù chōu xiàng
    abstraction 抽象 chōu xiàng
    3.3

    数学表达式

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.A
    Express an algorithm that uses sequencing without using a programming language. [Skill 2.A]

    • AAP-2.A.1 An algorithm is a finite set of instructions that accomplish a specific task.
    • AAP-2.A.2 Beyond visual and textual programming languages, algorithms can be expressed in a variety of ways, such as natural language, diagrams, and pseudocode.
    • AAP-2.A.3 Algorithms executed by programs are implemented using programming languages.
    • AAP-2.A.4 Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

    AAP-2.B
    Represent a step-by-step algorithmic process using sequential code statements. [Skill 2.B]

    • AAP-2.B.1 Sequencing is the application of each step of an algorithm in the order in which the code statements are given.
    • AAP-2.B.2 A code statement is a part of program code that expresses an action to be carried out.
    • AAP-2.B.3 An expression can consist of a value, a variable, an operator, or a procedure call that returns a value.
    • AAP-2.B.4 Expressions are evaluated to produce a single value.
    • AAP-2.B.5 The evaluation of expressions follows a set order of operations defined by the programming language.
    • AAP-2.B.6 Sequential statements execute in the order they appear in the code segment.
    • AAP-2.B.7 Clarity and readability are important considerations when expressing an algorithm in a programming language.

    AAP-2.C
    Evaluate expressions that use arithmetic operators. [Skill 4.B]

    • AAP-2.C.1 Arithmetic operators are part of most programming languages and include addition, subtraction, multiplication, division, and modulus operators.

    • AAP-2.C.2 The exam reference sheet provides a MOD b, which evaluates to the remainder when a is divided by b. Assume that a is an integer greater than or equal to 0 and b is an integer greater than 0. For example, 17 MOD 5 evaluates to 2.

    • AAP-2.C.3 The exam reference sheet provides the arithmetic operators +, -, *, /, and MOD.

      Text and Block:

      • a + b
      • a - b
      • a * b
      • a / b
      • a MOD b

      These are used to perform arithmetic on a and b. For example, 17 / 5 evaluates to 3.4.

    • AAP-2.C.4 The order of operations used in mathematics applies when evaluating expressions. The MOD operator has the same precedence as the * and / operators.

    来源:美国大学理事会 AP 课程与考试说明

    程序用运算符 +-*/MOD(一次除法的余数(remainder),例如 17 MOD 52)计算。表达式遵循通常的运算顺序。MOD 对测试可除性(n MOD 2 = 0 意味着 n 是偶数)和把值环绕一个范围尤其有用。

    探索

    Evaluate an expression step by step

    An expression is evaluated with order of operations: multiplication and division happen before addition and subtraction, left to right.

    词汇表 训练
    英文 中文 拼音
    remainder 余数 yú shù
    3.4

    字符串

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.D
    Evaluate expressions that manipulate strings. [Skill 4.B]

    • AAP-2.D.1 String concatenation joins together two or more strings end-to-end to make a new string.
    • AAP-2.D.2 A substring is part of an existing string.

    来源:美国大学理事会 AP 课程与考试说明

    一个字符串(string)是一个有序的字符序列,像 "hello"。程序连接字符串(拼接(concatenation))并找它们的长度。字符串表示文本——名字、消息、序列——而且是一个常见的程序输入和输出。

    词汇表 训练
    英文 中文 拼音
    string 字符串 zì fú chuàn
    concatenation 拼接 pīn jiē
    3.5

    布尔表达式

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.E
    For relationships between two variables, expressions, or values:
    a. Write expressions using relational operators. [Skill 2.B]
    b. Evaluate expressions that use relational operators. [Skill 4.B]

    • AAP-2.E.1 A Boolean value is either true or false.

    • AAP-2.E.2 The exam reference sheet provides the following relational operators: =, , >, <, , and .

      Text and Block:

      • a = b
      • a ≠ b
      • a > b
      • a < b
      • a ≥ b
      • a ≤ b

      These are used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.

    AAP-2.F
    For relationships between Boolean values:
    a. Write expressions using logical operators. [Skill 2.B]
    b. Evaluate expressions that use logic operators. [Skill 4.B]

    • AAP-2.F.1 The exam reference sheet provides the logical operators NOT, AND, and OR, which evaluate to a Boolean value.

    • AAP-2.F.2 The exam reference sheet provides

      Text:

      NOT condition

      Block:

      NOT condition

      which evaluates to true if condition is false; otherwise it evaluates to false.

    • AAP-2.F.3 The exam reference sheet provides

      Text:

      condition1 AND condition2

      Block:

      condition1 AND condition2

      which evaluates to true if both condition1 and condition2 are true; otherwise it evaluates to false.

    • AAP-2.F.4 The exam reference sheet provides

      Text:

      condition1 OR condition2

      Block:

      condition1 OR condition2

      which evaluates to true if condition1 is true or if condition2 is true or if both condition1 and condition2 are true; otherwise it evaluates to false.

    • AAP-2.F.5 The operand for a logical operator is either a Boolean expression or a single Boolean value.

    来源:美国大学理事会 AP 课程与考试说明

    一个布尔表达式(Boolean expression)求值为 truefalse。它使用关系运算符(=<>)和逻辑运算符 NOTANDOR:

    三个运算符家族:算术、关系和逻辑
    三个运算符家族:算术、关系和逻辑
    • NOT 反转一个值,
    • AND 只在侧都真时为真,
    • OR至少一侧为真时为真。

    这些条件驱动每个决定和循环。

    探索

    Try the OR truth table

    A Boolean expression is either true (1) or false (0). OR is true when at least one input is true; flip the inputs to see every case.

    词汇表 训练
    英文 中文 拼音
    Boolean expression 布尔表达式 bù ěr biǎo dá shì
    3.6

    条件语句

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.G
    Express an algorithm that uses selection without using a programming language. [Skill 2.A]

    • AAP-2.G.1 Selection determines which parts of an algorithm are executed based on a condition being true or false.

    AAP-2.H
    For selection:
    a. Write conditional statements. [Skill 2.B]
    b. Determine the result of conditional statements. [Skill 4.B]

    • AAP-2.H.1 Conditional statements, or "if-statements," affect the sequential flow of control by executing different statements based on the value of a Boolean expression.

    • AAP-2.H.2 The exam reference sheet provides

      Text:

      IF(condition) { <block of statements> }

      Block:

      IF condition block of statements

      in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.

    • AAP-2.H.3 The exam reference sheet provides

      Text:

      IF(condition) { <first block of statements> } ELSE { <second block of statements> }

      Block:

      IF condition first block of statements ELSE second block of statements

      in which the code in first block of statements is executed if the Boolean expression condition evaluates to true; otherwise, the code in second block of statements is executed.

    来源:美国大学理事会 AP 课程与考试说明

    一个条件语句(选择)(conditional (selection))选择运行哪段代码。IF 只在它的条件为真时运行一个块;ELSE 给出一个替代:

    选择基于一个条件在路径之间选择
    选择基于一个条件在路径之间选择
    IF (score ≥ 60)
    {
        DISPLAY("Pass")
    }
    ELSE
    {
        DISPLAY("Fail")
    }
    
    探索

    Follow an if / else decision

    A conditional runs one branch or another depending on whether its condition is true. Slide the value across the threshold and watch which branch is taken.

    词汇表 训练
    英文 中文 拼音
    conditional (selection) 条件语句 tiáo jiàn yǔ jù
    3.7

    嵌套条件语句

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.I
    For nested selection:
    a. Write nested conditional statements. [Skill 2.B]
    b. Determine the result of nested conditional statements. [Skill 4.B]

    • AAP-2.I.1 Nested conditional statements consist of conditional statements within conditional statements.

    来源:美国大学理事会 AP 课程与考试说明

    一个嵌套条件(nested conditional)把一个 IF 放进另一个里面(或链接 ELSE IF)以在多于两条路径中选择。只有第一个匹配的分支运行:

    IF (g ≥ 90)      { grade ← "A" }
    ELSE IF (g ≥ 80) { grade ← "B" }
    ELSE             { grade ← "C" }
    
    词汇表 训练
    英文 中文 拼音
    nested conditional 嵌套条件 qiàn tào tiáo jiàn
    3.8

    迭代

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.J
    Express an algorithm that uses iteration without using a programming language. [Skill 2.A]

    • AAP-2.J.1 Iteration is a repeating portion of an algorithm. Iteration repeats a specified number of times or until a given condition is met.

    AAP-2.K
    For iteration:
    a. Write iteration statements. [Skill 2.B]
    b. Determine the result or side effect of iteration statements. [Skill 4.B]

    • AAP-2.K.1 Iteration statements change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met.

    • AAP-2.K.2 The exam reference sheet provides

      Text:

      REPEAT n TIMES { <block of statements> }

      Block:

      REPEAT n TIMES block of statements

      in which the block of statements is executed n times.

    • AAP-2.K.3 The exam reference sheet provides

      Text:

      REPEAT UNTIL(condition) { <block of statements> }

      Block:

      REPEAT UNTIL condition block of statements

      in which the code in block of statements is repeated until the Boolean expression condition evaluates to true.

    • AAP-2.K.4 In REPEAT UNTIL(condition) iteration, an infinite loop occurs when the ending condition will never evaluate to true.

    • AAP-2.K.5 In REPEAT UNTIL(condition) iteration, if the conditional evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop.

    来源:美国大学理事会 AP 课程与考试说明

    迭代(一个循环)(iteration (a loop))重复指令。AP 伪代码有两种形式:

    一个前置条件(WHILE)循环在主体之前测试,所以它可能运行零次
    一个前置条件(WHILE)循环在主体之前测试,所以它可能运行零次
    REPEAT 5 TIMES        // a fixed count
    {
        DISPLAY("hi")
    }
    
    REPEAT UNTIL (found)  // until a condition becomes true
    {
        ...
    }
    

    一个从不满足它停止条件的循环是一个无限循环(infinite loop)。

    探索

    Trace a loop one pass at a time

    A loop repeats a block while its counter runs through a range. Step through to watch the counter and the running total update each pass.

    词汇表 训练
    英文 中文 拼音
    Iteration (a loop) 迭代 dié dài
    infinite loop 无限循环 wú xiàn xún huán
    3.9

    开发算法

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.L
    Compare multiple algorithms to determine if they yield the same side effect or result. [Skill 1.D]

    • AAP-2.L.1 Algorithms can be written in different ways and still accomplish the same tasks.
    • AAP-2.L.2 Algorithms that appear similar can yield different side effects or results.
    • AAP-2.L.3 Some conditional statements can be written as equivalent Boolean expressions.
    • AAP-2.L.4 Some Boolean expressions can be written as equivalent conditional statements.
    • AAP-2.L.5 Different algorithms can be developed or used to solve the same problem.

    AAP-2.M
    For algorithms:
    a. Create algorithms. [Skill 2.A]
    b. Combine and modify existing algorithms. [Skill 2.B]

    • AAP-2.M.1 Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.
    • AAP-2.M.2 Knowledge of existing algorithms can help in constructing new ones. Some existing algorithms include:
      • determining the maximum or minimum value of two or more numbers
      • computing the sum or average of two or more numbers
      • identifying if an integer is or is not evenly divisible by another integer
      • determining a robot's path through a maze
    • AAP-2.M.3 Using existing correct algorithms as building blocks for constructing another algorithm has benefits such as reducing development time, reducing testing, and simplifying the identification of errors.

    来源:美国大学理事会 AP 课程与考试说明

    一个算法(algorithm)是解决一个问题的一个有限的步骤序列,由顺序(sequencing)、选择(selection)和迭代(iteration)构建。不同的算法能解决同一个问题,而你应当能够组合和修改现有的算法(例如,数一个列表里满足一个条件的值,或找最大的)。手工跟踪一个算法以检查它正确。

    一个流程图用标准符号布置一个算法
    一个流程图用标准符号布置一个算法
    词汇表 训练
    英文 中文 拼音
    algorithm 算法 suàn fǎ
    3.10

    列表

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.N
    For list operations:
    a. Write expressions that use list indexing and list procedures. [Skill 2.B]
    b. Evaluate expressions that use list indexing and list procedures. [Skill 4.B]

    • AAP-2.N.1 The exam reference sheet provides basic operations on lists, including:
      • accessing an element by index

        Text:

        aList[i]

        Block:

        aList i

        accesses the element of aList at index i. The first element of aList is at index 1 and is accessed using the notation aList[1].

      • assigning a value of an element of a list to a variable

        Text:

        x ← aList[i]

        Block:

        x ← aList i

        assigns the value of aList[i] to the variable x.

      • assigning a value to an element of a list

        Text:

        aList[i] ← x

        Block:

        aList i ← x

        assigns the value of x to aList[i].

        Text:

        aList[i] ← aList[j]

        Block:

        aList i ← aList j

        assigns the value of aList[j] to aList[i].

      • inserting elements at a given index

        Text:

        INSERT(aList, i, value)

        Block:

        INSERT aList, i, value

        shifts to the right any values in aList at indices greater than or equal to i. The length of the list is increased by 1, and value is placed at index i in aList.

      • adding elements to the end of the list

        Text:

        APPEND(aList, value)

        Block:

        APPEND aList, value

        increases the length of aList by 1, and value is placed at the end of aList.

      • removing elements

        Text:

        REMOVE(aList, i)

        Block:

        REMOVE aList, i

        removes the item at index i in aList and shifts to the left any values at indices greater than i. The length of aList is decreased by 1.

      • determining the length of a list

        Text:

        LENGTH(aList)

        Block:

        LENGTH aList

        evaluates to the number of elements currently in aList.

    • AAP-2.N.2 List procedures are implemented in accordance with the syntax rules of the programming language.

    AAP-2.O
    For algorithms involving elements of a list:
    a. Write iteration statements to traverse a list. [Skill 2.B]
    b. Determine the result of an algorithm that includes list traversals. [Skill 4.B]

    • AAP-2.O.1 Traversing a list can be a complete traversal, where all elements in the list are accessed, or a partial traversal, where only a portion of elements are accessed.

      • Exclusion statement (EK AAP-2.O.1): Traversing multiple lists at the same time using the same index for both (parallel traversals) is outside the scope of this course and the AP Exam.
    • AAP-2.O.2 Iteration statements can be used to traverse a list.

    • AAP-2.O.3 The exam reference sheet provides

      Text:

      FOR EACH item IN aList { <block of statements> }

      Block:

      FOR EACH item IN aList block of statements

      The variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The code in block of statements is executed once for each assignment of item.

    • AAP-2.O.4 Knowledge of existing algorithms that use iteration can help in constructing new algorithms. Some examples of existing algorithms that are often used with lists include:

      • determining a minimum or maximum value in a list
      • computing a sum or average of a list of numbers
    • AAP-2.O.5 Linear search or sequential search algorithms check each element of a list, in order, until the desired value is found or all elements in the list have been checked.

    来源:美国大学理事会 AP 课程与考试说明

    一个列表(list)是一个名字下的一个有序的值搜集,课程的关键数据抽象。AP 伪代码从 1 索引:

    一个列表在一个变量里持有许多值,每个由它的索引找到
    一个列表在一个变量里持有许多值,每个由它的索引找到
    scores ← [88, 74, 95]
    DISPLAY(scores[1])          // 88
    scores[2] ← 80              // replace the 2nd value
    APPEND(scores, 60)          // add to the end
    INSERT(scores, 1, 100)      // insert at index 1
    REMOVE(scores, 3)           // delete the 3rd element
    LENGTH(scores)              // how many elements
    

    用一个循环遍历一个列表以求和、计数、搜索,或找一个最大值:

    FOR EACH x IN scores
    {
        total ← total + x
    }
    
    词汇表 训练
    英文 中文 拼音
    list 列表 liè biǎo
    3.11

    二分查找

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-2
    The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

    AAP-2.P
    For binary search algorithms:
    a. Determine the number of iterations required to find a value in a data set. [Skill 1.D]
    b. Explain the requirements necessary to complete a binary search. [Skill 1.A]

    • AAP-2.P.1 The binary search algorithm starts at the middle of a sorted data set of numbers and eliminates half of the data; this process repeats until the desired value is found or all elements have been eliminated.
      • Exclusion statement (EK AAP-2.P.1): Specific implementations of the binary search are outside the scope of the course and the AP Exam.
    • AAP-2.P.2 Data must be in sorted order to use the binary search algorithm.
    • AAP-2.P.3 Binary search is often more efficient than sequential/linear search when applied to sorted data.

    来源:美国大学理事会 AP 课程与考试说明

    二分搜索(binary search)在一个排序的列表里比检查每个元素快得多地找到一个值。它看中间的元素,然后丢弃不能包含目标的那一半,重复直到找到。每一步搜索空间减半,所以一个 $n$ 个项的列表取约 $\log_2 n$ 步。它需要数据先被排序

    二分搜索在每一步把范围减半(列表必须被排序)
    二分搜索在每一步把范围减半(列表必须被排序)

    Worked example. 搜索一个 $8$ 个项的排序列表,二分搜索每一步把范围减半:$8\rightarrow4\rightarrow2\rightarrow1$,最多 $3$ 次比较($\log_2 8=3$),而一个线性搜索可能取多达 $8$。优势爆炸式增长:约 $1{,}000$ 个项只需要 $\approx10$ 个二分搜索步(但多达 $1{,}000$ 个线性的),而 $1{,}000{,}000$ 个项只需要 $\approx20$。减半是使它成为一个合理时间算法的东西。

    词汇表 训练
    英文 中文 拼音
    Binary search 二分搜索 èr fēn sōu suǒ
    3.12

    调用过程

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-3
    Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

    AAP-3.A
    For procedure calls:
    a. Write statements to call procedures. [Skill 3.B]
    b. Determine the result or effect of a procedure call. [Skill 4.B]

    • AAP-3.A.1 A procedure is a named group of programming instructions that may have parameters and return values.

    • AAP-3.A.2 Procedures are referred to by different names, such as method or function, depending on the programming language.

    • AAP-3.A.3 Parameters are input variables of a procedure. Arguments specify the values of the parameters when a procedure is called.

    • AAP-3.A.4 A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing. Once the last statement in the procedure (or a return statement) has executed, flow of control is returned to the point immediately following where the procedure was called.

    • AAP-3.A.5 The exam reference sheet provides

      procName(arg1, arg2, ...)

      as a way to call

      Text:

      PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

      Block:

      PROCEDURE procName parameter1, parameter2,... block of statements

      which takes zero or more arguments; arg1 is assigned to parameter1, arg2 is assigned to parameter2, and so on.

    • AAP-3.A.6 The exam reference sheet provides the procedure

      Text:

      DISPLAY(expression)

      Block:

      DISPLAY expression

      to display the value of expression, followed by a space.

    • AAP-3.A.7 The exam reference sheet provides the

      Text:

      RETURN(expression)

      Block:

      RETURN expression

      statement, which is used to return the flow of control to the point where the procedure was called and to return the value of expression.

    • AAP-3.A.8 The exam reference sheet provides

      result ← procName(arg1, arg2, ...)

      to assign to result the "value of the procedure" being returned by calling

      Text:

      PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

      Block:

      PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

    • AAP-3.A.9 The exam reference sheet provides procedure

      Text:

      INPUT()

      Block:

      INPUT

      which accepts a value from the user and returns the input value.

    来源:美国大学理事会 AP 课程与考试说明

    一个过程(函数)(procedure (function))是一个命名的、可重用的代码块。调用它以你提供的实参(arguments)运行它的代码,而它可能返回一个值:

    sum ← Add(3, 4)      // call, passing 3 and 4
    

    过程让你使用代码而不知道它的内部工作——过程抽象(procedural abstraction)。

    词汇表 训练
    英文 中文 拼音
    procedure (function) 过程 guò chéng
    procedural abstraction 过程抽象 guò chéng chōu xiàng
    3.13

    开发过程

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-3
    Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

    AAP-3.B
    Explain how the use of procedural abstraction manages complexity in a program. [Skill 3.C]

    • AAP-3.B.1 One common type of abstraction is procedural abstraction, which provides a name for a process and allows a procedure to be used only knowing what it does, not how it does it.
    • AAP-3.B.2 Procedural abstraction allows a solution to a large problem to be based on the solutions of smaller subproblems. This is accomplished by creating procedures to solve each of the subproblems.
    • AAP-3.B.3 The subdivision of a computer program into separate subprograms is called modularity.
    • AAP-3.B.4 A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for program code reuse, which helps manage complexity.
    • AAP-3.B.5 Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.
    • AAP-3.B.6 Using procedural abstraction helps improve code readability.
    • AAP-3.B.7 Using procedural abstraction in a program allows programmers to change the internals of the procedure (to make it faster, more efficient, use less storage, etc.) without needing to notify users of the change as long as what the procedure does is preserved.

    AAP-3.C
    Develop procedural abstractions to manage complexity in a program by writing procedures. [Skill 3.B]

    • AAP-3.C.1 The exam reference sheet provides

      Text:

      PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

      Block:

      PROCEDURE procName parameter1, parameter2,... block of statements

      which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements.

    • AAP-3.C.2 The exam reference sheet provides

      Text:

      PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

      Block:

      PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

      which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements and returns the value of expression. The RETURN statement may appear at any point inside the procedure and causes an immediate return from the procedure back to the calling statement.

    来源:美国大学理事会 AP 课程与考试说明

    你用一个名字、参数(parameters)(输入)和一个主体定义一个过程,并可选地 RETURN 一个结果:

    把一个程序分解成过程和子过程
    把一个程序分解成过程和子过程
    PROCEDURE Add(a, b)
    {
        RETURN(a + b)
    }
    

    写你自己的过程减少重复、把一个大问题分解成命名的片段,并使程序可读且更容易测试——抽象(abstraction)的本质。

    3.14

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-3
    Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

    AAP-3.D
    Select appropriate libraries or existing code segments to use in creating new programs. [Skill 2.B]

    • AAP-3.D.1 A software library contains procedures that may be used in creating new programs.
    • AAP-3.D.2 Existing code segments can come from internal or external sources, such as libraries or previously written code.
    • AAP-3.D.3 The use of libraries simplifies the task of creating complex programs.
    • AAP-3.D.4 Application program interfaces (APIs) are specifications for how the procedures in a library behave and can be used.
    • AAP-3.D.5 Documentation for an API/library is necessary in understanding the behaviors provided by the API/library and how to use them.

    来源:美国大学理事会 AP 课程与考试说明

    一个(library)是一个其他人能重用的现成过程的搜集。一个 API(应用程序接口,Application Program Interface)记录每个过程做什么、它的参数,和它的结果——所以你能使用它而不看它的代码。库节省时间并让你能建立在现有的、经过测试的工作之上。

    词汇表 训练
    英文 中文 拼音
    library
    Interface 应用程序接口 yìng yòng chéng xù jiē kǒu
    3.15

    随机值

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-3
    Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

    AAP-3.E
    For generating random values:
    a. Write expressions to generate possible values. [Skill 2.B]
    b. Evaluate expressions to determine the possible results. [Skill 4.B]

    • AAP-3.E.1 The exam reference sheet provides

      Text:

      RANDOM(a, b)

      Block:

      RANDOM a, b

      which generates and returns a random integer from a to b, inclusive. Each result is equally likely to occur. For example, RANDOM(1, 3) could return 1, 2, or 3.

    • AAP-3.E.2 Using random number generation in a program means each execution may produce a different result.

    来源:美国大学理事会 AP 课程与考试说明

    RANDOM(a, b) 返回一个从 ab(含)的随机整数,让一个程序产生不可预测的结果——用于游戏、抽样,或模拟。每个调用可能给出一个不同的值,所以一个使用随机性的程序每次运行行为不同。

    3.16

    模拟

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-3
    Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

    AAP-3.F
    For simulations:
    a. Explain how computers can be used to represent real-world phenomena or outcomes. [Skill 1.A]
    b. Compare simulations with real-world contexts. [Skill 1.D]

    • AAP-3.F.1 Simulations are abstractions of more complex objects or phenomena for a specific purpose.
    • AAP-3.F.2 A simulation is a representation that uses varying sets of values to reflect the changing state of a phenomenon.
    • AAP-3.F.3 Simulations often mimic real-world events with the purpose of drawing inferences, allowing investigation of a phenomenon without the constraints of the real world.
    • AAP-3.F.4 The process of developing an abstract simulation involves removing specific details or simplifying functionality.
    • AAP-3.F.5 Simulations can contain bias derived from the choices of real-world elements that were included or excluded.
    • AAP-3.F.6 Simulations are most useful when real-world events are impractical for experiments (e.g., too big, too small, too fast, too slow, too expensive, or too dangerous).
    • AAP-3.F.7 Simulations facilitate the formulation and refinement of hypotheses related to the objects or phenomena under consideration.
    • AAP-3.F.8 Random number generators can be used to simulate the variability that exists in the real world.

    来源:美国大学理事会 AP 课程与考试说明

    一个模拟(simulation)是一个为一个现实世界过程建模以安全而廉价地研究它的程序。模拟简化现实(它们省略细节)并常常用随机性来模仿偶然事件。它们让你测试在现实生活里会太昂贵、缓慢或危险的场景——但它们的结果只与它们的假设一样好。

    词汇表 训练
    英文 中文 拼音
    simulation 模拟 mó nǐ
    3.17

    算法效率

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-4
    There exist problems that computers cannot solve, and even when a computer can solve a problem, it may not be able to do so in a reasonable amount of time.

    AAP-4.A
    For determining the efficiency of an algorithm:
    a. Explain the difference between algorithms that run in reasonable time and those that do not. [Skill 1.D]
    b. Identify situations where a heuristic solution may be more appropriate. [Skill 1.D]

    • AAP-4.A.1 A problem is a general description of a task that can (or cannot) be solved algorithmically. An instance of a problem also includes specific input. For example, sorting is a problem; sorting the list (2,3,1,7) is an instance of the problem.
    • AAP-4.A.2 A decision problem is a problem with a yes/no answer (e.g., is there a path from A to B?). An optimization problem is a problem with the goal of finding the "best" solution among many (e.g., what is the shortest path from A to B?).
    • AAP-4.A.3 Efficiency is an estimation of the amount of computational resources used by an algorithm. Efficiency is typically expressed as a function of the size of the input.
      • Exclusion statement (EK AAP-4.A.3): Formal analysis of algorithms (Big-O) and formal reasoning using mathematical formulas are outside the scope of this course and the AP Exam.
    • AAP-4.A.4 An algorithm's efficiency is determined through formal or mathematical reasoning.
    • AAP-4.A.5 An algorithm's efficiency can be informally measured by determining the number of times a statement or group of statements executes.
    • AAP-4.A.6 Different correct algorithms for the same problem can have different efficiencies.
    • AAP-4.A.7 Algorithms with a polynomial efficiency or slower (constant, linear, square, cube, etc.) are said to run in a reasonable amount of time. Algorithms with exponential or factorial efficiencies are examples of algorithms that run in an unreasonable amount of time.
    • AAP-4.A.8 Some problems cannot be solved in a reasonable amount of time because there is no efficient algorithm for solving them. In these cases, approximate solutions are sought.
    • AAP-4.A.9 A heuristic is an approach to a problem that produces a solution that is not guaranteed to be optimal but may be used when techniques that are guaranteed to always find an optimal solution are impractical.
      • Exclusion statement (AAP-4.A.9): Specific heuristic solutions are outside the scope of this course and the AP Exam.

    来源:美国大学理事会 AP 课程与考试说明

    效率(efficiency)是一个算法随着它的输入增长需要多少时间(或内存)。一个合理时间(reasonable-time)算法的工作像输入大小的一个多项式那样增长(例如线性或二次);一个不合理时间(unreasonable-time)算法增长得远快(例如每加一个项就加倍),对大输入变得不切实际。一个更快的算法能使一个先前不可能的问题可解。有时一个精确答案取太久,所以一个启发式(heuristic)——一个快速找到一个足够好答案的方法——被改用。

    一个算法的运行时间如何随输入大小 n 增长
    一个算法的运行时间如何随输入大小 n 增长
    词汇表 训练
    英文 中文 拼音
    Efficiency 效率 xiào lǜ
    heuristic 启发式 qǐ fā shì
    3.18

    不可判定问题

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    AAP-4
    There exist problems that computers cannot solve, and even when a computer can solve a problem, it may not be able to do so in a reasonable amount of time.

    AAP-4.B
    Explain the existence of undecidable problems in computer science. [Skill 1.A]

    • AAP-4.B.1 A decidable problem is a decision problem for which an algorithm can be written to produce a correct output for all inputs (e.g., "Is the number even?").
    • AAP-4.B.2 An undecidable problem is one for which no algorithm can be constructed that is always capable of providing a correct yes-or-no answer.
      • Exclusion statement (EK AAP-4.B.2): Determining whether a given problem is undecidable is outside the scope of this course and the AP Exam.
    • AAP-4.B.3 An undecidable problem may have some instances that have an algorithmic solution, but there is no algorithmic solution that could solve all instances of the problem.

    来源:美国大学理事会 AP 课程与考试说明

    一些问题是不可判定(undecidable)的:没有算法能用一个正确的是/否答案解决它们的每个情况。这是计算的一个根本限制——不是需要一台更快计算机的问题,而是没有这样的算法能存在的一个证明。

    考试技能: 能够通过跟踪确定一个代码段的结果、比较两个算法的效率(合理 vs 不合理时间),并在一个程序里辨认过程和数据抽象。

    词汇表 训练
    英文 中文 拼音
    undecidable 不可判定 bù kě pàn dìng
    3.18

    考试技巧

    • 知道一个变量是一个值的命名存储并逐步跟踪赋值如何更新它。
    • 仔细读 AP 伪代码——a <- expression 赋值,而列表在考试参考表上是1 索引的。
    • 把一个变量与一个列表(一个由索引访问的搜集)区分开并正确地使用列表操作。
    • 用正确的优先级和布尔逻辑(ANDORNOT)求表达式的值。
    • 挑选清晰的、有意义的变量名——书面任务奖励可读的代码。
  • 4

    计算机系统与网络

    讲义 词汇表
    4.1

    互联网

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CSN-1
    Computer systems and networks facilitate the transfer of data.

    CSN-1.A
    Explain how computing devices work together in a network. [Skill 5.A]

    • CSN-1.A.1 A computing device is a physical artifact that can run a program. Some examples include computers, tablets, servers, routers, and smart sensors.
    • CSN-1.A.2 A computing system is a group of computing devices and programs working together for a common purpose.
    • CSN-1.A.3 A computer network is a group of interconnected computing devices capable of sending or receiving data.
    • CSN-1.A.4 A computer network is a type of computing system.
    • CSN-1.A.5 A path between two computing devices on a computer network (a sender and a receiver) is a sequence of directly connected computing devices that begins at the sender and ends at the receiver.
    • CSN-1.A.6 Routing is the process of finding a path from sender to receiver.
    • CSN-1.A.7 The bandwidth of a computer network is the maximum amount of data that can be sent in a fixed amount of time.
    • CSN-1.A.8 Bandwidth is usually measured in bits per second.

    CSN-1.B
    Explain how the Internet works. [Skill 5.A]

    • CSN-1.B.1 The Internet is a computer network consisting of interconnected networks that use standardized, open (nonproprietary) communication protocols.
    • CSN-1.B.2 Access to the Internet depends on the ability to connect a computing device to an Internet-connected device.
    • CSN-1.B.3 A protocol is an agreed-upon set of rules that specify the behavior of a system.
    • CSN-1.B.4 The protocols used in the Internet are open, which allows users to easily connect additional computing devices to the Internet.
    • CSN-1.B.5 Routing on the Internet is usually dynamic; it is not specified in advance.
    • CSN-1.B.6 The scalability of a system is the capacity for the system to change in size and scale to meet new demands.
    • CSN-1.B.7 The Internet was designed to be scalable.

    CSN-1.C
    Explain how data are sent through the Internet via packets. [Skill 5.A]

    • CSN-1.C.1 Information is passed through the Internet as a data stream. Data streams contain chunks of data, which are encapsulated in packets.
    • CSN-1.C.2 Packets contain a chunk of data and metadata used for routing the packet between the origin and the destination on the Internet, as well as for data reassembly.
    • CSN-1.C.3 Packets may arrive at the destination in order, out of order, or not at all.
    • CSN-1.C.4 IP, TCP, and UDP are common protocols used on the Internet.

    CSN-1.D
    Describe the differences between the Internet and the World Wide Web. [Skill 5.A]

    • CSN-1.D.1 The World Wide Web is a system of linked pages, programs, and files.
    • CSN-1.D.2 HTTP is a protocol used by the World Wide Web.
    • CSN-1.D.3 The World Wide Web uses the Internet.

    来源:美国大学理事会 AP 课程与考试说明

    互联网(Internet)是一个网络的全球网络。数据作为数据包(packets)传播——被分开发送并在目的地重新组装的小块。两个思想使它在规模上起作用:

    互联网是全世界的网络;万维网是运行在它上面的一个服务
    互联网是全世界的网络;万维网是运行在它上面的一个服务
    • 协议(protocols)是通信的约定规则。IP(网际协议,Internet Protocol)寻址和路由数据包;TCP 按顺序重新组装它们并重新请求丢失的;HTTP 携带网页;DNS 把一个像 example.com 的名字翻译成一个 IP 地址。
    • 冗余(redundancy)和路由:两点之间有许多可能的路径,所以若一条路径失败,数据包走另一条。这使互联网容错(fault-tolerant)。

    互联网被设计为开放(open)和可扩展(scalable)——建立在任何人都能使用的标准上,所以随着数十亿设备加入它继续工作。带宽(bandwidth)是一个连接每秒能携带的数据量。

    探索

    How data crosses the Internet in packets

    The Internet breaks a message into numbered packets, each addressed and routed independently (often by different paths), then reassembled at the destination. That design makes it fault-tolerant — if one route fails, packets take another.

    词汇表 训练
    英文 中文 拼音
    Internet 互联网 hù lián wǎng
    packets 数据包 shù jù bāo
    Protocols 协议 xié yì
    Redundancy 冗余 rǒng yú
    fault-tolerant 容错 róng cuò
    Bandwidth 带宽 dài kuān
    4.2

    容错

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CSN-1
    Computer systems and networks facilitate the transfer of data.

    CSN-1.E
    For fault-tolerant systems, like the Internet:
    a. Describe the benefits of fault tolerance. [Skill 1.D]
    b. Explain how a given system is fault-tolerant. [Skill 5.A]
    c. Identify vulnerabilities to failure in a system. [Skill 1.D]

    • CSN-1.E.1 The Internet has been engineered to be fault-tolerant, with abstractions for routing and transmitting data.
    • CSN-1.E.2 Redundancy is the inclusion of extra components that can be used to mitigate failure of a system if other components fail.
    • CSN-1.E.3 One way to accomplish network redundancy is by having more than one path between any two connected devices.
    • CSN-1.E.4 If a particular device or connection on the Internet fails, subsequent data will be sent via a different route, if possible.
    • CSN-1.E.5 When a system can support failures and still continue to function, it is called fault-tolerant. This is important because elements of complex systems fail at unexpected times, often in groups, and fault tolerance allows users to continue to use the network.
    • CSN-1.E.6 Redundancy within a system often requires additional resources but can provide the benefit of fault tolerance.
    • CSN-1.E.7 The redundancy of routing options between two points increases the reliability of the Internet and helps it scale to more devices and more people.

    来源:美国大学理事会 AP 课程与考试说明

    一个系统是容错(fault-tolerant)的,若它即使在它的一部分失败时也继续工作。互联网通过冗余(redundant)连接实现这个:因为数据包能沿多条路径路由,一个路由器或电缆的失败不停止通信——流量只是重新路由。容错花费额外的资源(冗余的路径)但大大改善可靠性(reliability)。一条没有备份的单一路径不是容错的。

    数据包交换按独立的路由发送数据包,所以网络容忍一个失败的链路
    数据包交换按独立的路由发送数据包,所以网络容忍一个失败的链路
    词汇表 训练
    英文 中文 拼音
    reliability 可靠性 kě kào xìng
    4.3

    并行与分布式计算

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    CSN-2
    Parallel and distributed computing leverage multiple computers to more quickly solve complex problems or process large data sets.

    CSN-2.A
    For sequential, parallel, and distributed computing:
    a. Compare problem solutions. [Skill 1.D]
    b. Determine the efficiency of solutions. [Skill 1.D]

    • CSN-2.A.1 Sequential computing is a computational model in which operations are performed in order one at a time.
    • CSN-2.A.2 Parallel computing is a computational model where the program is broken into multiple smaller sequential computing operations, some of which are performed simultaneously.
    • CSN-2.A.3 Distributed computing is a computational model in which multiple devices are used to run a program.
    • CSN-2.A.4 Comparing efficiency of solutions can be done by comparing the time it takes them to perform the same task.
    • CSN-2.A.5 A sequential solution takes as long as the sum of all of its steps.
    • CSN-2.A.6 A parallel computing solution takes as long as its sequential tasks plus the longest of its parallel tasks.
    • CSN-2.A.7 The "speedup" of a parallel solution is measured in the time it took to complete the task sequentially divided by the time it took to complete the task when done in parallel.

    CSN-2.B
    Describe benefits and challenges of parallel and distributed computing. [Skill 1.D]

    • CSN-2.B.1 Parallel computing consists of a parallel portion and a sequential portion.
    • CSN-2.B.2 Solutions that use parallel computing can scale more effectively than solutions that use sequential computing.
    • CSN-2.B.3 Distributed computing allows problems to be solved that could not be solved on a single computer because of either the processing time or storage needs involved.
    • CSN-2.B.4 Distributed computing allows much larger problems to be solved quicker than they could be solved using a single computer.
    • CSN-2.B.5 When increasing the use of parallel computing in a solution, the efficiency of the solution is still limited by the sequential portion. This means that at some point, adding parallel portions will no longer meaningfully increase efficiency.

    来源:美国大学理事会 AP 课程与考试说明

    • 顺序计算(sequential computing)一次运行一个操作。
    • 并行计算(parallel computing)把一个任务分成同时在多个处理器上运行的部分,更快地完成。
    • 分布式计算(distributed computing)使用由一个网络连接的许多计算机来处理一个问题——对于对单台机器太大的问题至关重要。
    并行计算:许多处理器同时工作
    并行计算:许多处理器同时工作

    一个并行解决方案的加速比(speedup)是顺序时间除以并行时间。加速比是有限的:必须按顺序运行的部分不能通过添加处理器加速,所以把处理器加倍很少使速度加倍。

    Worked example. 一个任务有一个必须按顺序运行的部分,取 $40$ 秒,加一个在一个处理器上取 $60$ 秒的可并行部分——所以在单个处理器上整个任务取 $40+60=100$ 秒。把并行部分分散到 $3$ 个处理器上它取 $\tfrac{60}{3}=20$ 秒,所以总并行时间是 $40+20=60$ 秒而加速比是 $\tfrac{100}{60}\approx1.67$。这 $40$ 秒的顺序部分是一个下限:即使有无穷多个处理器任务也从不能在 $40$ 秒以下完成。

    考试技能: 给定一个任务顺序和并行部分的时间,能够计算总并行时间和加速比。

    词汇表 训练
    英文 中文 拼音
    Sequential computing 顺序计算 shùn xù jì suàn
    Parallel computing 并行计算 bìng xíng jì suàn
    Distributed computing 分布式计算 fēn bù shì jì suàn
    speedup 加速比 jiā sù bǐ
    4.3

    考试技巧

    • 描述数据如何在一个冗余的、容错的独立路由器网络上以数据包传播。
    • 知道协议(IP、TCP、HTTP)是约定的规则,以及开放的标准让不同的系统互操作。
    • 解释可扩展性以及互联网如何在没有中央控制的情况下增长。
    • 对比带宽(速率)与延迟(latency)(时延),并描述 DNS 名字到地址的查找。
    • 用平实的措辞讨论数字鸿沟(digital divide)和安全基础(加密、身份验证)。
  • 5

    计算的影响

    讲义 词汇表
    5.1

    有益与有害的影响

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-1
    While computing innovations are typically designed to achieve a specific purpose, they may have unintended consequences.

    IOC-1.A
    Explain how an effect of a computing innovation can be both beneficial and harmful. [Skill 5.C]

    • IOC-1.A.1 People create computing innovations.
    • IOC-1.A.2 The way people complete tasks often changes to incorporate new computing innovations.
    • IOC-1.A.3 Not every effect of a computing innovation is anticipated in advance.
    • IOC-1.A.4 A single effect can be viewed as both beneficial and harmful by different people, or even by the same person.
    • IOC-1.A.5 Advances in computing have generated and increased creativity in other fields, such as medicine, engineering, communications, and the arts.

    IOC-1.B
    Explain how a computing innovation can have an impact beyond its intended purpose. [Skill 5.C]

    • IOC-1.B.1 Computing innovations can be used in ways that their creators had not originally intended:
      • The World Wide Web was originally intended only for rapid and easy exchange of information within the scientific community.
      • Targeted advertising is used to help businesses, but it can be misused at both individual and aggregate levels.
      • Machine learning and data mining have enabled innovation in medicine, business, and science, but information discovered in this way has also been used to discriminate against groups of individuals.
    • IOC-1.B.2 Some of the ways computing innovations can be used may have a harmful impact on society, the economy, or culture.
    • IOC-1.B.3 Responsible programmers try to consider the unintended ways their computing innovations can be used and the potential beneficial and harmful effects of these new uses.
    • IOC-1.B.4 It is not possible for a programmer to consider all the ways a computing innovation can be used.
    • IOC-1.B.5 Computing innovations have often had unintended beneficial effects by leading to advances in other fields.
    • IOC-1.B.6 Rapid sharing of a program or running a program with a large number of users can result in significant impacts beyond the intended purpose or control of the programmer.

    来源:美国大学理事会 AP 课程与考试说明

    每个计算创新都能以帮助的方式和伤害的方式被使用——常常同一个技术两者都做。一个社交网络连接人们并且能传播错误信息;自动化提高生产率并且能除去工作。效应频繁是意料之外的:创造者不能预见每一种使用。当你评价一个计算创新时,权衡它对人们和社会的好处和害处,并记住害处不总是故意的。

    计算以几种方式影响公众的福祉
    计算以几种方式影响公众的福祉
    5.2

    数字鸿沟

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-1
    While computing innovations are typically designed to achieve a specific purpose, they may have unintended consequences.

    IOC-1.C
    Describe issues that contribute to the digital divide. [Skill 5.C]

    • IOC-1.C.1 Internet access varies between socioeconomic, geographic, and demographic characteristics, as well as between countries.
    • IOC-1.C.2 The "digital divide" refers to differing access to computing devices and the Internet, based on socioeconomic, geographic, or demographic characteristics.
    • IOC-1.C.3 The digital divide can affect both groups and individuals.
    • IOC-1.C.4 The digital divide raises issues of equity, access, and influence, both globally and locally.
    • IOC-1.C.5 The digital divide is affected by the actions of individuals, organizations, and governments.

    来源:美国大学理事会 AP 课程与考试说明

    数字鸿沟(digital divide)是跨群体——按收入、地理、年龄或国家——对计算和互联网的不平等访问。那些有访问的获得教育、工作和服务;那些没有的进一步落后。这个鸿沟由经济、社会和地理因素塑造,而弥合它的努力(可负担的设备、公共访问、基础设施)旨在使计算的好处更公平。

    Public library computers: digital divide is about unequal access to devices, connectivity and skills
    Public library computers: digital divide is about unequal access to devices, connectivity and skills
    A rural satellite dish: geography still shapes who gets fast internet and who waits
    A rural satellite dish: geography still shapes who gets fast internet and who waits
    词汇表 训练
    英文 中文 拼音
    digital divide 数字鸿沟 shù zì hóng gōu
    5.3

    计算偏见

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-1
    While computing innovations are typically designed to achieve a specific purpose, they may have unintended consequences.

    IOC-1.D
    Explain how bias exists in computing innovations. [Skill 5.E]

    • IOC-1.D.1 Computing innovations can reflect existing human biases because of biases written into the algorithms or biases in the data used by the innovation.
    • IOC-1.D.2 Programmers should take action to reduce bias in algorithms used for computing innovations as a way of combating existing human biases.
    • IOC-1.D.3 Biases can be embedded at all levels of software development.

    来源:美国大学理事会 AP 课程与考试说明

    偏见(bias)能被建入计算系统——常常无意地。若用来构建一个系统的数据反映现存的偏见,或若设计者的假设是片面的,系统能产生不公平的结果(例如,一个偏爱一个群体的招聘工具)。偏见能在每个阶段进入——数据收集、设计和使用——所以系统应当被跨不同群体测试公平性。认识到"计算机这么说的"不等于"公平"是一个重要的习惯。

    词汇表 训练
    英文 中文 拼音
    Bias 偏见 piān jiàn
    5.4

    众包

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-1
    While computing innovations are typically designed to achieve a specific purpose, they may have unintended consequences.

    IOC-1.E
    Explain how people participate in problem-solving processes at scale. [Skill 1.C]

    • IOC-1.E.1 Widespread access to information and public data facilitates the identification of problems, development of solutions, and dissemination of results.
    • IOC-1.E.2 Science has been affected by using distributed and "citizen science" to solve scientific problems.
    • IOC-1.E.3 Citizen science is scientific research conducted in whole or part by distributed individuals, many of whom may not be scientists, who contribute relevant data to research using their own computing devices.
    • IOC-1.E.4 Crowdsourcing is the practice of obtaining input or information from a large number of people via the Internet.
    • IOC-1.E.5 Human capabilities can be enhanced by collaboration via computing.
    • IOC-1.E.6 Crowdsourcing offers new models for collaboration, such as connecting businesses or social causes with funding.

    来源:美国大学理事会 AP 课程与考试说明

    众包(crowdsourcing)从一大群人——通常在网上——获得输入、想法或资金。它利用许多人的知识和努力——地图项目、产品评论、公民科学,和众筹(crowdfunding)都依赖它。互联网使众包以一个前所未有可达到的规模和速度成为可能,让一个项目借助全世界的贡献者。

    A Wikipedia edit-a-thon: crowdsourcing pools many people's work into a shared resource
    A Wikipedia edit-a-thon: crowdsourcing pools many people's work into a shared resource
    词汇表 训练
    英文 中文 拼音
    Crowdsourcing 众包 zhòng bāo
    5.5

    法律与伦理问题

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-1
    While computing innovations are typically designed to achieve a specific purpose, they may have unintended consequences.

    IOC-1.F
    Explain how the use of computing can raise legal and ethical concerns. [Skill 5.E]

    • IOC-1.F.1 Material created on a computer is the intellectual property of the creator or an organization.
    • IOC-1.F.2 Ease of access and distribution of digitized information raises intellectual property concerns regarding ownership, value, and use.
    • IOC-1.F.3 Measures should be taken to safeguard intellectual property.
    • IOC-1.F.4 The use of material created by someone else without permission and presented as one's own is plagiarism and may have legal consequences.
    • IOC-1.F.5 Some examples of legal ways to use materials created by someone else include:
      • Creative Commons—a public copyright license that enables the free distribution of an otherwise copyrighted work. This is used when the content creator wants to give others the right to share, use, and build upon the work they have created.
      • open source—programs that are made freely available and may be redistributed and modified
      • open access—online research output free of any and all restrictions on access and free of many restrictions on use, such as copyright or license restrictions
    • IOC-1.F.6 The use of material created by someone other than you should always be cited.
    • IOC-1.F.7 Creative Commons, open source, and open access have enabled broad access to digital information.
    • IOC-1.F.8 As with any technology or medium, using computing to harm individuals or groups of people raises legal and ethical concerns.
    • IOC-1.F.9 Computing can play a role in social and political issues, which in turn often raises legal and ethical concerns.
    • IOC-1.F.10 The digital divide raises ethical concerns around computing.
    • IOC-1.F.11 Computing innovations can raise legal and ethical concerns. Some examples of these include:
      • the development of software that allows access to digital media downloads and streaming
      • the development of algorithms that include bias
      • the existence of computing devices that collect and analyze data by continuously monitoring activities

    来源:美国大学理事会 AP 课程与考试说明

    计算提出法律和道德的问题:

    • 知识产权(intellectual property)和版权(copyright)保护创造者的作品;使用它可能需要许可或一个许可证。开源(open-source)和知识共享(Creative Commons)许可证让创造者在陈述的条款下分享作品。
    • 抄袭(plagiarism)——把其他人的作品当作你自己的——是不道德的且常常是非法的。
    • 收集和使用个人数据引发关于同意和误用的隐私问题。

    仅仅因为某事在技术上可能不使它合法或道德。

    词汇表 训练
    英文 中文 拼音
    Intellectual property 知识产权 zhī shí chǎn quán
    copyright 版权 bǎn quán
    Open-source 开源 kāi yuán
    Plagiarism 抄袭 chāo xí
    5.6

    安全计算

    大纲
    Enduring UnderstandingLearning ObjectiveEssential Knowledge

    IOC-2
    The use of computing innovations may involve risks to personal safety and identity.

    IOC-2.A
    Describe the risks to privacy from collecting and storing personal data on a computer system. [Skill 5.D]

    • IOC-2.A.1 Personally identifiable information (PII) is information about an individual that identifies, links, relates, or describes them. Examples of PII include:
      • Social Security number
      • age
      • race
      • phone number(s)
      • medical information
      • financial information
      • biometric data
    • IOC-2.A.2 Search engines can record and maintain a history of searches made by users.
    • IOC-2.A.3 Websites can record and maintain a history of individuals who have viewed their pages.
    • IOC-2.A.4 Devices, websites, and networks can collect information about a user's location.
    • IOC-2.A.5 Technology enables the collection, use, and exploitation of information about, by, and for individuals, groups, and institutions.
    • IOC-2.A.6 Search engines can use search history to suggest websites or for targeted marketing.
    • IOC-2.A.7 Disparate personal data, such as geolocation, cookies, and browsing history, can be aggregated to create knowledge about an individual.
    • IOC-2.A.8 PII and other information placed online can be used to enhance a user's online experiences.
    • IOC-2.A.9 PII stored online can be used to simplify making online purchases.
    • IOC-2.A.10 Commercial and governmental curation of information may be exploited if privacy and other protections are ignored.
    • IOC-2.A.11 Information placed online can be used in ways that were not intended and that may have a harmful impact. For example, an email message may be forwarded, tweets can be retweeted, and social media posts can be viewed by potential employers.
    • IOC-2.A.12 PII can be used to stalk or steal the identity of a person or to aid in the planning of other criminal acts.
    • IOC-2.A.13 Once information is placed online, it is difficult to delete.
    • IOC-2.A.14 Programs can collect your location and record where you have been, how you got there, and how long you were at a given location.
    • IOC-2.A.15 Information posted to social media services can be used by others. Combining information posted on social media and other sources can be used to deduce private information about you.

    IOC-2.B
    Explain how computing resources can be protected and can be misused. [Skill 5.E]

    • IOC-2.B.1 Authentication measures protect devices and information from unauthorized access. Examples of authentication measures include strong passwords and multifactor authentication.
    • IOC-2.B.2 A strong password is something that is easy for a user to remember but would be difficult for someone else to guess based on knowledge of that user.
    • IOC-2.B.3 Multifactor authentication is a method of computer access control in which a user is only granted access after successfully presenting several separate pieces of evidence to an authentication mechanism, typically in at least two of the following categories: knowledge (something they know), possession (something they have), and inherence (something they are).
    • IOC-2.B.4 Multifactor authentication requires at least two steps to unlock protected information; each step adds a new layer of security that must be broken to gain unauthorized access.
    • IOC-2.B.5 Encryption is the process of encoding data to prevent unauthorized access. Decryption is the process of decoding the data. Two common encryption approaches are:
      • Symmetric key encryption involves one key for both encryption and decryption.
      • Public key encryption pairs a public key for encryption and a private key for decryption. The sender does not need the receiver's private key to encrypt a message, but the receiver's private key is required to decrypt the message.
      • Exclusion statement (EK IOC-2.B.5): Specific mathematical procedures for encryption and decryption are beyond the scope of this course and the AP Exam.
    • IOC-2.B.6 Certificate authorities issue digital certificates that validate the ownership of encryption keys used in secure communications and are based on a trust model.
    • IOC-2.B.7 Computer virus and malware scanning software can help protect a computing system against infection.
    • IOC-2.B.8 A computer virus is a malicious program that can copy itself and gain access to a computer in an unauthorized way. Computer viruses often attach themselves to legitimate programs and start running independently on a computer.
    • IOC-2.B.9 Malware is software intended to damage a computing system or to take partial control over its operation.
    • IOC-2.B.10 All real-world systems have errors or design flaws that can be exploited to compromise them. Regular software updates help fix errors that could compromise a computing system.
    • IOC-2.B.11 Users can control the permissions programs have for collecting user information. Users should review the permission settings of programs to protect their privacy.

    IOC-2.C
    Explain how unauthorized access to computing resources is gained. [Skill 5.E]

    • IOC-2.C.1 Phishing is a technique that attempts to trick a user into providing personal information. That personal information can then be used to access sensitive online resources, such as bank accounts and emails.
    • IOC-2.C.2 Keylogging is the use of a program to record every keystroke made by a computer user in order to gain fraudulent access to passwords and other confidential information.
    • IOC-2.C.3 Data sent over public networks can be intercepted, analyzed, and modified. One way that this can happen is through a rogue access point.
    • IOC-2.C.4 A rogue access point is a wireless access point that gives unauthorized access to secure networks.
    • IOC-2.C.5 A malicious link can be disguised on a web page or in an email message.
    • IOC-2.C.6 Unsolicited emails, attachments, links, and forms in emails can be used to compromise the security of a computing system. These can come from unknown senders or from known senders whose security has been compromised.
    • IOC-2.C.7 Untrustworthy (often free) downloads from freeware or shareware sites can contain malware.

    来源:美国大学理事会 AP 课程与考试说明

    保护个人数据是一个共同的责任。关键思想:

    加密用一个密钥打乱明文;只有密钥能解密它
    加密用一个密钥打乱明文;只有密钥能解密它
    • 个人身份信息(PII)(personally identifiable information)(名字、地址、ID 号码)应当被小心地分享,因为它能被误用于身份盗窃(identity theft)。
    • 威胁包括网络钓鱼(phishing)(诱骗你透露信息)、恶意软件(malware),和弱密码。
    • 防御包括强的、唯一的密码(passwords)、多因素认证(multi-factor authentication)、加密(encryption)(打乱数据,以便只有授权的人能读它),和保持软件更新。

    加密是保持数据在传输和存储中私密的核心工具。作为一个负责任的计算机用户意味着保护你自己和其他人的信息。

    考试技能: 能够辨别一个给定创新的有益和有害效应、解释一个隐私或安全风险,并命名一个应对它的安全计算做法。

    Worked example. 一个招聘算法用一家公司过去的雇员(大多来自一个群体)训练,然后它拒绝了其他群体中合格的申请者。说出问题和它的原因:这是计算偏见,由有偏的训练数据引起——模型学到了历史格局而不是一个公平的规则。一个满分考试答案要说出危害(合格的人被不公平地拒绝)并且它的原因(偏见来自数据,而不是代码)。

    探索

    Scramble a message with encryption

    Encryption protects data by scrambling it with a key; only someone with the key can read it back. This simple Caesar cipher shifts each letter — real encryption uses the same idea with far stronger keys to keep passwords and messages safe.

    词汇表 训练
    英文 中文 拼音
    Personally identifiable information (PII) 个人身份信息 gè rén shēn fèn xìn xī
    identity theft 身份盗窃 shēn fèn dào qiè
    phishing 网络钓鱼 wǎng luò diào yú
    malware 恶意软件 è yì ruǎn jiàn
    multi-factor authentication 多因素认证 duō yīn sù rèn zhèng
    encryption 加密 jiā mì
    5.6

    考试技巧

    • 论证一个计算创新的两个有益和有害效应——一个平衡的答案得分最好。
    • 对数据顾虑使用正确的术语:PII、隐私、安全,和算法偏见
    • 解释众包和大数据集如何创造价值并引发新的风险。
    • 数字鸿沟(访问)与偏见(公平)区分开并给出每个的一个具体例子。
    • 把每个主张与一个具体的创新和效应联系起来,正如书面回答所要求。

登录或创建账号

IGCSE, A-Level & AP