COMP90038

COMP90038 · Algorithms and ComplexityCOMP90038 · 算法与复杂度

UniMelb's graduate gateway to algorithm design — asymptotic analysis, classic data structures, and the four core design paradigms.墨大研究生算法设计入门课 —— 渐进复杂度分析、经典数据结构,以及四大核心算法设计范式。

COMP90038 teaches you to design efficient algorithms and reason formally about their complexity, covering asymptotic notation, abstract data types (queues, trees, priority queues, graphs), and the brute-force, divide-and-conquer, dynamic-programming and greedy paradigms. Assessment is two assignments, weekly quizzes, and a 60% final exam. This guide is built from 37 real COMP90038 course materials in the AskSia Library.

COMP90038 教你设计高效算法并对其复杂度进行严格分析,内容涵盖渐进记号、抽象数据类型(队列、树、优先队列、图),以及暴力法、分治、动态规划与贪心四大范式。考核为两次作业、每周小测,外加占 60% 的期末闭卷考试。本指南基于AskSia Library 中 37 份真实 COMP90038 课程材料整理而成。

Built from 37 real COMP90038 course materials in the AskSia Library.

基于AskSia Library 中 37 份真实 COMP90038 课程材料整理而成。

Faculty院系School of Computing and Information Systems · Faculty of Engineering and Information TechnologyLevel层级Graduate / postgraduateCredit学分12.5 ptsSemester学期2026 Semester 1Prereq先修None (entry-level graduate subject). Assumes solid programming (conditionals, loops, functions), elementary data structures (arrays, records, linked lists), and Year-12 mathematics (functions, basic calculus, basic discrete maths) — typically met by an undergraduate degree in a cognate discipline.Campus校区Parkville
📚 AskSia Library data·37 AskSia Library resources·11 topics·40% coursework (2 × 15% assignments + 10% weekly quizzes) + 60% open-book final exam (hurdle: ≥30/60 on the exam and ≥50/100 overall).Built from 37 real COMP90038 materials in the AskSia Library, including the 2026 sample exam with full solutions, Assignment 1 and A2 solutions, all 21 lecture decks, and the weekly tutorial solution sets.
📚 AskSia Library 数据·37 份 AskSia Library 资料·11 个主题·40% 平时分(两次各 15% 的作业 + 10% 每周小测)+ 60% 开卷期末考(门槛:期末考须达 30/60,且总评须达 50/100)。基于 AskSia Library 中 37 份真实 COMP90038 材料整理而成,含带完整解答的 2026 年样卷、作业一与作业二的解答、全部 21 套讲义,以及每周辅导课的解答集。
Overview课程概览

What COMP90038 is aboutCOMP90038 讲什么

COMP90038 Algorithms and Complexity is a graduate-level subject in the School of Computing and Information Systems at the University of Melbourne. It introduces the theory of computational efficiency and the classic algorithms and data structures used to solve fundamental problems — computing distances in networks, searching large collections, and sorting. Students learn to analyse algorithm complexity using asymptotic notation, work with abstract data types such as queues, trees, priority queues and graphs, and apply the four core design paradigms: brute force, divide-and-conquer, dynamic programming and greedy. The subject also covers space–time trade-offs and the theoretical limits of algorithmic power.

COMP90038《算法与复杂度》是墨尔本大学计算与信息系统学院开设的研究生科目。它讲授计算效率理论,以及用来解决基础问题(如网络中的最短距离、大规模集合的查找与排序)的经典算法和数据结构。学生将学会用渐进记号分析算法复杂度,掌握队列、树、优先队列、图等抽象数据类型,并运用暴力法、分治、动态规划、贪心四大核心设计范式;课程还涉及空间—时间权衡以及算法能力的理论极限。

Topic map知识地图

The COMP90038 syllabus, topic by topicCOMP90038 大纲 · 逐个主题

1

Asymptotic notation & complexity classes渐进记号与复杂度分类

Big-O, Big-Omega and Big-Theta notation to describe how an algorithm's running time and space grow with input size. The foundation for comparing algorithms independently of hardware.

用大 O、大 Ω、大 Θ 记号刻画算法运行时间与空间随输入规模的增长趋势,是脱离硬件横向比较算法效率的基础。

2

