← Course Hub← 课程主页 ← All Units← 返回单元列表
H I G H  S C H O O L  C O M P U T E R  S C I E N C E
Practice练习题

Computational Thinking and Algorithms计算思维与算法

Practice Questions · AP CSP-Feeder · US / ON / BC / AB Styles练习题集 · AP CSP 衔接 · 美 / 安 / 卑 / 阿省风格

EASY MEDIUM HARD 🇺🇸 US 🇨🇦 ON 🇨🇦 BC 🇨🇦 AB AP CSP-style MCQAP CSP 风格选择题 AP CSP-feeder FRQAP CSP 衔接简答题 ON Provincial-style安大略省考风格 BC Provincial-style卑诗省考风格 AB/Universal Applied阿省/通用应用题 Honors荣誉级


Name:姓名:Date:日期:
PART I  ·  SHORT RESPONSE第一部分  ·  短答题AP CSP-style MCQ + ON/BC/AB short answer · 25 marksAP CSP 风格选择题 + 安/卑/阿省考短答 · 共 25 分

Section A · Short ResponseA 部分 · 短答题

Questions mix multiple-choice and short-answer items. For MCQs, circle the letter and write one sentence justifying your answer. For short-answer items, write your answer clearly. Pseudocode and plain English are both acceptable for written explanations.本部分包含选择题与短答题。选择题请圈出字母,并写一句话说明理由。短答题请清晰作答。书面解释可使用伪代码或普通文字。

Q1 EASY 🇺🇸 US AP CSP-style MCQAP CSP 风格选择题 §1 Computational Thinking Pillars计算思维支柱 · CSTA 3A-AP-17 [3 marks][3 分]

A student is building a weather app. She decides that the program only needs to store temperature and precipitation for each day, ignoring wind speed, humidity, and UV index, because those are irrelevant to the forecasts she wants to display. Which pillar of computational thinking describes this decision?一名学生正在构建天气应用程序。她决定程序只需存储每天的温度降水量,忽略风速、湿度和紫外线指数,因为这些对她想显示的预报无关。哪个计算思维支柱描述了这个决策?

  1. (A) Decomposition分解
  2. (B) Pattern recognition模式识别
  3. (C) Abstraction抽象
  4. (D) Algorithmic thinking算法思维
Q2 EASY 🇺🇸 US AP CSP-style MCQAP CSP 风格选择题 §2 Algorithm Properties + Pseudocode算法属性与伪代码 · AB CSE1110 outcome 1.6 [3 marks][3 分]

Which of the following is the best reason why the pseudocode statement WHILE TRUE: OUTPUT "Hello" does not describe a valid algorithm?以下哪项最能说明伪代码语句 WHILE TRUE: OUTPUT "Hello" 构成有效算法的原因?

  1. (A) It uses an invalid keyword它使用了无效的关键字
  2. (B) It does not produce any output它不产生任何输出
  3. (C) It violates the finiteness property because it never terminates它违反了有限性属性,因为它永远不会终止
  4. (D) It uses a Boolean value instead of a number它使用布尔值而不是数字
Q3 MEDIUM 🇨🇦 ON ON Provincial-style安大略省考风格 §3 Flowcharts and Logic Representation流程图与逻辑表示 · ICS3U B2.4 [7 marks][7 分]

A flowchart represents the following logic: read a number; if the number is greater than 0, output "Positive"; else if the number equals 0, output "Zero"; else output "Negative". Answer the questions below.一个流程图表示以下逻辑:读入一个数字;如果数字大于 0,输出"Positive";否则如果数字等于 0,输出"Zero";否则输出"Negative"。回答以下问题。

(a) Name the four standard flowchart shapes and state what each one represents.写出四种标准流程图形状的名称,并说明每种形状代表什么。 [4]
(b) How many decision diamonds appear in the flowchart described above? Justify your answer.上述流程图中有几个判断菱形?请说明理由。 [2]
(c) State the output when the input number is 0.当输入数字为 0 时,写出输出结果。 [1]
Q4 MEDIUM 🇨🇦 AB AB/Universal Applied阿省/通用应用题 §4 Sequencing and the IPO Model顺序结构与 IPO 模型 · AB CSE1110 outcome 1.3 [6 marks][6 分]

Consider the pseudocode below.考察以下伪代码。

