← All Units← 返回单元列表 ← Course Hub← 课程主页
A P C O M P U T E R S C I E N C E P R I N C I P L E S
Unit 3 · Algorithms and Programming第 3 单元 · 算法与编程

Algorithms and Programming算法与编程

AP-Style MC Practice QuestionsAP 风格选择题练习

MEDIUM HARD AP MC

Unit 3: Algorithms and Programming第 3 单元:算法与编程CSP



Name:姓名:Date:日期:
MULTIPLE CHOICE15 questions · ~26 min at exam pace15 道题 · 考试节奏约 26 分钟

Multiple Choice选择题(Multiple Choice)

Choose the best answer. Items marked Select two answers have exactly two correct choices. Code uses the AP CSP Exam Reference Sheet pseudocode: list indices start at 1, and a ← b assigns the value of b to a.选择最合适的答案。标有选择两个答案的题目恰好有两个正确选项。代码使用 AP CSP 考试参考表的伪代码:列表下标从 1 开始,a ← b 表示把 b 的值赋给 a。

Q1MEDIUMAP MC3.1 Variables and Assignments[1]

Consider the following code segment.请考虑以下代码段。

a ← 17
b ← a
 a ← a MOD 5
b ← b / 5
DISPLAY(a)
DISPLAY(b)

What is displayed?显示的结果是什么?

Q2HARDAP MC3.2 Data Abstraction[1]

A program stores related readings in a list and then makes a copy.程序将相关读数存储在一个列表(list)中,然后创建其副本。

readings ← [8, 3, 6]
backup ← readings
REMOVE(readings, 2)
INSERT(backup, 2, 9)
DISPLAY(readings[2])
DISPLAY(backup[3])

What is displayed?显示的结果是什么?

Q3MEDIUMAP MC3.4 Strings[1]

A label maker takes the first three characters of the string ORCHID, then the last two characters, and concatenates them in that order.标签制作程序先取字符串(string)ORCHID 的前三个字符,再取最后两个字符,并按此顺序拼接。

What string does the label maker produce?标签制作程序生成什么字符串?

Q4HARDAP MC3.7 Nested Conditionals[1]

A program assigns a category based on a score and absences.程序根据分数和缺勤次数确定类别。

score ← 75
absences ← 2
IF(score ≥ 70)
{
  IF(absences < 2)
  {
    DISPLAY(1)
  }
  ELSE
  {
    DISPLAY(2)
  }
}
ELSE
{
  DISPLAY(3)
}
DISPLAY(score MOD 10)

What is displayed?显示的结果是什么?

Q5HARDAP MC3.8 Iteration[1]

Consider the following code segment.请考虑以下代码段。

x ← 4
REPEAT UNTIL(x ≥ 4)
{
  x ← x + 100
}
REPEAT UNTIL(x ≥ 11)
{
  x ← x + 3
DISPLAY(x)
}

What is displayed?显示的结果是什么?

Q6HARDAP MC3.9 Developing Algorithms[1]

A robot is on a 5 by 5 grid. Coordinates increase eastward and northward. It starts at (2, 2), facing east. The only black squares are (4, 2) and (3, 4); all other squares are open.机器人(robot)位于一个 5 行 5 列的网格上。坐标向东和向北增大。机器人从 (2, 2) 出发,朝东。只有 (4, 2) 和 (3, 4) 是黑色方格,其余方格均可通行。

REPEAT 3 TIMES
{
  IF(CAN_MOVE(forward))
  {
    MOVE_FORWARD()
  }
  ELSE
  {
    ROTATE_LEFT()
    MOVE_FORWARD()
  }
}

Where is the robot, and which direction is it facing, after the code finishes?代码执行结束后,机器人位于何处、朝向哪个方向?

Q7HARDAP MC3.5 Boolean Expressions[1]

A service admits users whose integer age is from 18 through 65, inclusive.某服务允许整数年龄在 18 至 65 岁之间的用户使用,包含两个端点。