Analysis of algorithms (mathematical & empirical)算法分析(数学分析与经验分析)

Deriving the cost of non-recursive and recursive algorithms, setting up and solving recurrence relations, and measuring performance empirically by timing real runs.

推导非递归与递归算法的代价,建立并求解递推关系式,并通过实际运行计时进行经验性能测量。

3

Fundamental data structures基础数据结构

Arrays, linked lists, stacks and queues — their representations and the cost of core operations, plus how the choice of structure drives an algorithm's efficiency.

数组、链表、栈与队列的表示方式及核心操作代价,以及数据结构选择如何决定算法效率。

4

Trees, priority queues & heaps树、优先队列与堆

Binary search trees (inorder traversal yields keys in sorted order, but height can degrade to O(n)), and the two self-balancing structures COMP90038 examines: AVL trees — kept balanced via R / L / LR / RL rotations at the lowest node whose balance factor (height of left minus height of right) reaches ±2 — and 2-3 trees, where an overflowing 3-node splits and promotes its middle key. Heaps are complete binary trees stored in an array (children of node i at 2i and 2i+1); heapify runs in O(n), and heapsort, push, pop and update-key each cost O(log n).

二叉搜索树(中序遍历给出有序的键,但高度可能退化为 O(n)),以及 COMP90038 考查的两种自平衡结构:AVL 树——在平衡因子(左子树高减右子树高)达到 ±2 的最低节点处通过 R / L / LR / RL 旋转维持平衡——与 2-3 树,其中溢出的 3-节点会分裂并把中间键上提。堆是用数组存储的完全二叉树(节点 i 的子节点位于 2i 与 2i+1);建堆为 O(n),堆排序、入堆、出堆与改键各为 O(log n)。

5

Hashing & space–time trade-offs哈希与空间—时间权衡

Hash tables, collision handling, and the general principle of trading extra memory for faster access (e.g. input enhancement and precomputation).

哈希表、冲突处理,以及用额外内存换取更快访问的一般原理(如输入增强与预计算)。

6

Brute force & exhaustive search暴力法与穷举搜索

The brute-force design paradigm: straightforward but often costly approaches such as sequential search, selection/bubble sort, and exhaustive enumeration.

暴力设计范式:直接但常常代价高昂的方法,如顺序查找、选择/冒泡排序与穷举枚举。

7

Divide-and-conquer分治法

Splitting a problem into subproblems, solving recursively, and combining results — mergesort (Θ(n log n), stable, the optimal comparison sort) and quicksort (O(n log n) expected, O(n²) worst case). The course requires you to apply the Master Theorem to any recurrence T(n)=a·T(n/b)+Θ(n^d): compare a against b^d — a < b^d gives Θ(n^d), a = b^d gives Θ(n^d log n), a > b^d gives Θ(n^{log_b a}). Reconstructing a tree's postorder from its preorder and inorder traversals is a recurring exam mechanic here.

将问题拆分为子问题、递归求解再合并结果——归并排序(Θ(n log n),稳定,最优的比较排序)与快速排序(期望 O(n log n),最坏 O(n²))。本课要求你对任意递推式 T(n)=a·T(n/b)+Θ(n^d) 套用主定理:比较 a 与 b^d——a < b^d 得 Θ(n^d),a = b^d 得 Θ(n^d log n),a > b^d 得 Θ(n^{log_b a})。由前序与中序遍历重建出树的后序遍历是这里反复出现的考点。

8

Graphs & graph algorithms图与图算法

Adjacency matrix (O(V²) space, O(1) edge test) versus adjacency lists (O(V+E)) — this representation choice sets traversal cost at O(V²) versus O(V+E). One unified framework drives both traversals: a stack gives DFS, a queue gives BFS (and in an unweighted graph the BFS tree is the shortest-path tree). DFS-based topological sort emits nodes in reverse finish order, with ties broken alphabetically in the exam; connected components are found by repeated flood-fill in O(V+E). Warshall computes transitive closure (R^k via ∨/∧) and Floyd computes all-pairs shortest paths (D^k via min/+), both Θ(n³).

