High School Computer Science

Computational Thinking and Algorithms计算思维与算法

Computational thinking is the problem-solving mindset that computer scientists bring to every challenge: break a big problem apart (decomposition), spot repeated patterns, strip away irrelevant detail (abstraction), and express the solution as a precise sequence of steps (algorithmic thinking). This guide builds all four pillars from the ground up, then shows you how to write that step sequence as pseudocode and draw it as a flowchart, how to trace through an algorithm by hand so you can verify correctness before writing a single line of code, and how to start reasoning about whether one algorithm is faster than another. Worked examples use real pseudocode and Python throughout.计算思维(computational thinking,计算思维)是计算机科学家解决每一个挑战的思维方式:把大问题拆开(decomposition,分解)、找出重复的模式(pattern recognition,模式识别)、剥去无关细节(abstraction,抽象),再将解决方案表达为一系列精确的步骤(algorithmic thinking,算法思维)。本指南从零开始建立这四个支柱,再展示如何把步骤序列写成伪代码(pseudocode,伪代码)、画成流程图(flowchart,流程图),如何手工追踪一个算法(algorithm,算法)来验证正确性,以及如何初步判断算法效率(efficiency,效率)。全部例题均使用伪代码和 Python 演算。

7 sections7 节内容 US CSTA · AP CSP · ON · BC · ABUS CSTA · AP CSP · ON · BC · AB Pseudocode + Python worked examples伪代码 + Python 例题

How to use this guide如何使用本指南

Computational thinking is covered in every curriculum we map to, and all four agree on the core four pillars: decomposition, pattern recognition, abstraction, and algorithmic thinking. Pseudocode and flowcharts are universal. Where they diverge is on algorithm efficiency analysis: Alberta CSE1110 names explicit algorithm testing; Ontario ICS4U strand C adds formal analysis of efficiency (a Grade-12 topic). The tracing and debugging section (§7) maps to Ontario ICS3U strand B, BC Computer Programming 11 "use of test cases," and CSE1110 outcome 1.7. The table tells you which sections are core for you right now; each row cites the curriculum document it was checked against.在我们对照的所有大纲中,计算思维都是核心内容,四套大纲对四个支柱(分解、模式识别、抽象、算法思维)高度一致,伪代码与流程图也是共同要求。它们的分歧在于算法效率分析:阿尔伯塔 CSE1110 明确要求测试算法;安大略 ICS4U C 单元增加了正式的效率分析(属 12 年级内容)。追踪与调试(§7)对应安大略 ICS3U B 单元、BC Computer Programming 11"测试用例的使用"与 CSE1110 结果 1.7。下表告诉你当前哪些节属于你的核心;每行都注明所依据的课纲文件。

If you are in…如果你在… Focus on these sections重点学习 Defer / lighter可推迟 / 减负 Source依据
🇺🇸 US CSTA / AP CSP美国 CSTA / AP CSP §1 through §7 in full. CSTA 3A-AP-13 (prototypes using algorithms), 3A-AP-17 (decomposition), AP CSP Big Idea 3 topics 3.9 and 3.17 all map to this guide.§1 至 §7 完整学习。CSTA 3A-AP-13(使用算法的原型)、3A-AP-17(分解)、AP CSP 大概念 3 主题 3.9 和 3.17 均对应本指南。 §5 efficiency analysis is labelled “going deeper” for AP CSP floor students; Big Idea 3 topic 3.17 covers it at the exam level.§5 效率分析对 AP CSP 基础学生标注为"深入";大概念 3 主题 3.17 在考试层面覆盖此内容。 CSTA K-12 and AP CSP — CSTA 3A-AP-13, 3A-AP-17; AP CSP Big Idea 3 (AAP) topics 3.9, 3.17; Big Idea 1 (CRD) topics 1.3, 1.4— CSTA 3A-AP-13、3A-AP-17;AP CSP 大概念 3(AAP)主题 3.9、3.17;大概念 1(CRD)主题 1.3、1.4
🇨🇦 ON Grade 11 — ICS3U安大略 11 年级 — ICS3U §1 through §7 in full. ICS3U Strand B (B1, B3) explicitly names problem-solving strategies including “stepwise refinement, divide and conquer” and algorithm design. §7 tracing maps to B3.3 (algorithm testing) and B4 (software development cycle).§1 至 §7 完整学习。ICS3U B 单元(B1、B3)明确点名"逐步精化、分而治之"等解题策略和算法设计。§7 追踪对应 B3.3(算法测试)和 B4(软件开发周期)。 Formal efficiency analysis in §5 going-deeper is ICS4U strand C (Grade 12) — skip for ICS3U floor.§5 深入中的正式效率分析属 ICS4U C 单元(12 年级)——ICS3U 基础学生可跳过。 ON/BC Computer Studies 11-12 — ICS3U Strand B B1, B1.1, B1.3, B3, B3.1, B3.3; ICS4U Strand C C2, C2.1— ICS3U B 单元 B1、B1.1、B1.3、B3、B3.1、B3.3;ICS4U C 单元 C2、C2.1
🇨🇦 BC — CS10 / CP11BC — CS10 / CP11 §1 through §7. Computer Studies 10 Content names all four computational-thinking pillars verbatim. Computer Programming 11 Content names “problem decomposition,” “computational thinking processes,” “ways to transform requirements into algorithms.”§1 至 §7。BC Computer Studies 10 内容原文命名全部四个计算思维支柱。Computer Programming 11 内容点名"问题分解"、"计算思维过程"、"将需求转化为算法的方法"。 BC has no explicit algorithm-efficiency standard at grade 11; §5 going-deeper is enrichment for BC students.BC 11 年级无明确算法效率标准;§5 深入对 BC 学生为拓展内容。 ON/BC Computer Studies 11-12 — BC CS10 computational-thinking Content bullet; CP11 problem decomposition / computational thinking Content; CP11 Applied Design Curricular Competency (Prototyping)— BC CS10 计算思维内容条目;CP11 问题分解/计算思维内容;CP11 应用设计课程能力(原型制作)
🇨🇦 AB — CSE1010 / CSE1110阿尔伯塔 — CSE1010 / CSE1110 §1 through §7. CSE1010 introduces the algorithm as a problem-solving tool. CSE1110 outcomes 1.1–1.7 cover algorithm description, analysis, decomposition, pseudocode/structured-chart writing, and algorithm testing — a near-perfect match for this guide.§1 至 §7。CSE1010 将算法作为解决问题的工具引入。CSE1110 结果 1.1–1.7 涵盖算法描述、分析、分解、伪代码/结构图编写和算法测试——与本指南高度契合。 Formal efficiency comparison (§5 going-deeper) is CSE3110 Advanced — skip for CSE1110 floor students.正式效率比较(§5 深入)属 CSE3110 高级模块——CSE1110 基础学生可跳过。 Alberta CTS Computing Science — CSE1010 outcomes 1.1.2, 1.2.2; CSE1110 outcomes 1.1–1.7— CSE1010 结果 1.1.2、1.2.2;CSE1110 结果 1.1–1.7
🇺🇸 AP CSP / AP CSA feeder trackAP CSP / AP CSA 衔接轨道 All seven sections including going-deeper boxes. AP CSP Big Idea 3 (30–35% of the exam) assumes you can read and write pseudocode fluently. AP CSA (Java OOP) assumes algorithmic thinking and decomposition from day one.全部 7 节,包含深入框。AP CSP 大概念 3(占考试 30–35%)假定你能流畅读写伪代码。AP CSA(Java 面向对象)从第一天起就假定你具备算法思维和分解能力。 Nothing — this unit is the conceptual bedrock that both AP CS courses build on. See the feeder links in "What This Feeds Into."无 — 本单元是两门 AP CS 课程的概念基石。见"本单元的去向"中的衔接链接。 CSTA K-12 and AP CSP — AP CSP Big Idea 3 (AAP) exam weighting 30–35%; AP CSP Big Idea 1 (CRD) 10–13%— AP CSP 大概念 3(AAP)考试占比 30–35%;大概念 1(CRD)10–13%

Once you have located your row, use the two cards below for the speed at which you should work through the recommended sections.找到所在行后,用下面两张卡片决定推进速度。

!
If you are cramming the night before如果你在临阵磨枪