SET a TO 3
SET b TO a + 2
SET c TO b * a
SET a TO c - b
OUTPUT a
(a) Complete the trace table below, recording the value of each variable after each line executes.补全以下追踪表,记录每行执行后每个变量的值。 [4]
Lineabc
Start初始---
1
2
3
4
(b) State the value output by the final OUTPUT a statement.写出最后 OUTPUT a 语句输出的值。 [1]
(c) Identify the Input, Process, and Output phases of this algorithm using the IPO model.用 IPO 模型识别该算法的输入、处理和输出阶段。 [1]
Q5 MEDIUM 🇨🇦 BC BC Provincial-style卑诗省考风格 §7 Tracing and Debugging追踪与调试 · AB CSE1110 outcome 3.1 [6 marks][6 分]

The pseudocode below is intended to sum the integers from 1 to 4 inclusive and output 10. It contains a bug.以下伪代码旨在计算 1 到 4(含)的整数之和并输出 10。其中包含一个错误。

SET total TO 0
SET i TO 1
WHILE i < 4:
    SET total TO total + i
    SET i TO i + 1
OUTPUT total
(a) Trace the pseudocode above with a variable trace table. Show the value of i and total after each iteration.用变量追踪表追踪以上伪代码。写出每次迭代后 itotal 的值。 [3]
(b) State the actual output of the buggy pseudocode.写出有错误的伪代码的实际输出。 [1]
(c) Identify the type of error (syntax, logic, or runtime) and state the one-line fix.识别错误类型(语法、逻辑或运行时)并写出单行修复方案。 [2]
PART II  ·  EXTENDED RESPONSE第二部分  ·  简答题AP CSP-feeder FRQ + Honors · 30 marksAP CSP 衔接简答题 + 荣誉级 · 共 30 分

Section B · Extended ResponseB 部分 · 简答题

Show all reasoning. Write pseudocode in the standard block format (IF/THEN/END IF, WHILE/END WHILE, FOR/END FOR) or valid Python. Justify answers in one to two sentences. Calculator not applicable; trace by hand.展示所有推理过程。伪代码使用标准块格式(IF/THEN/END IF、WHILE/END WHILE、FOR/END FOR)或合法 Python。用一两句话论证作答。无需计算器;手工追踪。

Q6 EASY 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §1 + §6 Decomposition applied分解应用 · CSTA 3A-AP-17 / ICS3U B1.1 [5 marks][5 分]

A student wants to build a program that reads five exam scores from the user, computes the average, and prints a letter grade (A if average ≥ 90; B if ≥ 80; C if ≥ 70; D if ≥ 60; F otherwise).一名学生想构建一个程序,从用户读取五个考试成绩,计算平均分,并打印字母等级(平均分 ≥ 90 为 A;≥ 80 为 B;≥ 70 为 C;≥ 60 为 D;其他为 F)。

(a) Apply decomposition. List at least three distinct sub-problems that must be solved to build this program.应用分解。列出构建此程序必须解决的至少三个不同子问题。 [3]
(b) Apply abstraction. Identify two pieces of data the program needs and two pieces it does not need (even though a real school system would store them).应用抽象。识别程序需要的两项数据,以及程序不需要的两项数据(尽管真实学校系统会存储它们)。 [2]
Q7 MEDIUM 🇨🇦 ON 🇨🇦 BC ON Provincial-style安大略省考风格 §2 Pseudocode authoring伪代码编写 · ICS3U B1.1 / BC CP11 [8 marks][8 分]

Write a pseudocode algorithm that inputs a positive integer n and outputs the sum of all odd numbers from 1 to n inclusive. For example: if n = 7, the odd numbers are 1, 3, 5, 7 and their sum is 16.编写伪代码算法,输入正整数 n,输出从 1 到 n(含)所有奇数之和。例如:若 n = 7,奇数为 1、3、5、7,其和为 16。

(a) State the Input, Process, and Output of this algorithm using the IPO model.用 IPO 模型说明该算法的输入、处理和输出。 [2]
(b) Write the full pseudocode algorithm using correct keywords (INPUT, OUTPUT, SET, WHILE or FOR, IF).使用正确关键字(INPUT、OUTPUT、SET、WHILE 或 FOR、IF)编写完整的伪代码算法。 [4]
(c) Trace your pseudocode with n = 5. Record the value of your accumulator variable after each step where it changes.n = 5 追踪你的伪代码。记录每次累加器变量改变后的值。 [2]
Q8 HARD 🇺🇸 US AP CSP-feeder FRQAP CSP 衔接简答题 §5 Algorithm Efficiency算法效率 · AP CSP AAP-4.A (3.17) [9 marks][9 分]

A program searches for the value 71 in the sorted list below using two different algorithms.一个程序使用两种不同算法在以下已排序列表中搜索值 71。