邻接矩阵(O(V²) 空间,O(1) 边判定)对比邻接表(O(V+E))——这一表示选择决定了遍历代价是 O(V²) 还是 O(V+E)。一套统一框架驱动两种遍历:用栈得 DFS,用队列得 BFS(在无权图中,BFS 树即最短路径树)。基于 DFS 的拓扑排序按逆完成顺序输出节点,考试中并列时按字母序打破;连通分量通过重复 flood-fill 以 O(V+E) 求得。Warshall 计算传递闭包(R^k 用 ∨/∧),Floyd 计算全源最短路(D^k 用 min/+),二者均为 Θ(n³)。

9

Dynamic programming动态规划

Solving problems with overlapping subproblems by storing intermediate results, avoiding redundant recomputation.

针对含重叠子问题的问题,通过存储中间结果避免重复计算来求解。

10

Greedy algorithms贪心算法

Making the locally optimal choice at each step, and the conditions under which this yields a globally optimal solution (e.g. minimum spanning trees, Dijkstra).

每步做出局部最优选择,以及这种策略能得到全局最优解的条件(如最小生成树、Dijkstra 算法)。

11

Limits of algorithmic power算法能力的极限

Lower bounds, decision trees, and an introduction to the theoretical limits of what algorithms can achieve, including the P vs NP distinction.

下界、决策树,以及对算法能力理论极限的引入,包括 P 与 NP 之分。

Assessment考核方式

How COMP90038 is assessedCOMP90038 怎么考核

Final exam: Yes期末考试:有
Component考核项 Weight占比 Note说明
Weekly online quizzes (10 quizzes, 1% each)每周在线小测(共 10 次,每次 1%) 10% One short quiz most teaching weeks across the semester.学期内大部分教学周各有一次简短小测。
Assignment 1作业一 15% Due around Week 6.约第 6 周提交。
Assignment 2作业二 15% Due around Week 11.约第 11 周提交。
Final examination (3-hour)期末考试(3 小时) 60% Held in the end-of-semester exam period. Hurdle: must score at least 30/60 on the exam, and at least 50/100 overall, to pass.在学期末考试周举行。门槛要求:期末考至少 30/60,且总评至少 50/100 方可通过。

40% coursework (two 15% assignments + 10% weekly quizzes) + a 60% final exam, which is a hurdle (≥30/60 on the exam and ≥50/100 overall required to pass).

40% 平时分(两次各 15% 的作业 + 10% 每周小测)+ 60% 期末考;期末考为门槛项(须达 30/60,且总评须达 50/100 才能通过)。

Assessment timeline考核时间线

When each COMP90038 task is dueCOMP90038 各项考核时间

Weekly online quizzes (10 × 1%)每周在线小测(10 次,每次 1%)
Weeks ~2–11 (one most teaching weeks)约第 2–11 周(大部分教学周各一次)
10%
Assignment 1 (recurrences + design)作业一(递推式 + 算法设计)
Due around Week 6约第 6 周提交
15%
Assignment 2 (algorithm design)作业二(算法设计)
Due around Week 11约第 11 周提交
15%
Final examination (3-hour, open book, hurdle)期末考试(3 小时,开卷,门槛项)
End-of-semester exam period学期末考试周
60%
Self-test自测练习

Test yourself: COMP90038 practice questions自测一下:COMP90038 练习题

Question 1第 1 题
You apply the Master Theorem to T(n) = 2·T(n/4) + Θ(n). Identifying a = 2, b = 4, d = 1, you compare a against b^d. What is the tight bound?对 T(n) = 2·T(n/4) + Θ(n) 套用主定理。识别出 a = 2、b = 4、d = 1 后,比较 a 与 b^d。其紧确界是多少?
  1. Θ(n)
  2. Θ(n log n)
  3. Θ(n^1.5)
  4. Θ(√n)
  1. Θ(n)
  2. Θ(n log n)
  3. Θ(n^1.5)
  4. Θ(√n)