Memorise four things: the four pillars of computational thinking (decomposition, pattern recognition, abstraction, algorithmic thinking); what an algorithm is and how to write simple pseudocode; how to read a flowchart and follow its logic; and how to trace an algorithm by hand using a variable table. Read every cram-cheat box. Skip the going-deeper efficiency analysis.背熟四件事:计算思维的四个支柱(分解、模式识别、抽象、算法思维);算法是什么以及如何写简单伪代码;如何读懂流程图并遵循其逻辑;如何用变量追踪表手工追踪一个算法。读每个速记框,跳过深入的效率分析。

*
If you are going for the top mark如果你目标顶分

Always decompose before you code: write the algorithm in plain pseudocode first, trace through it with a worked example to check correctness, then translate to a programming language. AP CSP Big Idea 3 (30–35% of the exam) expects you to read and write the College Board pseudocode fluently. AB CSE1110 and ON ICS3U both require you to test your algorithm with both success and failure cases — §7 shows you how.永远先分解再编码:先用普通伪代码写算法,用例题追踪验证正确性,再翻译为编程语言。AP CSP 大概念 3(占考试 30–35%)要求你能流畅读写 College Board 伪代码。AB CSE1110 和 ON ICS3U 都要求你分别用成功与失败用例测试算法——§7 展示了如何做到这一点。

Algorithm efficiency note.算法效率说明。 Section 5 (Introduction to Algorithm Efficiency) introduces the idea that some algorithms are faster than others, and shows how to compare step counts informally. The Honors chip marks the going-deeper box where formal Big-O notation is introduced. That box maps to Ontario ICS4U strand C2 (Grade 12) and Alberta CSE3110 (Advanced level). For ICS3U / CSE1110 / AP CSP floor students, the intuitive “count the steps” approach in the cram box is the assessed level.§5(算法效率初步)介绍了某些算法比其他算法更快的思想,并展示如何非正式地比较步骤数量。Honors 标记深入框,其中正式引入大 O 表示法。该框对应安大略 ICS4U C 单元第 2 条(12 年级)和阿尔伯塔 CSE3110(高级模块)。对于 ICS3U / CSE1110 / AP CSP 基础学生,速记框中的直观"计步"方法是被评估的层次。

What is Computational Thinking?什么是计算思维?

The four pillars — memorise these before anything else.四个支柱 — 在学其他内容之前先背会这些。
  • Decomposition分解 — break a complex problem into smaller, manageable sub-problems. BC Computer Studies 10 names this verbatim; AB CSE1110 outcome 1.4 says "decompose the problem into its input, processing and output components."— 将复杂问题拆分为更小、可处理的子问题。BC Computer Studies 10 原文命名此项;AB CSE1110 结果 1.4 要求"将问题分解为输入、处理和输出组件"。
  • Pattern recognition模式识别 — spot similarities or repeated structures across problems or within data. Recognising patterns means you can reuse solutions instead of starting from scratch every time.— 发现问题之间或数据内部的相似性或重复结构。识别模式意味着你可以重复使用解决方案,而不必每次从头开始。
  • Abstraction抽象 — strip away irrelevant detail and keep only what matters for solving the problem. A map is an abstraction of a city; a function is an abstraction of repeated code.— 去除无关细节,只保留解决问题所需的内容。地图是城市的抽象;函数是重复代码的抽象。
  • Algorithmic thinking算法思维 — express the solution as a precise, unambiguous, step-by-step sequence that anyone (or any computer) can follow. This step sequence is called an algorithm.— 将解决方案表达为任何人(或任何计算机)都能遵循的精确、无歧义的逐步序列。这个步骤序列称为算法
The one fact that catches people: computational thinking is a mindset, not a programming language. You can apply decomposition and algorithmic thinking entirely in plain English (or pseudocode) before writing a single line of code. CSTA 3A-AP-13 says "Create prototypes that use algorithms to solve computational problems" — the prototype can be pseudocode.最易踩坑的一点:计算思维是一种思维方式,而非编程语言。在写一行代码之前,你完全可以用普通英语(或伪代码)运用分解和算法思维。CSTA 3A-AP-13 要求"创建使用算法解决计算问题的原型"——原型可以是伪代码。
CT
Worked Example 1 · Planning a school schedule例题 1 · 规划学校课表

Problem: build an app that helps a student organise their homework across five subjects. Apply all four pillars.问题:创建一个帮助学生在五门学科之间安排作业的应用程序。应用全部四个支柱。

Decomposition.分解。 Break into sub-problems: (1) store the list of subjects and due dates; (2) sort tasks by urgency; (3) display the prioritised list; (4) mark tasks complete. Each is now small enough to code independently.拆分为子问题:(1) 存储学科列表和截止日期;(2) 按紧迫性排序任务;(3) 显示优先列表;(4) 标记任务为已完成。每个子问题现在都足够小,可以独立编码。

Pattern recognition.模式识别。 Sorting tasks by date is the same pattern as sorting any list of items by a key — you can reuse a general sorting approach (covered in the Searching and Sorting guide).按日期排序任务与按键排序任何项目列表的模式相同——你可以重复使用通用排序方法(在搜索与排序指南中介绍)。

Abstraction.抽象。 Represent each task as a record with just three fields: subject, due_date, done. Ignore everything else (teacher name, room number, textbook page) — it is irrelevant to the scheduling problem.将每个任务表示为只有三个字段的记录:subject(学科)、due_date(截止日期)、done(完成状态)。忽略其他一切(教师姓名、教室编号、课本页码)——它们与调度问题无关。

Algorithmic thinking.算法思维。 Write the steps in pseudocode: INPUT tasks with due dates → SORT tasks by due date → FOR EACH task: DISPLAY subject and date → END. Each step is unambiguous and executable.用伪代码写出步骤:输入带截止日期的任务 → 按截止日期排序任务 → 对每个任务:显示学科和日期 → 结束。每个步骤都是无歧义且可执行的。

A student wants to build a program to calculate the average of a list of test scores. Which computational thinking pillar involves deciding that the program only needs to store the scores (not student names or dates) to calculate the average?一名学生想编写一个程序来计算一组考试成绩的平均值。哪个计算思维支柱涉及决定程序只需存储成绩(而非学生姓名或日期)来计算平均值?
§1 · Q1
Decomposition分解
Abstraction抽象
Algorithmic thinking算法思维
Pattern recognition模式识别
Abstraction means keeping only what is relevant and stripping away unneeded detail. Deciding to store only scores (not names or dates) is a classic abstraction decision — it simplifies the data model to what the calculation actually requires.抽象意味着只保留相关内容,去除不需要的细节。决定只存储成绩(而非姓名或日期)是经典的抽象决策——它将数据模型简化为计算实际所需的内容。
This is about filtering out irrelevant detail — that is abstraction. Decomposition breaks a problem into sub-parts; algorithmic thinking writes step sequences; pattern recognition spots repetition across problems.这是关于过滤无关细节——那是抽象。分解将问题拆分为子部分;算法思维编写步骤序列;模式识别发现问题间的重复。
Which pillar of computational thinking means breaking a large problem into smaller, manageable sub-problems?计算思维的哪个支柱意味着将一个大问题拆分为更小、可管理的子问题?
§1 · Q2
Decomposition分解
Abstraction抽象
Pattern recognition模式识别
Algorithmic thinking算法思维
Decomposition is the pillar that breaks a complex problem into smaller, more manageable sub-problems. CSTA 3A-AP-17 states: "Decompose problems into smaller components through systematic analysis."分解是将复杂问题拆分为更小、更易管理的子问题的支柱。CSTA 3A-AP-17 指出:"通过系统分析将问题分解为更小的组件。"
Decomposition = break into pieces. Abstraction = hide irrelevant detail. Pattern recognition = spot repetition. Algorithmic thinking = write a step sequence.分解 = 拆分为部分。抽象 = 隐藏无关细节。模式识别 = 发现重复。算法思维 = 编写步骤序列。
Going deeper — computational thinking across disciplines深入 — 跨学科的计算思维