Which two expressions are true exactly for the admitted ages? Select two answers. Select two answers.以下哪两个表达式恰好在年龄符合要求时为真?请选择两个答案。 选择两个答案。

Q8HARDAP MC3.10 Lists[1]

The following code removes selected values from a list.以下代码从列表(list)中删除指定的值。

values ← [4, 2, 2, 5, 2]
i ← 1
REPEAT UNTIL(i > LENGTH(values))
{
  IF(values[i] = 2)
  {
    REMOVE(values, i)
  }
  ELSE
  {
    i ← i + 1
  }
}

What is the value of values when the loop ends?循环结束时,values 的值是什么?

Q9MEDIUMAP MC3.11 Binary Search[1]

A school wants to find an ID in a list. The list is currently in the order in which IDs were issued, not in numerical order.学校要在一个列表(list)中查找某个编号。该列表目前按编号发放顺序排列,而不是按数值顺序排列。

Which change makes binary search applicable to this list?进行哪项更改后,可以对该列表使用二分查找(binary search)?

Q10HARDAP MC3.12 Calling Procedures[1]

The procedure returns the index of the first list element greater than a limit, or -1 if none exists.该过程(procedure)返回列表中第一个大于指定上限的元素的索引;若不存在这样的元素,则返回 -1。

PROCEDURE FirstAbove(items, limit)
{
  i ← 1
REPEAT UNTIL(i > LENGTH(items))
  {
    IF(items[i] > limit)
    {
      RETURN(i)
    }
    i ← i + 1
  }
  RETURN(-1)
}
values ← [2, 5, 9, 7]
result ← FirstAbove(values, 6)
DISPLAY(result)
DISPLAY(LENGTH(values) - result)

What is displayed?显示的结果是什么?

Q11HARDAP MC3.13 Developing Procedures[1]

A team uses a documented library procedure to calculate shipping costs. The procedure accepts a weight and returns a cost. The team wants to update its application and avoid duplicating the calculation.某团队使用一个有文档说明的库(library)过程(procedure)计算运费。该过程接收重量并返回费用。团队希望更新应用程序,同时避免重复编写计算代码。

Which two statements are valid? Select two answers. Select two answers.以下哪两个说法正确?请选择两个答案。 选择两个答案。

Q12HARDAP MC3.15 Random Values[1]

A simulation represents an event by drawing an integer uniformly with RANDOM(1, 8). The event occurs when the returned value is at most 3.一个模拟(simulation)使用 RANDOM(1, 8) 等概率抽取整数来表示事件。当返回值不大于 3 时,事件发生。

What is the probability that the event occurs on one draw?一次抽取中该事件发生的概率是多少?

Q13HARDAP MC3.16 Simulations[1]

A city simulates evacuation times using road capacity and the number of vehicles. Its model assumes every vehicle starts at the same time, although actual departure times vary.某城市利用道路容量和车辆数量模拟疏散时间。模型假设所有车辆同时出发,但实际出发时间各不相同。

Which conclusion about the simulation is best supported?关于该模拟(simulation),以下哪个结论最有依据?

Q14HARDAP MC3.17 Algorithmic Efficiency[1]

A delivery company must find a low-cost route among many possible routes. An exact algorithm is known to examine an exponentially growing number of candidates as the number of stops increases.一家配送公司需要在众多可能的路线中寻找低成本路线。已知某精确算法检查的候选路线数量会随着停靠点数量增加而呈指数增长。

Which approach is most appropriate when the exact algorithm takes too long on large instances?当精确算法处理大型实例所需时间过长时,哪种方法最合适?

Q15MEDIUMAP MC3.18 Undecidable Problems[1]

A researcher studies a decision problem that is known to be undecidable.一名研究者正在研究一个已知不可判定的判定问题(decision problem)。

Which statement must be true?以下哪个说法必然正确?