Show answer查看答案
Answer: A. Θ(n)b^d = 4^1 = 4, and a = 2 < 4, so this is the leaf-dominated case a < b^d, giving Θ(n^d) = Θ(n). The trap is flipping the comparison or defaulting to the a = b^d case (Θ(n^d log n)), which only applies when a equals b^d (e.g. mergesort's 2·T(n/2)+Θ(n)).
答案:A. Θ(n)b^d = 4^1 = 4,而 a = 2 < 4,属于叶子主导情形 a < b^d,得 Θ(n^d) = Θ(n)。陷阱是把比较方向写反,或误用 a = b^d 情形(Θ(n^d log n))——后者只在 a 恰等于 b^d 时成立(如归并排序的 2·T(n/2)+Θ(n))。
Question 2第 2 题
Using h(k) = k mod 11 with separate chaining into a table of size m = 11, which pair of keys collides in the SAME bucket?用 h(k) = k mod 11、链地址法插入大小 m = 11 的表,下列哪一对键会碰撞到同一个桶?
  1. 18 and 25
  2. 18 and 40
  3. 18 and 30
  4. 18 and 27
  1. 18 与 25
  2. 18 与 40
  3. 18 与 30
  4. 18 与 27
Show answer查看答案
Answer: B. 18 and 40h(18) = 18 mod 11 = 7 and h(40) = 40 mod 11 = 7 (40 − 33 = 7), so 18 and 40 chain together in bucket 7. The others differ: 25 mod 11 = 3, 30 mod 11 = 8, 27 mod 11 = 5 — none equal to 7. The exam mechanic: compute k mod m for each key and group equal remainders into one chain; the longest chain's length is the largest such group. m is prime here precisely to spread keys and avoid the pathological clustering a composite modulus can cause.
答案:B. 18 与 40h(18) = 18 mod 11 = 7,h(40) = 40 mod 11 = 7(40 − 33 = 7),故 18 与 40 链入同一个桶 7。其余各异:25 mod 11 = 3,30 mod 11 = 8,27 mod 11 = 5,均不等于 7。考试机制:对每个键算 k mod m,余数相同者归入同一条链;最长链长度即最大的那一组。这里 m 取素数正是为了让键分散、避免合数模可能造成的病态聚集。
Question 3第 3 题
A min-heap is stored 1-indexed in an array as [4, 9, 7, 14, 11, 8]. You perform one delete-min. After swapping the last element into the root and bubbling down, which array results?一个 1-索引的最小堆以数组 [4, 9, 7, 14, 11, 8] 存储。你执行一次 delete-min。把最后一个元素换到根并下沉后,得到的数组是哪一个?
  1. [7, 9, 8, 14, 11]
  2. [8, 9, 7, 14, 11]
  3. [7, 9, 8, 11, 14]
  4. [8, 11, 7, 14, 9]
  1. [7, 9, 8, 14, 11]
  2. [8, 9, 7, 14, 11]
  3. [7, 9, 8, 11, 14]
  4. [8, 11, 7, 14, 9]
Show answer查看答案
Answer: A. [7, 9, 8, 14, 11]Delete-min removes 4; move the last element 8 to the root → [8, 9, 7, 14, 11]. Bubble-down: children of index 1 are 9 (idx 2) and 7 (idx 3); the smaller is 7, and 7 < 8, so swap → [7, 9, 8, 14, 11]. Now 8 at index 3 has no children (n = 5), so stop. Trap: bubble down toward the SMALLER child in a min-heap, and the last leaf — not the second element — is what moves to the root.
答案:A. [7, 9, 8, 14, 11]delete-min 删去 4;把最后一个元素 8 移到根 → [8, 9, 7, 14, 11]。下沉:索引 1 的子节点是 9(索引 2)与 7(索引 3),较小者为 7,且 7 < 8,交换 → [7, 9, 8, 14, 11]。此时索引 3 的 8 无子节点(n = 5),停止。陷阱:最小堆中要朝较小的子节点下沉;移到根的是最后一个叶子,而非第二个元素。
Exam questions考试题型

High-value exam questions in COMP90038COMP90038 高频考点 · 考试风格题

AVL trees (CH7)AVL 树(CH7)
Insert a sequence of ~8 keys one-by-one into an empty AVL tree and report how many rotations of each type (R / L / LR / RL) occur. Decide each rotation by the new node's path relative to the lowest node whose |balance factor| reaches 2.把约 8 个键逐个插入空 AVL 树,统计各类旋转(R / L / LR / RL)各发生几次。每次旋转的类型由新节点相对「平衡因子绝对值首次达到 2 的最低节点」的路径决定。
Recurring Q1-MCQ trace type seen in the 2026 sample exam. Re-number with fresh keys; never reuse the original key sequence.
2026 样卷 Q1 选择题中反复出现的手算题型。请用新键重新编号,切勿照搬原始键序列。
2-3 trees (CH7)2-3 树(CH7)
Insert a key sequence into an empty 2-3 tree and count how many DISTINCT 3-nodes are created over the whole build (a 3-node overflows into a split, promoting its middle key — which may cascade).把一组键插入空 2-3 树,统计整个构建过程中共创建了多少个不同的 3-节点(3-节点溢出会分裂并上提中间键,可能级联)。
Sample-exam Q1 trace type. The trap is counting only the final 3-nodes, not every one ever created.
样卷 Q1 手算题型。陷阱是只数最终的 3-节点,而非曾经创建过的全部 3-节点。
Hashing — chaining vs probing (CH8)哈希——链地址法对比探测法(CH8)
Given the same ~8 integer keys and h(k) = k mod m (m ≈ 11): (i) under separate chaining, report the length of the longest chain; (ii) under linear probing, identify the resulting table. The paired contrast on identical keys is the recurring device.给定相同的约 8 个整数键与 h(k) = k mod m(m ≈ 11):(i) 链地址法下报告最长链的长度;(ii) 线性探测下指出最终的表。对同一组键做这两种对比是反复出现的考法。
Sample-exam Q1(c)/(d) pairing. m must be prime; probing is insertion-order-sensitive with wrap-around.
样卷 Q1(c)/(d) 配对。m 须为素数;探测法对插入顺序敏感且会环绕回头。
Master Theorem & recurrences (CH1/CH5)主定理与递推式(CH1/CH5)
Solve a recurrence T(n) = a·T(n/b) + Θ(n^d) two ways: (a) by backward-substitution/expansion to the base case, and (b) by the Master Theorem — naming a, b, d and the case (a<b^d, a=b^d, or a>b^d).用两种方法求解递推式 T(n) = a·T(n/b) + Θ(n^d):(a) 反向代入/展开至基例;(b) 套用主定理——指明 a、b、d 与所属情形(a<b^d、a=b^d 或 a>b^d)。
Sample-exam Q6 type; the Master Theorem MUST be remembered and applied per the course. The trap is flipping the a-vs-b^d comparison.
样卷 Q6 题型;本课要求必须记住并会套用主定理。陷阱是把 a 与 b^d 的比较方向写反。
Min-heap heapify + delete-min (CH6)最小堆建堆 + delete-min(CH6)
(a) Heapify a ~9-element array into a MIN-heap and write the array; (b) perform one delete-min and write the resulting array — shown as an array-index trace, not just a tree picture.(a) 把约 9 个元素的数组建成最小堆并写出数组;(b) 执行一次 delete-min 并写出结果数组——以数组下标的形式展示,而非仅画树。
Sample-exam Q5 type. Read MIN vs max carefully; heapify is bottom-up and O(n); after delete-min the last leaf moves to the root.
样卷 Q5 题型。注意区分最小堆与最大堆;建堆是自底向上、O(n);delete-min 后由最后一个叶子移到根。
Warshall / Floyd matrices (CH9)Warshall / Floyd 矩阵(CH9)
Given a (di)graph, identify the correct R^k transitive-closure matrix (Warshall, ∨/∧) or D^k all-pairs distance matrix (Floyd, min/+) after k rounds. The superscript k means intermediate node ids ≤ k.给定一个(有向)图,识别 k 轮后正确的 R^k 传递闭包矩阵(Warshall,∨/∧)或 D^k 全源距离矩阵(Floyd,min/+)。上标 k 表示中间节点编号 ≤ k。
Sample-exam Q1(e)/(f) types. Warshall uses boolean ∨/∧; Floyd uses min/+ with ∞ off-edges and 0 on the diagonal.
样卷 Q1(e)/(f) 题型。Warshall 用布尔 ∨/∧;Floyd 用 min/+,非边为 ∞、对角线为 0。
Tree reconstruction (CH5)二叉树重建(CH5)
Given the preorder and inorder traversals of a binary tree, determine the postorder. Preorder[0] is the root; locate it in inorder to split left/right subtrees, then recurse.给定一棵二叉树的前序与中序遍历,求其后序遍历。前序的第一个元素是根;在中序中定位它以划分左右子树,再递归。
Sample-exam Q1(g) type. The trap is swapping the roles of preorder (gives roots) and inorder (splits L/R).
样卷 Q1(g) 题型。陷阱是把前序(给出根)与中序(划分左右)的角色弄反。
DFS topological sort (CH3)DFS 拓扑排序(CH3)
Given a DAG, produce the topological order by the DFS method: output nodes in reverse finish (pop) order, breaking ties alphabetically when choosing the next unvisited neighbour.给定一个 DAG,用 DFS 方法给出拓扑序:按逆完成(出栈)顺序输出节点,在选择下一个未访问邻居时按字母序打破并列。
Sample-exam Q1(h) type. The trap is using push order instead of reverse-pop, or ignoring the alphabetical tie-break.
样卷 Q1(h) 题型。陷阱是用入栈顺序代替逆出栈顺序,或忽略字母序的并列打破规则。
MST / Dijkstra design (CH10)最小生成树 / Dijkstra 设计(CH10)
Compute an MST's total weight via Prim/Kruskal (Q1-MCQ), or a higher-mark design: e.g. nearest-of-k-sites for every node in O((n+m) log n) independent of k, using a virtual super-source joined to all sites by 0-weight edges and one Dijkstra. Always STATE and JUSTIFY both the time and space bound.用 Prim/Kruskal 计算最小生成树的总权(Q1 选择题),或更高分的设计题:例如在 O((n+m) log n)、与 k 无关的时间内为每个节点求 k 个站点中最近者——用一个以 0 权边连到所有站点的虚拟超级源点跑一次 Dijkstra。务必陈述并论证时间与空间界。
Sample-exam Q1(i) (MST weight) and Q10 (super-source design) types. In design questions, marks live in justifying BOTH bounds.
样卷 Q1(i)(最小生成树权重)与 Q10(超级源点设计)题型。设计题的分数在于论证时间与空间两个界。
Asymptotic true/false with justification (CH1)渐进记号的判断题并说明理由(CH1)
Decide whether an asymptotic or data-structure claim is true or false AND justify it — for an asymptotic claim by exhibiting the constants c1, c2; for an 'always/never' claim by a concrete counterexample (e.g. an unbalanced BST has height n−1, so 'a BST is O(log n)' is false).判断一个渐进或数据结构命题是真是假并说明理由——渐进命题给出常数 c1、c2;「总是/从不」类命题给出具体反例(如不平衡 BST 高度为 n−1,故「BST 是 O(log n)」为假)。
Sample-exam Q2 type (2 marks = 1 answer + 1 justification). The trap is answering true/false with no justification, which earns half marks.
样卷 Q2 题型(2 分 = 1 分答案 + 1 分理由)。陷阱是只答真假不给理由,只得一半分。
Worked example例题精解

A worked COMP90038 problemCOMP90038 例题

Nearest of k sites, in O((n+m) log n) — independent of k在 O((n+m) log n) 内求每个点到 k 个站点中最近者——与 k 无关

Problem题目

You are given a weighted, non-negative graph G with n nodes and m edges, and a set of k special 'site' nodes (e.g. hospitals). For every node in the graph, report the distance to its nearest site. The naive approach — run Dijkstra once from each of the k sites — costs O(k·(n+m) log n), which is too slow when k is large. Design an algorithm that runs in O((n+m) log n), independent of k.

给定一个非负权图 G,含 n 个节点、m 条边,以及一组 k 个特殊「站点」节点(如医院)。请为图中每个节点报告其到最近站点的距离。朴素做法——从 k 个站点各跑一次 Dijkstra——代价为 O(k·(n+m) log n),当 k 较大时太慢。请设计一个运行在 O((n+m) log n)、与 k 无关的算法。

Approach解题思路

Add a virtual super-source s* and connect it to every site with a 0-weight edge. Run a single Dijkstra from s* on this augmented graph: because every site sits at distance 0 from s*, the shortest path from s* to any node v passes through v's nearest site, so dist(s*, v) is exactly the distance to the nearest site. To name which site is nearest, run one DFS over the resulting shortest-path tree tracking the most-recent site seen on the path from the root — the lowest site-ancestor of each node is its nearest site. Augmenting is O(k), the single Dijkstra is O((n+1+m+k) log n) = O((n+m) log n) since k ≤ n, and the DFS is O(n+m). Trap: do not run a per-site Dijkstra; the whole point is the super-source insight, and you must justify k ≤ n to collapse the bound.

新增一个虚拟超级源点 s*,用 0 权边把它连到每个站点。在这个扩展图上从 s* 跑一次 Dijkstra:由于每个站点到 s* 的距离都是 0,从 s* 到任意节点 v 的最短路必经过 v 的最近站点,因此 dist(s*, v) 恰为到最近站点的距离。要指出具体是哪个站点最近,再对所得最短路径树跑一次 DFS,沿根到当前节点的路径记录最近遇到的站点——每个节点的最低站点祖先即其最近站点。扩展为 O(k),单次 Dijkstra 为 O((n+1+m+k) log n) = O((n+m) log n)(因 k ≤ n),DFS 为 O(n+m)。陷阱:不要按站点逐个跑 Dijkstra;关键在于超级源点这一洞见,且需论证 k ≤ n 才能把界收紧。

Key terms核心术语

COMP90038 glossaryCOMP90038 术语表

Asymptotic notation (Big-O / Θ / Ω)渐进记号(大 O / Θ / Ω)
Notation describing the growth rate of an algorithm's cost as input size approaches infinity.
描述输入规模趋于无穷时算法代价增长速率的记号。
Recurrence relation递推关系式
An equation expressing an algorithm's cost in terms of its cost on smaller inputs, used to analyse recursive algorithms.
用更小输入上的代价来表达算法代价的方程,用于分析递归算法。
Abstract data type (ADT)抽象数据类型(ADT)
A data type defined by its operations and behaviour rather than its implementation (e.g. queue, priority queue, graph).
由其操作与行为而非具体实现来定义的数据类型(如队列、优先队列、图)。
Divide-and-conquer分治
A paradigm that splits a problem into subproblems, solves them recursively, and combines the results.
将问题分解为子问题、递归求解再合并结果的设计范式。
Dynamic programming动态规划
Solving problems with overlapping subproblems by storing and reusing intermediate results.
对含重叠子问题的问题,通过存储并复用中间结果来求解的方法。
Greedy algorithm贪心算法
A strategy that makes the locally optimal choice at each step in the hope of reaching a global optimum.
每步选择局部最优、期望达到全局最优的策略。
Priority queue / heap优先队列 / 堆
An ADT serving the highest-priority element first, commonly implemented as a binary heap.
优先弹出最高优先级元素的抽象数据类型,常用二叉堆实现。
Hash table哈希表
A structure mapping keys to slots via a hash function for near-constant-time lookup, trading space for speed.
通过哈希函数将键映射到槽位、以近常数时间查找的结构,以空间换速度。
Spanning tree (MST)生成树(最小生成树 MST)
A subgraph connecting all vertices of a graph with no cycles; the minimum-weight version is the MST.
连接图中所有顶点且无环的子图;权值最小者为最小生成树。
P vs NPP 与 NP
The distinction between problems solvable in polynomial time (P) and those whose solutions are merely verifiable in polynomial time (NP).
可在多项式时间内求解的问题(P)与解仅可在多项式时间内验证的问题(NP)之间的区分。
Master Theorem主定理
A closed-form rule for T(n)=a·T(n/b)+Θ(n^d): compare a with b^d to read off Θ(n^d), Θ(n^d log n) or Θ(n^{log_b a}). COMP90038 expects you to identify the parameters and name the case.
针对 T(n)=a·T(n/b)+Θ(n^d) 的闭式规则:比较 a 与 b^d,直接得出 Θ(n^d)、Θ(n^d log n) 或 Θ(n^{log_b a})。COMP90038 要求你识别参数并指明所属情形。
Balance factor平衡因子
For an AVL-tree node, the height of its left subtree minus that of its right subtree; the AVL invariant keeps it in {−1, 0, +1}, triggering a rotation when it reaches ±2.
AVL 树中某节点左子树高度减右子树高度之差;AVL 不变式将其保持在 {−1, 0, +1},当达到 ±2 时触发旋转。
Horspool's algorithmHorspool 算法
An input-enhancement string-matching method that precomputes a shift table from the pattern and matches right-to-left; the shift is governed by the text character aligned with the pattern's last position. It is the only string-search algorithm examined (Boyer-Moore, KMP and Rabin-Karp are not).
一种输入增强的字符串匹配方法,先由模式预计算移位表,再从右向左匹配;移位量由与模式末位对齐的文本字符决定。它是唯一被考查的字符串搜索算法(Boyer-Moore、KMP、Rabin-Karp 不在考查范围)。
Universal hashing全域哈希
Choosing a hash function at random from a 2-universal family so that no fixed input can be made to collide adversarially, giving O(1) expected query time with O(n) space.
从 2-全域哈希族中随机选取哈希函数,使得没有固定输入能被对手构造成必然碰撞,从而以 O(n) 空间获得 O(1) 期望查询时间。
FAQ

COMP90038 — common questionsCOMP90038 常见问题

How is COMP90038 assessed?COMP90038 怎么考核?
Assessment is 40% coursework plus a 60% final exam. The coursework is two assignments (15% each, due around Weeks 6 and 11) and 10 weekly online quizzes (1% each, 10% total). The 3-hour final exam in the exam period is worth 60% and is a hurdle — you must score at least 30/60 on the exam and at least 50/100 overall to pass.
考核为 40% 平时分加 60% 期末考。平时分包括两次作业(各 15%,约第 6、11 周提交)和 10 次每周在线小测(每次 1%,合计 10%)。学期末的 3 小时期末考占 60% 且为门槛项——期末考须达 30/60,且总评须达 50/100 才能通过。
Is there a final exam in COMP90038?COMP90038 有期末考吗?
Yes. There is a 3-hour final exam worth 60%, held in the end-of-semester examination period. It is a hurdle requirement: a minimum of 30 out of 60 on the exam is needed to pass the subject.
有。期末为一场 3 小时考试,占 60%,在学期末考试周举行。它是门槛项:期末考至少须达 30/60 才能通过本科目。
Do I need programming or maths background for COMP90038?学 COMP90038 需要编程或数学基础吗?
Yes. While there's no formal prerequisite subject, COMP90038 assumes solid programming (conditionals, loops, functions), familiarity with elementary data structures (arrays, records, linked lists), and Year-12-level mathematics including basic calculus and discrete maths. This is typically met by an undergraduate degree in a related discipline.
需要。虽无正式先修科目,但本课默认你已具备扎实编程能力(条件、循环、函数)、熟悉基本数据结构(数组、记录、链表),以及含基础微积分与离散数学的 12 年级数学水平,通常本科为相关专业即满足。
What's the difference between COMP90038 and an undergraduate algorithms subject?COMP90038 和本科算法课有什么区别?
COMP90038 is the graduate-level (Master's) entry point to algorithms at UniMelb, covering the same core ground as undergraduate algorithms — asymptotic analysis, data structures, and the four design paradigms — but pitched for students entering computing at postgraduate level, often from a cognate discipline.
COMP90038 是墨大研究生(硕士)层面的算法入门课,覆盖与本科算法课相同的核心内容——渐进分析、数据结构与四大设计范式——但面向以研究生身份进入计算领域的学生,通常来自相关本科专业。
Is AskSia allowed under the University of Melbourne academic integrity policy?墨尔本大学的学术诚信政策允许用 AskSia 吗?
AskSia is a study aid — Sia helps you understand asymptotic analysis, walk through algorithm traces, and check your reasoning step-by-step, which fits the University of Melbourne's policy on using AI to support learning. Submitting Sia-generated work as your own, however, is academic misconduct. Use it like a tutor: to learn, not to substitute for your own work.
AskSia 是学习辅助工具——Sia 帮你理解渐进分析、走查算法执行过程、逐步核对推理,这符合墨尔本大学关于用 AI 支持学习的政策。但把 Sia 生成的内容当作自己的作业提交属于学术不端。把它当 tutor 用:用来学,而不是替你完成作业。

AskSia is an independent study aid and is not affiliated with, endorsed by, or sponsored by The University of Melbourne. Course details may change — always confirm against the official handbook. Read about how this guide is built. AskSia 是独立的学习辅助工具,与墨尔本大学没有任何隶属、背书或赞助关系。课程信息可能变动,请始终以官方 handbook 为准。了解本指南的编写方法