CSTA 3A-IC-26 states: "Demonstrate ways a given algorithm applies to problems across disciplines." Computational thinking is not exclusive to programming: a biologist who sequences genomes uses decomposition (break the genome into segments) and pattern recognition (find repeating base sequences). A historian who analyses census data uses abstraction (which fields matter?) and algorithmic thinking (which decades should be compared first?). This cross-disciplinary reach is why every major curriculum includes computational thinking as a core skill, not merely a programming prerequisite.CSTA 3A-IC-26 指出:"展示给定算法在跨学科问题中的应用方式。"计算思维不仅限于编程:对基因组测序的生物学家运用分解(将基因组分成片段)和模式识别(找出重复的碱基序列)。分析人口普查数据的历史学家运用抽象(哪些字段重要?)和算法思维(应该首先比较哪几十年?)。这种跨学科的广泛应用是每个主要课程将计算思维作为核心技能而非仅仅是编程先决条件的原因。

The BC Computer Programming 11 Big Idea "The design cycle includes updating content, tools, and delivery" reinforces this: the four pillars are the design phase of the software development cycle (covered in depth in the Software Development Process guide). Mastering them here pays dividends in every subsequent unit.BC Computer Programming 11 的大概念"设计周期包括更新内容、工具和交付"强化了这一点:四个支柱是软件开发周期的设计阶段(在软件开发过程指南中深入介绍)。在这里掌握它们,在后续每个单元都会带来回报。


Algorithms and Pseudocode算法与伪代码

Three properties every algorithm must have.每个算法必须具备的三个属性。
  • Finiteness有限性 — terminates after a finite number of steps (no infinite loops).— 经过有限步骤后终止(无无限循环)。
  • Definiteness确定性 — every step is precisely and unambiguously defined; no guessing.— 每个步骤都是精确且无歧义地定义的;不需要猜测。
  • Effectiveness有效性 — every step can actually be carried out (no "wave a magic wand").— 每个步骤都可以实际执行(不存在"挥动魔杖")。
Pseudocode is a human-readable way to write an algorithm — structured enough to be clear, but not tied to any particular programming language. Use keywords like INPUT, OUTPUT, IF/ELSE, WHILE, FOR, SET x TO. AB CSE1110 outcome 1.6 says: "write the algorithm in an acceptable format; e.g., pseudocode, structured chart."伪代码是一种人类可读的算法编写方式——结构足够清晰,但不依赖任何特定的编程语言。使用关键字如 INPUT(输入)、OUTPUT(输出)、IF/ELSE(如果/否则)、WHILE(当…时)、FOR(对于)、SET x TO(将 x 设为)。AB CSE1110 结果 1.6 要求:"以可接受的格式编写算法,如伪代码、结构图。"
WE
Worked Example 2 · Finding the minimum number of coins例题 2 · 找最少硬币数

Problem: given an amount in cents (e.g. 87 cents) and coin denominations [25, 10, 5, 1], write an algorithm that returns the fewest coins needed.问题:给定以分为单位的金额(如 87 分)和硬币面值 [25, 10, 5, 1],编写一个返回所需最少硬币数的算法。

Algorithm in pseudocode.算法(伪代码)。

INPUT amount
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

In the pseudocode above: INPUT reads a value; SET ... TO assigns a value; FOR EACH iterates over each element; WHILE repeats while a condition holds; OUTPUT prints a result.以上伪代码中:INPUT 输入,SET ... TO 赋值,FOR EACH 对每个,WHILE 当…时,OUTPUT 输出。

Python rendering.Python 实现。

def min_coins(amount):
    count = 0
    for coin in [25, 10, 5, 1]:
        while amount >= coin:
            amount -= coin
            count += 1
    return count

print(min_coins(87))  # Output: 6

The pseudocode maps directly to Python: each keyword has a near-identical Python counterpart. Writing pseudocode first means the Python almost writes itself. Output: 87 = 3×25 + 1×10 + 2×1 = 6 coins.伪代码直接映射到 Python:每个关键字都有近乎相同的 Python 对应物。先写伪代码意味着 Python 几乎会自动写出。输出:87 = 3×25 + 1×10 + 2×1 = 6 枚硬币。

Which of the following is the best description of an algorithm?以下哪项最能描述算法?
§2 · Q1
A program written in Python or Java用 Python 或 Java 编写的程序
A flowchart drawn on paper画在纸上的流程图
A precise, finite, step-by-step procedure for solving a problem解决问题的精确、有限、逐步程序
A list of test cases for debugging用于调试的测试用例列表
An algorithm is a precise, finite, step-by-step procedure. It can be expressed in pseudocode, a flowchart, plain English, or a programming language — the format is secondary; the precision and finiteness are essential.算法是精确、有限的逐步程序。它可以用伪代码、流程图、普通英语或编程语言表达——格式是次要的;精确性和有限性是本质要求。
An algorithm is a general concept, not tied to any language or representation. A Python program and a pseudocode sketch are both implementations of an algorithm.算法是一个通用概念,不依附于任何语言或表示形式。Python 程序和伪代码草图都是算法的实现。
In pseudocode, SET total TO total + score means what in Python?在伪代码中,SET total TO total + score 对应 Python 中的哪行代码?
§2 · Q2
total == total + score
total = total + score
print(total + score)
total + score = total
SET x TO value in pseudocode is an assignment statement. In Python, assignment is written with a single equals sign: total = total + score (or equivalently total += score).伪代码中的 SET x TO value 是赋值语句。在 Python 中,赋值用单等号写:total = total + score(等价地 total += score)。
== is a comparison (checks equality); = is assignment (sets a value). Pseudocode SET x TO y always maps to assignment, not comparison.== 是比较(检查是否相等);= 是赋值(设置值)。伪代码 SET x TO y 总是映射到赋值,而不是比较。
Going deeper — College Board AP CSP pseudocode vs Python深入 — College Board AP CSP 伪代码与 Python 对比

AP CSP uses its own reference-sheet pseudocode (not Python). Key differences: assignment is written x ← value; lists are 1-indexed (first element is index 1, not 0); Boolean values are TRUE/FALSE; display uses DISPLAY(value); procedures are PROCEDURE name(params). You will see this notation on the AP CSP exam. Learning pseudocode in this guide gives you the underlying concepts; mapping those to the AP CSP notation is a surface-level translation exercise.AP CSP 使用自己的参考手册伪代码(不是 Python)。主要区别:赋值写作 x ← value;列表从 1 开始索引(第一个元素索引为 1,不是 0);布尔值为 TRUE/FALSE;显示使用 DISPLAY(value);过程为 PROCEDURE name(params)。你会在 AP CSP 考试中看到这种表示法。学习本指南中的伪代码让你掌握底层概念;将这些概念映射到 AP CSP 表示法只是一个表层翻译练习。


Flowcharts and Representing Logic流程图与逻辑表示

Four flowchart shapes — memorise these.四种流程图形状 — 背熟这些。
  • Oval / Rounded rectangle椭圆 / 圆角矩形 — Start or End (terminal). Every flowchart must have exactly one Start and at least one End.— 开始或结束(终端)。每个流程图必须恰好有一个开始和至少一个结束。
  • Rectangle矩形 — Process / Action (assignment, calculation, I/O operation).— 处理 / 操作(赋值、计算、I/O 操作)。
  • Diamond菱形 — Decision (yes/no question). Two arrows leave: one for YES, one for NO.— 判断(是/否问题)。两条箭头离开:一条表示"是",一条表示"否"。
  • Parallelogram平行四边形 — Input or Output (read data in, write data out).— 输入或输出(读取数据、写出数据)。
BC Computer Programming 11 names "computational thinking processes" and "ways to transform requirements into algorithms" as core content; flowcharts are the standard visual tool for this transformation. AB CSE1110 outcome 1.6 accepts "pseudocode, structured chart" — a structured chart is essentially a flowchart or Nassi-Schneiderman diagram.BC Computer Programming 11 将"计算思维过程""将需求转化为算法的方法"列为核心内容;流程图是这种转换的标准可视化工具。AB CSE1110 结果 1.6 接受"伪代码、结构图"——结构图本质上就是流程图或 Nassi-Schneiderman 图。
WE
Worked Example 3 · Flowchart for grade classification例题 3 · 成绩分类的流程图

Draw the flowchart for: read a score; if score ≥ 90 output "A"; else if score ≥ 80 output "B"; else output "C or below."画出以下流程图:读入分数;如果分数 ≥ 90 输出"A";否则如果分数 ≥ 80 输出"B";否则输出"C 或以下"。