List: [3, 9, 15, 22, 31, 44, 57, 71, 83, 96]   (10 items, indices 0-9)
(a) Trace a linear search for value 71. State the index checked at each step and how many steps are needed in total.追踪对值 71 的线性搜索。写出每步检查的索引及所需总步数。 [3]
(b) Trace a binary search for value 71 on the same list. At each step state: the current low index, high index, mid index, the value at mid, and whether to go left or right.在同一列表上追踪对值 71 的二分搜索。每步写出:当前低索引、高索引、中索引、中位置的值,以及向左还是向右搜索。 [3]
(c) State one pre-condition that must be true for binary search to work correctly.写出二分搜索正确工作所需的一个前提条件。 [1]
(d) For a list of 1,000 items, state the worst-case number of steps for (i) linear search and (ii) binary search. Explain in one sentence which is more efficient and why.对于 1000 项的列表,写出 (i) 线性搜索和 (ii) 二分搜索的最坏情况步数。用一句话解释哪个更高效及原因。 [2]
Q9 HARD Honors荣誉级 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §5 Big-O Efficiency Reasoning大 O 效率推理 · ON ICS4U C2 / AB CSE3110 [8 marks][8 分]

Computer scientists classify algorithms by how their step count grows with input size n, ignoring constant factors. The two classifications relevant here are O(n) (linear) and O(log n) (logarithmic).计算机科学家根据算法步骤数随输入大小 n 增长的方式对其分类,忽略常数因子。此处相关的两种分类为 O(n)(线性)和 O(log n)(对数)。

(a) Classify each algorithm: linear search, binary search. Write the Big-O class for each.分类以下算法:线性搜索、二分搜索。写出每个算法的大 O 分类。 [2]
(b) A list has n = 1,048,576 items (that is 220). State the worst-case step count for binary search on this list. Show your working.一个列表有 n = 1,048,576 项(即 220)。写出对该列表进行二分搜索的最坏情况步数。展示计算过程。 [2]
(c) The same list undergoes a linear search in the worst case. How many times more steps does linear search need compared to binary search? Express your answer as a ratio and explain what this means practically.同一列表在最坏情况下进行线性搜索。线性搜索需要的步骤数是二分搜索的多少倍?用比率表示你的答案,并解释这在实际中意味着什么。 [2]
(d) Explain in one sentence why a programmer would still choose linear search over binary search in some situations. Give one concrete example scenario.用一句话解释为什么程序员在某些情况下仍会选择线性搜索而非二分搜索。举一个具体的应用场景例子。 [2]
PART III  ·  MODELING / APPLIED第三部分  ·  建模与应用Universal / multi-region applied · 25 marks通用/多地区应用题 · 共 25 分

Section C · Modeling and ApplicationsC 部分 · 建模与应用

Read each scenario carefully. Use standard pseudocode block format or Python as directed. Show all trace steps. Conclude each question with a one-sentence answer. No EASY items in this Part.仔细阅读每个场景。按要求使用标准伪代码块格式或 Python。展示所有追踪步骤。每题以一句完整的结论句作答。本部分无易题。

Q10 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §2 + §4 + §7 Pseudocode trace: greedy algorithm伪代码追踪:贪心算法 · ICS3U B1.3 [8 marks][8 分]

The pseudocode below implements a greedy coin-change algorithm that finds the minimum number of coins to make an exact amount, using denominations [25, 10, 5, 1] cents.以下伪代码实现一个贪心找零算法,使用面值 [25, 10, 5, 1] 分的硬币找出凑成指定金额所需的最少硬币数。

INPUT amount          -- amount = 41 cents for this question
SET count TO 0
FOR EACH coin IN [25, 10, 5, 1]:
    WHILE amount >= coin:
        SET amount TO amount - coin
        SET count TO count + 1
OUTPUT count
(a) Trace the algorithm with amount = 41 cents. For each time the WHILE loop body executes, record: the current coin denomination, the value of amount before and after, and the updated value of count.amount = 41 分追踪算法。每次 WHILE 循环体执行时,记录:当前硬币面值、amount 执行前后的值,以及更新后的 count 值。 [4]
(b) State the final value of count output by the algorithm. Express the coins used as a sum (e.g., 25 + 10 + 5 + 1 = 41).写出算法输出的 count 最终值。将所用硬币表达为求和式(如 25 + 10 + 5 + 1 = 41)。 [2]
(c) Identify the computational thinking pillar that the greedy strategy (always pick the largest coin that fits) represents. Justify in one sentence.识别贪心策略(总是选择能放入的最大面值硬币)所代表的计算思维支柱。用一句话论证。 [2]
Q11 MEDIUM 🇨🇦 ON 🇨🇦 BC ON Provincial-style安大略省考风格 §3 + §6 + §7 Flowchart, decomposition, debugging流程图、分解、调试 · ICS3U B3.3 / BC CP11 [8 marks][8 分]