Pseudocode first (always write this before the flowchart).先写伪代码(总是在画流程图之前写这个)。

START
INPUT score
IF score >= 90 THEN
    OUTPUT "A"
ELSE IF score >= 80 THEN
    OUTPUT "B"
ELSE
    OUTPUT "C or below"
END IF
END

Flowchart structure (described textually).流程图结构(文字描述)。

Oval "START" → Parallelogram "Read score" → Diamond "score ≥ 90?" → YES branch: Parallelogram "Output A" → Oval "END". NO branch → Diamond "score ≥ 80?" → YES branch: Parallelogram "Output B" → Oval "END". NO branch → Parallelogram "Output C or below" → Oval "END". Notice: three possible END ovals (or alternatively one shared END after merging the branches).椭圆"开始"→ 平行四边形"读取分数"→ 菱形"分数 ≥ 90?"→ 是分支:平行四边形"输出 A"→ 椭圆"结束"。否分支 → 菱形"分数 ≥ 80?"→ 是分支:平行四边形"输出 B"→ 椭圆"结束"。否分支 → 平行四边形"输出 C 或以下"→ 椭圆"结束"。注意:三个可能的结束椭圆(或者在合并分支后共享一个结束)。

In a flowchart, what shape represents a decision (a yes/no question)?在流程图中,哪种形状代表判断(是/否问题)?
§3 · Q1
Rectangle矩形
Parallelogram平行四边形
Oval椭圆
Diamond菱形
A diamond (rhombus) represents a decision in a flowchart. It has two exit arrows labelled YES and NO (or TRUE and FALSE). A rectangle is a process; a parallelogram is input/output; an oval is start/end.菱形(菱形)代表流程图中的判断。它有两条出口箭头,标记为"是"和"否"(或 TRUE 和 FALSE)。矩形是处理;平行四边形是输入/输出;椭圆是开始/结束。
Remember: Diamond = Decision (two exits). Rectangle = Process. Parallelogram = Input/Output. Oval = Start/End.记住:菱形 = 判断(两个出口)。矩形 = 处理。平行四边形 = 输入/输出。椭圆 = 开始/结束。
How many arrows exit a decision diamond?判断菱形有几条出口箭头?
§3 · Q2
Two (one for YES, one for NO)两条(一条表示"是",一条表示"否")
One一条
Three or more三条或更多
It depends on the number of conditions取决于条件的数量
A decision diamond always has exactly two exit arrows: one for YES (condition true) and one for NO (condition false). If you need more than two branches, use nested or sequential diamonds.判断菱形总是恰好有两条出口箭头:一条表示"是"(条件为真),一条表示"否"(条件为假)。如果需要两个以上的分支,请使用嵌套或顺序菱形。
A diamond always has exactly two exits: YES and NO. Multi-way decisions require chaining multiple diamonds.菱形总是恰好有两个出口:是和否。多路判断需要串联多个菱形。

Sequencing and Step-by-Step Execution顺序结构与逐步执行

Sequence = order matters. Every step executes exactly once, in the order written.顺序 = 顺序很重要。每个步骤按照书写的顺序恰好执行一次。
  • IPO modelIPO 模型 — Input, Process, Output. Every sequential algorithm follows this structure. AB CSE1110 B1.3 and Ontario ICS3U B1.3 both mandate the IPO model as the core problem-solving framework.— 输入(Input)、处理(Process)、输出(Output)。每个顺序算法都遵循这种结构。AB CSE1110 B1.3 和安大略 ICS3U B1.3 都将 IPO 模型规定为核心解题框架。
  • Assignment is not comparison赋值不是比较 x = 5 sets x to 5. x == 5 checks if x equals 5. Mixing these up causes logic bugs that are hard to spot.x = 5 将 x 设为 5。x == 5 检查 x 是否等于 5。混淆这两者会导致难以发现的逻辑错误。
  • Left-to-right / top-to-bottom从左到右 / 从上到下 — the computer executes statements in the order they appear (unless control flow changes this — see §3 and the Control Flow guide).— 计算机按照语句出现的顺序执行(除非控制流改变了这一点——见 §3 和控制流指南)。
AB CSE1110 outcome 1.3 says "analyze problems and determine if they can be solved using algorithms that employ an input/processing/output (IPO) approach." The IPO model is the sequential algorithm in its simplest form.AB CSE1110 结果 1.3 要求"分析问题并确定是否可以使用采用输入/处理/输出(IPO)方法的算法来解决。" IPO 模型是顺序算法的最简形式。
WE
Worked Example 4 · Temperature converter例题 4 · 温度转换器

Write a sequential algorithm to convert Celsius to Fahrenheit. Formula: F = (C × 9/5) + 32.编写一个顺序算法将摄氏度转换为华氏度。公式:F = (C × 9/5) + 32。

IPO analysis first.首先进行 IPO 分析。

  • Input: Celsius temperature (a number).输入:摄氏温度(一个数字)。
  • Process: multiply by 9, divide by 5, add 32.处理:乘以 9,除以 5,加 32。
  • Output: Fahrenheit temperature.输出:华氏温度。

Pseudocode.伪代码。

INPUT celsius
SET fahrenheit TO (celsius * 9 / 5) + 32
OUTPUT fahrenheit

Python.Python。

celsius = float(input("Enter Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(f"{celsius}°C = {fahrenheit}°F")

Notice: three lines, three phases. The order is critical — you must have the Celsius value before you can compute Fahrenheit; you must have Fahrenheit before you can output it. Swapping lines 1 and 2 causes an error.注意:三行,三个阶段。顺序至关重要——在计算华氏度之前必须有摄氏度值;在输出之前必须有华氏度。交换第 1 行和第 2 行会导致错误。

In the IPO model, which phase converts raw input into a result?在 IPO 模型中,哪个阶段将原始输入转换为结果?
§4 · Q1
Process处理
Input输入
Output输出
Algorithm算法
The Process phase contains the calculations or transformations that convert input data into the result. Input reads data in; Output displays or returns the result; Process is where the actual computation happens.处理阶段包含将输入数据转换为结果的计算或转换。输入读取数据;输出显示或返回结果;处理是实际计算发生的地方。
IPO: Input (read data), Process (transform data), Output (display/return result). The computation lives in the Process phase.IPO:输入(读取数据)、处理(转换数据)、输出(显示/返回结果)。计算在处理阶段进行。
What is the value of result after these three lines execute in order?
SET x TO 4
SET x TO x + 3
SET result TO x * 2
这三行按顺序执行后,result 的值是多少?
SET x TO 4
SET x TO x + 3
SET result TO x * 2
§4 · Q2
8
11
6
14
Step 1: x = 4. Step 2: x = 4 + 3 = 7. Step 3: result = 7 × 2 = 14. Order matters — if step 2 were skipped, result would be 4 × 2 = 8.步骤 1:x = 4。步骤 2:x = 4 + 3 = 7。步骤 3:result = 7 × 2 = 14。顺序很重要——如果跳过步骤 2,result 将是 4 × 2 = 8。
Trace line by line: x starts as 4, then becomes 7 (line 2 updates x), then result = 7 * 2 = 14.逐行追踪:x 开始为 4,然后变为 7(第 2 行更新 x),然后 result = 7 * 2 = 14。
Going deeper — why order of operations in code differs from algebra深入 — 代码中的运算顺序为何与代数不同

In algebra, x = x + 1 is a contradiction (no number equals itself plus one). In programming, it is a valid sequential statement: "take the current value of x, add 1, and store the result back in x." The variable on the left of = names the storage location to write to; the expression on the right is evaluated first using the old value, then the result is stored. This execution model — evaluate right side, assign to left side — is why SET total TO total + score accumulates a running sum correctly. AB CSE1110 outcome 2.4.6 covers "assignment, arithmetical and concatenation and interpolation operators" in this sequential context.在代数中,x = x + 1 是矛盾的(没有数字等于自身加一)。在编程中,这是一个有效的顺序语句:"取 x 的当前值,加 1,将结果存回 x。"= 左边的变量命名要写入的存储位置;右边的表达式首先使用旧值求值,然后将结果存储。这种执行模型——求右边的值,赋值给左边——是 SET total TO total + score 正确累积运行总和的原因。AB CSE1110 结果 2.4.6 在此顺序上下文中涵盖"赋值、算术和拼接与插值运算符"。


Introduction to Algorithm Efficiency算法效率初步

Count steps to compare algorithms — the one with fewer steps is (usually) faster.计步比较算法——步骤少的(通常)更快。
  • Linear search线性搜索 — check each item in turn until you find the target. For a list of n items, worst case is n steps.— 依次检查每项,直到找到目标。对于 n 项的列表,最坏情况是 n 步。
  • Binary search (sorted list required)二分搜索(需要已排序列表) — check the middle item; eliminate half the list; repeat. For n items, worst case is about log2(n) steps.— 检查中间项;排除一半列表;重复。对于 n 项,最坏情况约为 log2(n) 步。
  • Why it matters为什么重要 — for a list of 1,000 items: linear search takes up to 1,000 steps; binary search takes at most 10 steps. For 1,000,000 items: 1,000,000 vs 20 steps.— 对于 1000 项的列表:线性搜索最多需要 1000 步;二分搜索最多需要 10 步。对于 100 万项:1,000,000 步 vs 20 步。
AP CSP Big Idea 3 topic 3.17 ("Algorithmic Efficiency") and Learning Objective AAP-4.A cover exactly this comparison. ICS3U B3.1 says to "design simple algorithms" — efficiency is one criterion for choosing among alternatives.AP CSP 大概念 3 主题 3.17("算法效率")和学习目标 AAP-4.A 正是涵盖这种比较。ICS3U B3.1 要求"设计简单算法"——效率是在备选方案中选择的标准之一。
WE
Worked Example 5 · Linear vs binary search on a 16-item list例题 5 · 16 项列表上的线性搜索与二分搜索

List: [2, 5, 8, 12, 16, 23, 38, 42, 55, 60, 71, 80, 88, 91, 99, 105]. Target: 91. Count steps for each search.列表:[2, 5, 8, 12, 16, 23, 38, 42, 55, 60, 71, 80, 88, 91, 99, 105]。目标:91。计算每种搜索的步骤数。

Linear search (check index 0, 1, 2, … until found).线性搜索(检查索引 0、1、2……直到找到)。

91 at index 13 → checked indices 0-13 → 14 steps

Binary search (list has 16 items; indices 0–15).二分搜索(列表有 16 项;索引 0–15)。

Step 1: mid = 7 → list[7] = 42. 91 > 42 → search upper half [8..15]
Step 2: mid = 11 → list[11] = 80. 91 > 80 → search upper half [12..15]
Step 3: mid = 13 → list[13] = 91. FOUND! → 3 steps

Linear: 14 steps. Binary: 3 steps. For 16 items, log2(16) = 4 (upper bound), and we did it in 3. Binary search is dramatically more efficient on sorted data, but requires the list to be sorted first.线性:14 步。二分:3 步。对于 16 项,log2(16) = 4(上界),我们在 3 步内完成。二分搜索在已排序数据上效率显著更高,但需要先对列表排序。

Which of the following is a requirement for binary search to work correctly?以下哪项是二分搜索正确工作的要求?
§5 · Q1
The list must contain only numbers列表必须只包含数字
The list must have an even number of items列表必须有偶数个项目
The list must be sorted列表必须已排序
The target must be in the list目标必须在列表中
Binary search works by comparing the target to the middle element and eliminating half the list. This only works if the list is sorted — otherwise "eliminating the lower half" has no meaning.二分搜索通过将目标与中间元素比较并排除一半列表来工作。这只在列表已排序时才有效——否则"排除下半部分"毫无意义。
Binary search requires a sorted list. It works on any type of comparable data (not just numbers), any list length, and correctly returns "not found" if the target is absent.二分搜索需要已排序的列表。它适用于任何可比较的数据类型(不仅仅是数字),任何列表长度,如果目标不存在,则正确返回"未找到"。
A sorted list has 1,024 items. Approximately how many steps does binary search need in the worst case?一个已排序的列表有 1024 项。二分搜索在最坏情况下大约需要多少步?
§5 · Q2
512
10
1024
100
Binary search halves the search space each step. Starting from 1,024: 1024 → 512 → 256 → 128 → 64 → 32 → 16 → 8 → 4 → 2 → 1. That is 10 halvings. log2(1024) = 10.二分搜索每步将搜索空间减半。从 1024 开始:1024 → 512 → 256 → 128 → 64 → 32 → 16 → 8 → 4 → 2 → 1。那是 10 次减半。log2(1024) = 10。
Binary search takes log2(n) steps in the worst case. log2(1024) = 10, since 210 = 1024.二分搜索在最坏情况下需要 log2(n) 步。log2(1024) = 10,因为 210 = 1024。
Going deeper — Big-O notation Honors — ICS4U C2 / CSE3110深入 — 大 O 表示法 荣誉 — ICS4U C2 / CSE3110

Computer scientists use Big-O notation to describe how an algorithm's step count grows as the input size n grows, ignoring constant factors. Common classes: O(1) = constant (same steps regardless of n); O(log n) = logarithmic (binary search); O(n) = linear (linear search); O(n²) = quadratic (simple sorting like bubble sort on an unsorted list). Ontario ICS4U strand C2 ("analyse algorithms for their effectiveness") and Alberta CSE3110 ("compare and contrast the computational efficiencies") are the curricula that assess Big-O reasoning formally. For floor students, "more steps = slower" is sufficient.计算机科学家使用大 O 表示法来描述算法的步骤数随输入大小 n 增长而增长的方式,忽略常数因子。常见类别:O(1) = 常数(无论 n 如何,步骤数相同);O(log n) = 对数(二分搜索);O(n) = 线性(线性搜索);O(n²) = 二次(对未排序列表的简单排序,如冒泡排序)。安大略 ICS4U C 单元第 2 条("分析算法的有效性")和阿尔伯塔 CSE3110("比较计算效率")是正式评估大 O 推理的课程。对于基础学生,"更多步骤 = 更慢"就足够了。


Problem Decomposition: Worked Example问题分解:综合例题

Top-down design — start big, subdivide until each piece is small enough to code.自顶向下设计 — 从大开始,细分直到每个部分小到可以编码。
  • Level 1第 1 级 — the overall problem statement (one sentence).— 整体问题陈述(一句话)。
  • Level 2第 2 级 — the major sub-problems (3–6 items, each a clear responsibility).— 主要子问题(3-6 项,每项职责明确)。
  • Level 3第 3 级 — each sub-problem broken into steps small enough to write a pseudocode loop or decision for.— 每个子问题拆分为足够小的步骤,可以为其编写伪代码循环或判断。
CSTA 3A-AP-17: "Decompose problems into smaller components through systematic analysis." Ontario ICS3U B1.1: "stepwise refinement, divide and conquer … when solving different types of problems." AB CSE1110 outcome 1.4: "decompose the problem into its input, processing and output components."CSTA 3A-AP-17:"通过系统分析将问题分解为更小的组件。"安大略 ICS3U B1.1:"解决不同类型问题时逐步精化、分而治之……"AB CSE1110 结果 1.4:"将问题分解为输入、处理和输出组件。"
WE
Worked Example 6 · A student grade book program例题 6 · 学生成绩册程序

Problem: write a program that reads a student's scores on five assignments, computes their average, and prints a letter grade (A ≥ 90, B ≥ 80, C ≥ 70, D ≥ 60, F otherwise). Apply decomposition.问题:编写一个程序,读取学生在五项作业上的成绩,计算平均分,并打印字母等级(A ≥ 90,B ≥ 80,C ≥ 70,D ≥ 60,F 否则)。应用分解。

Level 1 — overall problem.第 1 级——整体问题。 Read 5 scores → compute average → determine letter grade → output.读取 5 个成绩 → 计算平均分 → 确定字母等级 → 输出。

Level 2 — four sub-problems.第 2 级——四个子问题。

  • Sub-problem A: Read 5 scores from the user.子问题 A:从用户读取 5 个成绩。
  • Sub-problem B: Compute the average of the 5 scores.子问题 B:计算 5 个成绩的平均值。
  • Sub-problem C: Map the average to a letter grade.子问题 C:将平均值映射到字母等级。
  • Sub-problem D: Output the average and the grade.子问题 D:输出平均分和等级。

Pseudocode (one sub-problem at a time).伪代码(每次一个子问题)。

-- Sub-problem A: Read scores
SET total TO 0
FOR i FROM 1 TO 5:
    INPUT score
    SET total TO total + score

-- Sub-problem B: Compute average
SET average TO total / 5

-- Sub-problem C: Determine grade
IF average >= 90 THEN SET grade TO "A"
ELSE IF average >= 80 THEN SET grade TO "B"
ELSE IF average >= 70 THEN SET grade TO "C"
ELSE IF average >= 60 THEN SET grade TO "D"
ELSE SET grade TO "F"

-- Sub-problem D: Output
OUTPUT average, grade

Each sub-problem is now a small, independent piece of pseudocode. You can test each part separately before combining them. This is the core benefit of decomposition: independently testable units.每个子问题现在是一小段独立的伪代码。你可以在合并之前分别测试每个部分。这是分解的核心好处:可独立测试的单元

What is the main benefit of decomposing a problem into sub-problems before writing code?在编写代码之前将问题分解为子问题的主要好处是什么?
§6 · Q1
It makes programs run faster它使程序运行更快
It eliminates all bugs它消除所有错误
It allows the program to use less memory它允许程序使用更少的内存
It makes large problems manageable by creating smaller, independently testable pieces它通过创建更小、可独立测试的部分使大问题变得可管理
Decomposition makes large problems manageable by breaking them into smaller sub-problems, each of which can be designed, written, and tested independently. It does not automatically make code faster or eliminate bugs, but it makes the development process much more tractable.分解通过将大问题拆分为更小的子问题使其变得可管理,每个子问题都可以独立设计、编写和测试。它不会自动使代码更快或消除错误,但使开发过程更加可控。
Decomposition is a design strategy, not a runtime optimization. Its benefit is manageability and testability, not speed or memory efficiency.分解是一种设计策略,而不是运行时优化。其好处是可管理性和可测试性,而不是速度或内存效率。
A student is building a calculator app. Which is the best first step using decomposition?一名学生正在构建一个计算器应用程序。使用分解的最佳第一步是什么?
§6 · Q2
Identify the major sub-problems: get input, perform operation, display result识别主要子问题:获取输入、执行操作、显示结果
Write all the code immediately立即编写所有代码
Choose a programming language first先选择编程语言
Design the visual layout of the app设计应用程序的视觉布局
Decomposition starts with identifying the major sub-problems. For a calculator: get the user's numbers and operation (input), apply the operation (process), show the answer (output). The language choice and visual design come later.分解从识别主要子问题开始。对于计算器:获取用户的数字和操作(输入),应用操作(处理),显示答案(输出)。语言选择和视觉设计稍后进行。
Decomposition means breaking the problem down first. Writing code immediately, choosing a language, or designing UI before understanding the problem structure is working in the wrong order.分解意味着首先分解问题。在理解问题结构之前立即编写代码、选择语言或设计 UI 是错误的工作顺序。

Tracing and Debugging Algorithms追踪与调试算法

Tracing = running the algorithm by hand with concrete values.追踪 = 用具体值手工运行算法。
  • Variable trace table变量追踪表 — one column per variable, one row per step. Fill in the new value every time a variable changes.— 每个变量一列,每步一行。每次变量更改时填入新值。
  • Three types of bugs三种错误类型 — (1) Syntax: code does not parse (typo in a keyword). (2) Logic: code runs but produces the wrong answer. (3) Runtime: code crashes during execution (division by zero, accessing out-of-bounds index).— (1) 语法:代码无法解析(关键字中有错别字)。(2) 逻辑:代码运行但产生错误答案。(3) 运行时:代码在执行过程中崩溃(除以零、访问越界索引)。
  • AB CSE1110AB CSE1110 outcome 1.7: "test the algorithm for failure as well as success with appropriate data"; outcome 3.1: "use appropriate test data and debugging techniques to track and correct errors including: run-time errors; logic errors."结果 1.7:"用适当数据测试算法的成功与失败情况";结果 3.1:"使用适当的测试数据和调试技术来跟踪和纠正错误,包括:运行时错误;逻辑错误。"
Ontario ICS3U B3.3 says "design algorithms to detect, intercept, and handle exceptions" — a direct link to debugging. BC Computer Programming 11 Content lists "use of test cases to detect logical or semantic errors." AB CSE1110 outcome 3.1.2: "logic errors."安大略 ICS3U B3.3 要求"设计算法以检测、拦截和处理异常"——与调试直接相关。BC Computer Programming 11 内容列出"使用测试用例检测逻辑或语义错误"。AB CSE1110 结果 3.1.2:"逻辑错误。"
WE
Worked Example 7 · Trace a buggy sum algorithm例题 7 · 追踪一个有错误的求和算法

The following pseudocode is supposed to sum the numbers 1 to 5 and output 15. Trace it and find the bug.以下伪代码本应求 1 到 5 的数字之和并输出 15。追踪它并找出错误。

Buggy pseudocode.有错误的伪代码。

SET total TO 0
SET i TO 1
WHILE i < 5:
    SET total TO total + i
    SET i TO i + 1
OUTPUT total

Trace table (variable: i, total).追踪表(变量:i,total)。

Step步骤itotalCondition i < 5?条件 i < 5?
Init初始10
111TRUE
223TRUE
336TRUE
4410TRUE
5510FALSE → exits

Bug found.找到错误。 Output is 10, not 15. The condition i < 5 stops the loop before adding 5. Fix: change to i <= 5 (or equivalently i < 6). This is a classic off-by-one logic error.输出是 10,不是 15。条件 i < 5 在添加 5 之前停止了循环。修复:改为 i <= 5(或等价地 i < 6)。这是经典的"差一"逻辑错误。

A program compiles and runs without crashing, but always prints the wrong answer. What type of error is this?一个程序能编译并运行而不崩溃,但总是打印错误答案。这是什么类型的错误?
§7 · Q1
Syntax error语法错误
Runtime error运行时错误
Logic error逻辑错误
Compilation error编译错误
A logic error is when the code runs correctly (no crash, no syntax problem) but produces the wrong output. The program's logic does not match what was intended. Tracing through the algorithm with a variable trace table is the standard technique for finding logic errors.逻辑错误是指代码正确运行(不崩溃,无语法问题)但产生错误输出。程序的逻辑与预期不符。通过变量追踪表追踪算法是查找逻辑错误的标准技术。
Syntax errors prevent compilation/parsing. Runtime errors crash the program during execution. Logic errors let the program run but produce wrong results.语法错误阻止编译/解析。运行时错误在执行过程中使程序崩溃。逻辑错误让程序运行但产生错误结果。
What is the purpose of a variable trace table when checking an algorithm?在检查算法时,变量追踪表的目的是什么?
§7 · Q2
To display the program's output on screen在屏幕上显示程序的输出
To track the value of each variable at each step so you can spot where the logic goes wrong跟踪每步每个变量的值,以便找出逻辑出错的地方
To measure how many seconds the algorithm takes to run测量算法运行需要多少秒
To count the total number of lines of code计算代码的总行数
A variable trace table records the value of each variable after each step, letting you follow the algorithm's execution by hand. When the trace table shows a value that differs from what you expected, you have found the location of the logic error.变量追踪表记录每步之后每个变量的值,让你手工跟踪算法的执行。当追踪表显示与预期不同的值时,你就找到了逻辑错误的位置。
A trace table is a hand-execution tool for correctness checking, not a timing tool or output display. It shows variable states step by step.追踪表是用于正确性检查的手工执行工具,而不是计时工具或输出显示。它逐步显示变量状态。
Going deeper — testing strategies: normal, boundary, and error cases深入 — 测试策略:正常情况、边界情况和错误情况

AB CSE1110 outcome 1.7 says to "test the algorithm for failure as well as success." A thorough test plan covers three categories: (1) Normal cases — typical valid inputs (e.g., score = 75 for a grade calculator). (2) Boundary cases — values at the exact edge of a condition (e.g., score = 90, score = 89, score = 0, score = 100 — each triggers a different branch). (3) Error/exception cases — invalid inputs that the algorithm might encounter (e.g., score = -5, score = 200, score = "hello"). Ontario ICS3U B3.3 says to "design algorithms to detect, intercept, and handle exceptions" — the error cases are what test this. BC Computer Programming 11 says "use of test cases to detect logical or semantic errors." Always test all three categories before calling an algorithm finished.AB CSE1110 结果 1.7 要求"用适当数据测试算法的成功失败情况"。完整的测试计划涵盖三个类别:(1) 正常情况——典型的有效输入(例如,成绩计算器中的分数 = 75)。(2) 边界情况——恰好在条件边缘的值(例如,分数 = 90、分数 = 89、分数 = 0、分数 = 100——每个触发不同的分支)。(3) 错误/异常情况——算法可能遇到的无效输入(例如,分数 = -5、分数 = 200、分数 = "hello")。安大略 ICS3U B3.3 要求"设计算法以检测、拦截和处理异常"——错误情况正是测试这一点的。BC Computer Programming 11 要求"使用测试用例检测逻辑或语义错误"。在宣布算法完成之前,始终测试所有三个类别。


Exam Strategy and Common Pitfalls考试策略与常见陷阱

Discipline before you code编码前的纪律
  • Decompose first, pseudocode second, code third.先分解,再写伪代码,最后写代码。 Never open a code editor before you have a clear pseudocode plan. Students who skip straight to code produce untraceable bugs. The mark-winning habit is: problem → sub-problems → pseudocode → trace → code.在有清晰伪代码计划之前,永远不要打开代码编辑器。跳过直接写代码的学生会产生难以追踪的错误。获得高分的习惯是:问题 → 子问题 → 伪代码 → 追踪 → 代码。
  • Label each pillar explicitly.明确标注每个支柱。 On a written exam, when you are asked to apply computational thinking, write the four pillar names (Decomposition, Pattern Recognition, Abstraction, Algorithmic Thinking) and state what each one contributed to your solution. Examiners are checking that you can name and apply all four.在笔试中,当被要求应用计算思维时,写出四个支柱名称(分解、模式识别、抽象、算法思维)并说明每个支柱对你的解决方案的贡献。考官在检查你是否能命名并应用全部四个支柱。
  • Trace before you submit.提交前先追踪。 On any pseudocode or algorithm question, always trace through your answer with a concrete example before moving on. A trace table takes 60 seconds and catches most off-by-one and sign errors.在任何伪代码或算法问题上,在继续之前始终用具体示例追踪你的答案。追踪表只需 60 秒,能发现大多数"差一"和符号错误。
Pseudocode and algorithm questions (§1-§4)伪代码和算法问题(§1-§4)
  • Assignment is not equality.赋值不是等式。 x = 5 sets; x == 5 tests. In AP CSP pseudocode, assignment uses the arrow (). Mixing these up is the single most common exam error in this unit.x = 5 设置值;x == 5 测试相等。在 AP CSP 伪代码中,赋值使用箭头()。混淆这两者是本单元最常见的考试错误。
  • State the IPO explicitly.明确陈述 IPO。 For any algorithm question: identify the inputs, the processing steps, and the output before writing a single line of pseudocode. Ontario ICS3U B1.3 and AB CSE1110 1.3 both assess this.对于任何算法问题:在写一行伪代码之前,确定输入、处理步骤和输出。安大略 ICS3U B1.3 和 AB CSE1110 1.3 都评估这一点。
Efficiency and tracing (§5-§7)效率和追踪(§5-§7)
  • Name the error type.命名错误类型。 When asked about a bug, state whether it is a syntax, logic, or runtime error and justify your answer. Examiners expect the correct term.当被问及错误时,说明它是语法错误、逻辑错误还是运行时错误,并证明你的答案。考官期望正确的术语。
  • Binary vs linear search argument.二分搜索与线性搜索的论据。 On efficiency questions: state the pre-condition (list must be sorted for binary), the step count (n vs log n), and a concrete example with numbers. Two sentences scores more than a vague claim.在效率问题上:说明前提条件(二分搜索需要列表已排序)、步骤数(n 对比 log n),以及带数字的具体例子。两句话比模糊的说法得分更高。
Answer hygiene作答规范
  • Use pseudocode keywords, not real-language syntax.使用伪代码关键字,而非真实语言语法。 AP CSP uses its own keyword set (DISPLAY, ←, REPEAT, etc.). Write the keywords from the reference sheet, not Python or Java syntax.AP CSP 使用其自己的关键字集(DISPLAY、←、REPEAT 等)。写参考手册中的关键字,而不是 Python 或 Java 语法。
  • Show your trace table work.展示你的追踪表工作。 When tracing, draw the table explicitly — column headers are the variable names, rows are the steps. A partial trace that reaches the error is worth more than "I ran it in my head."在追踪时,明确画出表格——列标题是变量名称,行是步骤。到达错误的部分追踪比"我在脑子里运行了它"更有价值。

Flashcards闪卡

0 / 14 flipped0 / 14 已翻
Decomposition分解
Breaking a complex problem into smaller, manageable sub-problems. CSTA 3A-AP-17.将复杂问题分解为更小、可管理的子问题。CSTA 3A-AP-17。
Abstraction抽象
Stripping away irrelevant detail; keeping only what matters for solving the problem. E.g., a map abstracts a city.去除无关细节;只保留解决问题所需的内容。例如,地图是城市的抽象。
Pattern recognition模式识别
Spotting similarities or repeated structures across problems or within data, allowing solution reuse.发现问题间或数据内的相似性或重复结构,从而实现解决方案复用。
Algorithmic thinking算法思维
Expressing a solution as a precise, unambiguous, step-by-step sequence that anyone (or any computer) can follow.将解决方案表达为任何人(或计算机)都能遵循的精确、无歧义的逐步序列。
What is an algorithm?什么是算法?
A precise, finite, step-by-step procedure for solving a problem. Must be finite, definite, and effective.解决问题的精确、有限的逐步程序。必须是有限的、确定的和有效的。
What is pseudocode?什么是伪代码?
Human-readable algorithm notation, structured but not tied to any language. Uses keywords like INPUT, OUTPUT, IF, WHILE, FOR, SET.人类可读的算法表示法,结构化但不依附于任何语言。使用关键字如 INPUT、OUTPUT、IF、WHILE、FOR、SET。
Flowchart diamond shape?流程图菱形形状?
Decision (yes/no question). Has exactly two exit arrows: YES and NO.判断(是/否问题)。恰好有两条出口箭头:是和否。
Flowchart four shapes?流程图四种形状?
Oval = Start/End. Rectangle = Process. Parallelogram = Input/Output. Diamond = Decision.椭圆 = 开始/结束。矩形 = 处理。平行四边形 = 输入/输出。菱形 = 判断。
IPO modelIPO 模型
Input → Process → Output. Every sequential algorithm follows this structure. AB CSE1110 outcome 1.3; ON ICS3U B1.3.输入 → 处理 → 输出。每个顺序算法都遵循这种结构。AB CSE1110 结果 1.3;ON ICS3U B1.3。
Linear search step count?线性搜索步骤数?
Worst case: n steps (check every item). No pre-condition needed. Simple but slow for large lists.最坏情况:n 步(检查每项)。不需要前提条件。简单但对大列表较慢。
Binary search step count?二分搜索步骤数?
Worst case: log₂(n) steps. Requires sorted list. 1024 items → at most 10 steps.最坏情况:log₂(n) 步。需要已排序列表。1024 项 → 最多 10 步。
Three types of program errors?三种程序错误类型?
Syntax: code doesn't parse. Logic: runs but wrong answer. Runtime: crashes during execution.语法:代码无法解析。逻辑:运行但答案错误。运行时:执行过程中崩溃。
Variable trace table变量追踪表
A hand-execution table: one column per variable, one row per step. Records the value of each variable after each step. Used to find logic errors.手工执行表:每个变量一列,每步一行。记录每步后每个变量的值。用于查找逻辑错误。
Off-by-one error差一错误
A logic error where a loop runs one too many or one too few times. E.g., WHILE i < 5 stops at i=4, missing the 5. Fix: WHILE i <= 5.循环运行次数多一次或少一次的逻辑错误。例如,WHILE i < 5 在 i=4 时停止,遗漏了 5。修复:WHILE i <= 5。

Practice Quiz综合测验

You are building a program to find the largest number in a list of exam scores. Applying computational thinking, which step comes first?你正在构建一个程序来找出一列考试成绩中的最大值。应用计算思维,哪个步骤最先?
Q1
Write the Python code编写 Python 代码
Decompose: identify the sub-problems (read scores, compare, track maximum, output)分解:识别子问题(读取成绩、比较、跟踪最大值、输出)
Draw a flowchart画流程图
Choose a programming language选择编程语言
Decomposition is always the first step. Identify sub-problems first, then write pseudocode, then code.分解始终是第一步。先识别子问题,再写伪代码,再写代码。
Computational thinking workflow: problem → decompose → pseudocode → trace → code.计算思维工作流程:问题 → 分解 → 伪代码 → 追踪 → 代码。
What does the pseudocode line SET max TO scores[0] do?伪代码行 SET max TO scores[0] 做什么?
Q2
Tests if max equals scores[0]测试 max 是否等于 scores[0]
Adds scores[0] to the variable max将 scores[0] 添加到变量 max
Assigns the value of scores[0] to the variable max将 scores[0] 的值赋给变量 max
Prints the value of max打印 max 的值
SET x TO value is assignment — it stores the value in the variable. This sets max to the first item in the scores list.SET x TO value 是赋值——它将值存储在变量中。这将 max 设置为成绩列表中的第一项。
SET...TO is assignment. To test equality you would write IF max = scores[0] THEN.SET...TO 是赋值。测试相等需写 IF max = scores[0] THEN。
In a flowchart for "if temperature > 30 then output WARN else output OK," how many decision diamonds are needed?在"如果温度 > 30 则输出 WARN 否则输出 OK"的流程图中,需要多少个判断菱形?
Q3
One一个
Two两个
Three三个
None没有
One condition = one diamond. The diamond's YES path goes to WARN; the NO path goes to OK.一个条件 = 一个菱形。菱形的是路径通向 WARN;否路径通向 OK。
One condition, one diamond. Two outputs but only one decision point.一个条件,一个菱形。两个输出但只有一个决策点。
Trace this pseudocode with input 6. What is the output?
INPUT n | SET result TO 1
FOR i FROM 1 TO n: SET result TO result * i
OUTPUT result
用输入 6 追踪以下伪代码。输出是什么?
INPUT n | SET result TO 1
FOR i FROM 1 TO n: SET result TO result * i
OUTPUT result
Q4
6
21
36
720
This computes 6! (factorial). Trace: 1→1→2→6→24→120→720. Output: 720.这计算 6!(阶乘)。追踪:1→1→2→6→24→120→720。输出:720。
Trace: i=1:1, i=2:2, i=3:6, i=4:24, i=5:120, i=6:720.追踪:i=1:1, i=2:2, i=3:6, i=4:24, i=5:120, i=6:720。
A sorted list has 1,024 items. Using binary search, what is the maximum number of comparisons needed?一个已排序的列表有 1024 项。使用二分搜索,最多需要多少次比较?
Q5
256
10
1024
100
log₂(1024) = 10 (since 2¹⁰ = 1024). Binary search halves the list each step, taking at most log₂(n) steps.log₂(1024) = 10(因为 2¹⁰ = 1024)。二分搜索每步将列表减半,最多需要 log₂(n) 步。
Binary search: log₂(n) steps max. 2¹⁰ = 1024 ⇒ log₂(1024) = 10.二分搜索:最多 log₂(n) 步。2¹⁰ = 1024 ⇒ log₂(1024) = 10。
An algorithm outputs 10 instead of 15 (should sum 1+2+3+4+5). It runs without crashing. What type of bug is this?一个算法输出 10 而不是 15(应求 1+2+3+4+5 的和)。它运行不崩溃。这是什么类型的错误?
Q6
Syntax error语法错误
Runtime error运行时错误
Logic error (off-by-one: condition should be <= 5)逻辑错误(差一:条件应为 <= 5)
No error — 10 is correct没有错误 — 10 是正确的
Runs without crash (not syntax/runtime). Wrong answer (logic error). Classic off-by-one: WHILE i < 5 stops before adding 5. Fix: i <= 5.运行不崩溃(不是语法/运行时错误)。答案错误(逻辑错误)。经典差一错误:WHILE i < 5 在添加 5 之前停止。修复:i <= 5。
Runs without crash = not syntax/runtime. Wrong answer = logic error.运行不崩溃 = 不是语法/运行时。答案错误 = 逻辑错误。
Which CSTA standard says "Decompose problems into smaller components through systematic analysis"? 🇺🇸 CSTA哪个 CSTA 标准说"通过系统分析将问题分解为更小的组件"?🇺🇸 CSTA
Q7
3A-AP-17
3A-AP-13
3B-AP-15
3A-IC-26
CSTA 3A-AP-17 (verbatim): "Decompose problems into smaller components through systematic analysis, using constructs such as procedures, modules, and/or objects."CSTA 3A-AP-17(原文):"通过系统分析将问题分解为更小的组件,使用过程、模块和/或对象等构造。"
3A-AP-17 = decomposition. 3A-AP-13 = prototypes using algorithms. 3B-AP-15 = generalizable patterns. 3A-IC-26 = algorithms across disciplines.3A-AP-17 = 分解。3A-AP-13 = 使用算法的原型。3B-AP-15 = 可概括模式。3A-IC-26 = 跨学科算法。

Readiness Checklist准备就绪清单

Tick each item when you can do it cold, without notes, on a first attempt.能在无笔记、首次尝试下完成,再勾选每一项。

0 / 11 mastered已掌握 0 / 11

What This Feeds Into本单元的去向

Computational thinking is the conceptual bedrock of every topic in this HS Computer Science series. Every subsequent guide (control flow, functions, data structures, OOP) assumes you can decompose a problem before you code, write clear pseudocode, trace an algorithm, and reason informally about efficiency. The two downstream AP courses both assume this unit has already been covered. The links below point at the existing AP CSA guide (which uses Java OOP but depends on exactly the algorithmic thinking taught here) and are provided only for files confirmed to exist in this repo.计算思维是本 HS 计算机科学系列中每个主题的概念基础。后续每本指南(控制流、函数、数据结构、OOP)都假定你能在编码前分解问题、编写清晰的伪代码、追踪算法,并非正式地推理效率。两门下游 AP 课程都假定本单元已经学过。以下链接指向现有 AP CSA 指南(使用 Java OOP,但依赖于这里所教授的算法思维),仅提供已确认存在于本仓库的文件链接。

Within High School Computer Science.在 HS Computer Science 内部。

The next unit (Programming Fundamentals) translates the pseudocode and IPO patterns you learned here into actual variables, data types, and I/O in a real language. Control Flow adds selection and iteration to the sequential step-by-step execution of §4. Functions and Modular Design formalises the decomposition you practiced in §6 into callable sub-programs with parameters. Every later unit reuses the algorithmic thinking and tracing discipline from this guide.下一单元(编程基础)将你在这里学到的伪代码和 IPO 模式转化为真实语言中的实际变量、数据类型和 I/O。控制流在 §4 的顺序逐步执行基础上添加选择和迭代。函数与模块化设计将 §6 中练习的分解正式化为带参数的可调用子程序。每个后续单元都重用本指南中的算法思维和追踪纪律。

AP feeder links (existing in this repo).AP 衔接链接(本仓库中已有)。

AP CSA Unit 1 · Using Objects and Methods (Java OOP: the algorithmic thinking and pseudocode-to-code translation practiced here is the foundation AP CSA builds on from day one)AP CSA Unit 1 · 使用对象和方法(Java 面向对象:这里练习的算法思维和伪代码转代码是 AP CSA 从第一天起就依赖的基础)

The AP CSP feeder (Big Idea 3, Algorithms & Programming, 30–35% of the exam) directly tests pseudocode fluency, decomposition, and algorithm efficiency reasoning covered in this guide. AP CSA (Java-specific, the downstream programming course) assumes you can decompose problems, write clean step-by-step algorithms, and trace code by hand before the first class. Both courses benefit from mastering this unit thoroughly before attempting either AP.AP CSP 衔接(大概念 3,算法与编程,占考试 30–35%)直接测试本指南所涵盖的伪代码流利度、分解和算法效率推理。AP CSA(Java 专项,下游编程课程)假定你在第一堂课之前就能分解问题、编写清晰的逐步算法并手工追踪代码。在尝试任一 AP 课程之前,彻底掌握本单元对两门课程都有益。