A student describes a flowchart for a password-strength checker: START → Read password → Decision: is length ≥ 8? (YES: go to next check; NO: output "Too short" → END) → Decision: does password contain a digit? (YES: output "Strong" → END; NO: output "Add a digit" → END).一名学生描述了一个密码强度检查器的流程图:START → 读取密码 → 判断:长度 ≥ 8?(是:进入下一项检查;否:输出"Too short" → END)→ 判断:密码是否包含数字?(是:输出"Strong" → END;否:输出"Add a digit" → END)。

(a) Convert the flowchart to pseudocode using standard IF/ELSE/END IF blocks. Your pseudocode must start with INPUT password.将流程图转换为使用标准 IF/ELSE/END IF 块的伪代码。你的伪代码必须以 INPUT password 开头。 [4]
(b) The student realizes the checker should also verify that passwords do not exceed 20 characters. Apply decomposition: identify the updated list of sub-problems the checker now solves (there are at least three).学生意识到检查器还应验证密码不超过 20 个字符。应用分解:识别检查器现在解决的子问题更新列表(至少有三个)。 [2]
(c) A tester inputs the password "hello" (5 characters, no digit). State the output and the path taken through the flowchart.测试员输入密码 "hello"(5 个字符,无数字)。写出输出结果及在流程图中经过的路径。 [2]
Q12 HARD 🇺🇸 US 🇨🇦 ON 🇨🇦 BC AP CSP-feeder FRQAP CSP 衔接简答题 All sections · Full design + trace全节综合 · 完整设计与追踪 · CSTA 3A-AP-13 / 3A-AP-17 [9 marks][9 分]

A school library app needs to find whether a student's requested book title is available. The library catalogue is a sorted list of titles. The developer must choose between linear search and binary search, then implement the chosen algorithm as a pseudocode procedure that returns TRUE if found and FALSE if not.一个学校图书馆应用程序需要查找学生请求的书名是否可用。图书馆目录是已排序的书名列表。开发者必须在线性搜索和二分搜索之间选择,然后将所选算法实现为伪代码过程,如果找到则返回 TRUE,否则返回 FALSE

(a) Apply decomposition. List the three high-level sub-problems this library app must solve.应用分解。列出图书馆应用程序必须解决的三个高层子问题。 [2]
(b) Justify which search algorithm (linear or binary) is more appropriate for a sorted catalogue of 5,000 titles. Give one reason referring to step count.论证对于包含 5000 个书名的已排序目录,哪种搜索算法(线性或二分)更合适。给出一个涉及步骤数的理由。 [2]
(c) Write a pseudocode procedure SEARCH(catalogue, target) that implements binary search and returns TRUE if target is found, FALSE otherwise. Use variables low, high, and mid.编写伪代码过程 SEARCH(catalogue, target),实现二分搜索,如果找到 target 则返回 TRUE,否则返回 FALSE。使用变量 lowhighmid [4]
(d) The developer tests the procedure with an unsorted catalogue by mistake. Describe what type of error this would cause and why.开发者不小心用未排序的目录测试该过程。描述这会导致什么类型的错误以及原因。 [1]

🇺🇸 US CSTA / AP CSP美国 CSTA / AP CSP3A-AP-13 · 3A-AP-17 · AAP-4.A
🇨🇦 Ontario安大略ICS3U B1.1 · B1.3 · B3.3
🇨🇦 British Columbia不列颠哥伦比亚CS 10 / CP11: computational thinking, pseudocode, flowcharts, debuggingCS 10 / CP11:计算思维、伪代码、流程图、调试
🇨🇦 Alberta阿尔伯塔CSE1110: outcomes 1.3, 1.4, 1.6, 1.7, 3.1CSE1110:结果 1.3、1.4、1.6、1.7、3.1

Full Syllabus Map in Study Guide: ../Study Guides/Unit_1_Computational_Thinking_and_Algorithms.html. CS has no AB standalone diploma exam; AB framing uses CSE1110 outcomes.完整大纲对照见学习指南:../Study Guides/Unit_1_Computational_Thinking_and_Algorithms.html。CS 无独立 AB 毕业考;AB 题使用 CSE1110 结果框架。