Unit C5: Graph Theory单元 C5:图论
A graph is a set of vertices joined by edges: towns joined by roads, web pages joined by links, people joined by friendships. C5 is the HL-only graph theory unit of IB Mathematics: Applications and Interpretation. It builds the vocabulary (degree, simple, complete, weighted and directed graphs, subgraphs, trees), counts walks with powers of the adjacency matrix, turns a graph into a transition matrix for a random walk, decides when a graph has an Eulerian or Hamiltonian route, and then runs the four classic algorithms by hand: Kruskal's and Prim's algorithms for a minimum spanning tree, the Chinese postman problem, and nearest-neighbour and deleted-vertex bounds for the travelling salesman problem.图(graph)是由边连接起来的一组顶点:道路连接的城镇、链接连接的网页、友谊连接的人。C5 是 IB 数学:应用与解释(Applications and Interpretation)课程中仅限 HL 的图论单元。它先建立术语(度、简单图、完全图、带权图、有向图、子图、树),再用邻接矩阵的幂计数通路,把图转化为随机游走的转移矩阵,判断图何时有欧拉路线或哈密顿路线,最后手算四个经典算法:求最小生成树的 Kruskal 算法与 Prim 算法、中国邮递员问题,以及旅行商问题的最近邻上界与删点下界。
This unit is HL only; SL students can skip it. Graph theory (AHL 3.14 to 3.16) is additional higher level content in IB Mathematics: Applications and Interpretation, so it is not part of the SL course. Switch the course button at the top of the page to HL to read the full unit.
本单元仅限 HL;SL 学生可以跳过。图论(graph theory,AHL 3.14 至 3.16)属于 IB 数学:应用与解释的高级附加内容(additional higher level),不在 SL 课程中。如需阅读完整单元,请把页面顶部的课程按钮切换到 HL。
Graph Language: Vertices, Edges, Degree, Kinds of Graph, Subgraphs and Trees图的语言:顶点、边、度、图的种类、子图与树 HL AHL 3.14
- Define vertex, edge, adjacent, loop, multiple edge and the degree of a vertex.
- Distinguish simple, complete, weighted and directed graphs, and state the number of edges of the complete graph $K_n$.
- State the handshake lemma and use it to explain why a graph with given degrees cannot exist.
- Identify subgraphs, decide whether a graph is connected, and recognise a tree.
- Calculate in-degrees and out-degrees in a directed graph.
- 定义(
define)顶点、边、相邻、环、重边以及顶点的度。 - 区分简单图、完全图、带权图与有向图,并写出(
state)完全图 $K_n$ 的边数。 - 写出握手引理,并用它解释(
explain)为什么具有给定度数的图不可能存在。 - 识别子图,判断图是否连通,认出树。
- 计算(
calculate)有向图中各顶点的入度与出度。
Vertices, edges and degree顶点、边与度
A graph is a set of vertices (also called nodes) together with a set of edges; each edge joins two vertices. Two vertices joined by an edge are adjacent. An edge that starts and ends at the same vertex is a loop, and two or more edges joining the same pair of vertices are multiple edges. Only the connections matter: a graph can be redrawn with the vertices moved and the edges bent, and it is still the same graph.
图(graph)由一组顶点(vertices,也叫结点)和一组边(edges)组成;每条边连接两个顶点。由一条边连接的两个顶点称为相邻(adjacent)。起点和终点是同一顶点的边叫环(loop),连接同一对顶点的两条或更多条边叫重边(multiple edges)。图只关心连接关系:移动顶点、弯曲边重新画出来,仍然是同一个图。
The degree of a vertex $v$, written $\deg(v)$, is the number of edge ends at $v$. An ordinary edge adds $1$ to the degree of each of its two end vertices; a loop adds $2$ to the degree of its vertex, because both of its ends are there. A vertex is odd or even according to its degree.
顶点 $v$ 的度(degree),记作 $\deg(v)$,是落在 $v$ 上的边端点个数。普通的边使两个端点的度各加 $1$;环使所在顶点的度加 $2$,因为它的两个端点都在这个顶点上。按度的奇偶,顶点分为奇顶点(odd vertex)与偶顶点(even vertex)。
Kinds of graph图的种类
- A simple graph has no loops and no multiple edges. In a simple graph with $n$ vertices each vertex has degree at most $n - 1$, because it can be joined to each of the other $n - 1$ vertices at most once.
- A complete graph $K_n$ is a simple graph on $n$ vertices in which every pair of distinct vertices is joined by an edge. Every vertex has degree $n - 1$, and $K_n$ has $\tfrac{n(n-1)}{2}$ edges (one for each pair of vertices).
- A weighted graph has a number, its weight, on each edge: a distance, a time or a cost. The weight of a route is the sum of the weights of its edges.
- A directed graph (digraph) has a direction on each edge, drawn as an arrow; a directed edge is also called an arc. The in-degree of a vertex is the number of arcs arriving at it and the out-degree is the number leaving it.
- 简单图(
simple graph)没有环也没有重边。在 $n$ 个顶点的简单图中,每个顶点的度至多为 $n - 1$,因为它与其余 $n - 1$ 个顶点各至多连一条边。 - 完全图(
complete graph)$K_n$ 是 $n$ 个顶点、每一对不同顶点之间都有一条边的简单图。每个顶点的度都是 $n - 1$,$K_n$ 共有 $\tfrac{n(n-1)}{2}$ 条边(每对顶点一条)。 - 带权图(
weighted graph)的每条边上都标有一个数,称为权(weight),可以是距离、时间或费用。一条路线的权是其各边权之和。 - 有向图(
directed graph,digraph)的每条边都有方向,用箭头表示;有向边也叫弧(arc)。顶点的入度(in-degree)是指向它的弧数,出度(out-degree)是从它出发的弧数。
The handshake lemma握手引理
Every edge has exactly two ends, and each end adds $1$ to the degree of the vertex it sits on. Counting edge ends in two ways gives the handshake lemma:
每条边恰有两个端点,每个端点使其所在顶点的度加 $1$。用两种方法数边的端点,就得到握手引理(handshake lemma):
So the sum of the degrees is always even, and therefore the number of odd vertices is always even (the even degrees add to an even number, so the odd degrees must also add to an even number, which needs an even count of them). In a directed graph each arc adds $1$ to one out-degree and $1$ to one in-degree, so the sum of the in-degrees and the sum of the out-degrees both equal the number of arcs.
因此度数之和总是偶数,从而奇顶点的个数总是偶数(偶数度之和是偶数,所以奇数度之和也必须是偶数,这要求奇数度的个数为偶数)。在有向图中,每条弧使某个出度加 $1$、某个入度加 $1$,所以入度之和与出度之和都等于弧的条数。
Common misconception. "The degrees add up to an even number, so the graph exists" is not a valid argument. An even sum is necessary, not sufficient: degrees $3, 3, 1, 1$ add to $8$, yet no simple graph has them (each degree-3 vertex must be joined to all three other vertices, so each degree-1 vertex would get degree 2).
常见误解。"度数之和是偶数,所以这个图存在"不是有效的论证。和为偶数是必要条件,而不是充分条件:度数 $3, 3, 1, 1$ 之和为 $8$,但没有简单图具有这组度数(每个度为 3 的顶点都必须与其余三个顶点相连,于是每个度为 1 的顶点的度都会变成 2)。
Worked Example C5.1a: degrees and the handshake lemma例题 C5.1a:度与握手引理
A simple graph has vertices $P, Q, R, S, T$ and edges $PQ$, $PR$, $PS$, $QR$, $RS$, $ST$. (a) Write down the degree of each vertex. (b) Verify the handshake lemma. (c) Explain why no graph can have six vertices of degrees $4, 3, 3, 2, 2, 1$.一个简单图的顶点为 $P, Q, R, S, T$,边为 $PQ$、$PR$、$PS$、$QR$、$RS$、$ST$。(a) 写出每个顶点的度。(b) 验证握手引理。(c) 解释为什么没有任何图能有六个顶点、度数分别为 $4, 3, 3, 2, 2, 1$。
(a) Count edge ends. $P$ lies on $PQ, PR, PS$, so $\deg(P) = 3$. $Q$ lies on $PQ, QR$: $\deg(Q) = 2$. $R$ lies on $PR, QR, RS$: $\deg(R) = 3$. $S$ lies on $PS, RS, ST$: $\deg(S) = 3$. $T$ lies on $ST$ only: $\deg(T) = 1$.
(a) 数边的端点。$P$ 在 $PQ, PR, PS$ 上,所以 $\deg(P) = 3$。$Q$ 在 $PQ, QR$ 上:$\deg(Q) = 2$。$R$ 在 $PR, QR, RS$ 上:$\deg(R) = 3$。$S$ 在 $PS, RS, ST$ 上:$\deg(S) = 3$。$T$ 只在 $ST$ 上:$\deg(T) = 1$。
(b) Verify. Sum of degrees $= 3 + 2 + 3 + 3 + 1 = 12$, and there are $6$ edges, so $2 \times 6 = 12$. The two counts agree. There are four odd vertices ($P, R, S, T$), an even number, as expected.
(b) 验证。度数之和 $= 3 + 2 + 3 + 3 + 1 = 12$,共有 $6$ 条边,$2 \times 6 = 12$。两者一致。奇顶点有四个($P, R, S, T$),是偶数个,与预期相符。
(c) Explain. $4 + 3 + 3 + 2 + 2 + 1 = 15$, which is odd. By the handshake lemma the sum of the degrees equals twice the number of edges and so must be even. Hence no graph (simple or not) has these degrees. Another way to see it: the list has three odd degrees, and the number of odd vertices must be even.
(c) 解释。$4 + 3 + 3 + 2 + 2 + 1 = 15$,是奇数。由握手引理,度数之和等于边数的两倍,必须是偶数。因此没有任何图(无论是否简单)具有这组度数。另一种看法:这组度数中有三个奇数,而奇顶点的个数必须是偶数。
Why this works. Each edge is counted exactly twice when you add the degrees, once from each end.
为什么可行。把度数相加时,每条边恰好被数两次,两个端点各一次。
Worked Example C5.1b: complete graphs and directed graphs例题 C5.1b:完全图与有向图
(a) Find the number of edges of $K_6$ and the degree of each of its vertices. (b) Explain why there is no simple graph with $6$ vertices and $16$ edges. (c) A directed graph has arcs $P \to Q$, $Q \to R$, $R \to P$, $P \to R$ and a loop $R \to R$. Find the in-degree and out-degree of each vertex and check the totals.(a) 求 $K_6$ 的边数及每个顶点的度。(b) 解释为什么不存在 $6$ 个顶点、$16$ 条边的简单图。(c) 某有向图的弧为 $P \to Q$、$Q \to R$、$R \to P$、$P \to R$,以及环 $R \to R$。求每个顶点的入度与出度,并检验总数。
(a) $K_6$ has one edge for each pair of vertices: $\tfrac{6 \times 5}{2} = 15$ edges. Each vertex is joined to the other $5$, so every degree is $5$. Check: $6 \times 5 = 30 = 2 \times 15$.
(a) $K_6$ 每对顶点有一条边:共 $\tfrac{6 \times 5}{2} = 15$ 条边。每个顶点与其余 $5$ 个顶点相连,所以每个度都是 $5$。检验:$6 \times 5 = 30 = 2 \times 15$。
(b) A simple graph on $6$ vertices has at most one edge per pair of vertices, so at most $15$ edges, the number in $K_6$. Sixteen edges would need a repeated pair (a multiple edge) or a loop, so the graph would not be simple.
(b) $6$ 个顶点的简单图每对顶点至多一条边,所以至多 $15$ 条边,正是 $K_6$ 的边数。十六条边就需要某对顶点重复连接(重边)或出现环,那么这个图就不是简单图。
(c) Out-degrees (arcs leaving): $P$ has $P \to Q, P \to R$, so $2$; $Q$ has $Q \to R$, so $1$; $R$ has $R \to P, R \to R$, so $2$. In-degrees (arcs arriving): $P$ receives $R \to P$, so $1$; $Q$ receives $P \to Q$, so $1$; $R$ receives $Q \to R, P \to R, R \to R$, so $3$. Totals: out $2 + 1 + 2 = 5$ and in $1 + 1 + 3 = 5$, both equal to the $5$ arcs. The loop counts once as leaving $R$ and once as arriving at $R$.
(c) 出度(离开的弧):$P$ 有 $P \to Q, P \to R$,为 $2$;$Q$ 有 $Q \to R$,为 $1$;$R$ 有 $R \to P, R \to R$,为 $2$。入度(到达的弧):$P$ 收到 $R \to P$,为 $1$;$Q$ 收到 $P \to Q$,为 $1$;$R$ 收到 $Q \to R, P \to R, R \to R$,为 $3$。总数:出度 $2 + 1 + 2 = 5$,入度 $1 + 1 + 3 = 5$,都等于 $5$ 条弧。环既算作离开 $R$ 一次,也算作到达 $R$ 一次。
Why this works. The edge count of $K_n$ is the number of ways to choose $2$ vertices from $n$; on a GDC this is $\binom{n}{2}$ (nCr).
为什么可行。$K_n$ 的边数就是从 $n$ 个顶点中选 $2$ 个的方法数;在 GDC 上就是 $\binom{n}{2}$(nCr)。
Subgraphs, connected graphs and trees子图、连通图与树
A subgraph of a graph $G$ is a graph whose vertices are all vertices of $G$ and whose edges are all edges of $G$ (each joining two vertices of the subgraph). Deleting some edges, or some vertices together with every edge at them, leaves a subgraph. A graph is connected if there is a route along edges between every pair of vertices; a graph in two or more separate pieces is disconnected. A cycle is a closed route that returns to its start without repeating any other vertex (C5.4 makes this exact).
图 $G$ 的子图(subgraph)是这样的图:它的顶点都是 $G$ 的顶点,边都是 $G$ 的边(每条边连接子图中的两个顶点)。删去若干条边,或删去若干顶点以及与它们相连的所有边,剩下的就是子图。若任意两个顶点之间都有沿边走的路线,则图是连通的(connected);分成两块或更多块的图是不连通的。圈(cycle)是回到起点、且不重复其他任何顶点的闭合路线(C5.4 给出精确定义)。
A tree is a connected graph with no cycles. A tree with $n$ vertices has exactly $n - 1$ edges: removing any one edge disconnects it, and adding any edge between two of its vertices creates a cycle. A spanning tree of a connected graph $G$ is a subgraph that is a tree and contains every vertex of $G$; in a weighted graph the spanning tree of least total weight is the minimum spanning tree of C5.5.
树(tree)是没有圈的连通图。有 $n$ 个顶点的树恰有 $n - 1$ 条边:删去任何一条边都会使它不连通,在它的两个顶点之间再加任何一条边都会产生圈。连通图 $G$ 的生成树(spanning tree)是包含 $G$ 的全部顶点且本身是树的子图;在带权图中,总权最小的生成树就是 C5.5 的最小生成树。
Common misconception. "It has $n - 1$ edges, so it is a tree" needs the graph to be connected as well: two separate pieces (a triangle and a single vertex) have $4$ vertices and $3$ edges but are not a tree. A connected graph with $n$ vertices and $n - 1$ edges is a tree.
常见误解。"它有 $n - 1$ 条边,所以是树"还需要图是连通的:一个三角形加一个孤立顶点,有 $4$ 个顶点、$3$ 条边,却不是树。有 $n$ 个顶点、$n - 1$ 条边的连通图才是树。
When a question asks you to "explain why" a graph cannot exist, name the result you use ("by the handshake lemma, the sum of the degrees must be even") and show the sum; a bare "impossible" is an incomplete answer. Read the wording carefully: "simple" rules out loops and multiple edges, and a loop adds 2 to a degree. For a directed graph, give in-degree and out-degree separately when asked for "degree".
题目要求"解释为什么"(explain why)某个图不可能存在时,要写出所用的结论("由握手引理,度数之和必须是偶数")并写出求和过程;只写"不可能"是不完整的答案。仔细读题:"简单"(simple)排除了环和重边,环使度加 2。对有向图,被问到"度"时要分别写出入度和出度。
How many edges does $K_8$ have, and what is the degree of each vertex?$K_8$ 有多少条边?每个顶点的度是多少?
$\tfrac{8 \times 7}{2} = 28$ edges; each vertex has degree $7$. Check: $8 \times 7 = 56 = 2 \times 28$.
$\tfrac{8 \times 7}{2} = 28$ 条边;每个顶点的度为 $7$。检验:$8 \times 7 = 56 = 2 \times 28$。
A tree has $12$ vertices. How many edges does it have? What happens if one more edge is added between two of its vertices?一棵树有 $12$ 个顶点,它有多少条边?在它的两个顶点之间再加一条边会怎样?
$12 - 1 = 11$ edges. The two vertices were already joined by a route in the tree, so the new edge closes that route into a cycle and the graph is no longer a tree.
$12 - 1 = 11$ 条边。这两个顶点在树中本来就有路线相连,新边把这条路线封闭成一个圈,所以图不再是树。
Explain why there is no graph with $9$ vertices each of degree $3$.解释为什么不存在 $9$ 个顶点、每个顶点的度都是 $3$ 的图。
The degree sum would be $9 \times 3 = 27$, which is odd. By the handshake lemma the degree sum equals twice the number of edges, so it must be even. Hence no such graph exists.
度数之和将是 $9 \times 3 = 27$,是奇数。由握手引理,度数之和等于边数的两倍,必须是偶数。因此这样的图不存在。
Adjacency Matrices and Counting Walks邻接矩阵与通路计数 HL AHL 3.15
- Write down the adjacency matrix of an undirected or directed graph, including loops and multiple edges.
- Explain why the adjacency matrix of an undirected graph is symmetric.
- Use the entries of $A^k$ to find the number of walks of length $k$ between two vertices.
- Find the number of walks of length at most $k$ by adding powers of $A$.
- Use a GDC to calculate matrix powers and interpret the entries in context.
- 写出(
write down)无向图或有向图的邻接矩阵,包括环与重边。 - 解释(
explain)为什么无向图的邻接矩阵是对称的。 - 用 $A^k$ 的元素求两个顶点之间长度为 $k$ 的通路数。
- 把 $A$ 的各次幂相加,求长度不超过 $k$ 的通路数。
- 用 GDC 计算(
calculate)矩阵的幂,并结合情境解读其元素。
The adjacency matrix邻接矩阵
Label the vertices $1, 2, \dots, n$ in a fixed order. The adjacency matrix $A$ is the $n \times n$ matrix whose entry $a_{ij}$ is the number of edges from vertex $i$ to vertex $j$. For an undirected graph each edge can be travelled either way, so $a_{ij} = a_{ji}$ and $A$ is symmetric. For a directed graph $a_{ij}$ counts only arcs from $i$ to $j$, so $A$ is usually not symmetric; its row sums are the out-degrees and its column sums are the in-degrees. Multiple edges give entries greater than $1$. A loop at vertex $i$ is entered as $1$ in $a_{ii}$ in this guide (it is one way to step from $i$ back to $i$, which is what walk counting needs), even though it adds $2$ to the degree; check which convention a question states.
按固定顺序把顶点编号为 $1, 2, \dots, n$。邻接矩阵(adjacency matrix)$A$ 是 $n \times n$ 矩阵,其元素 $a_{ij}$ 等于从顶点 $i$ 到顶点 $j$ 的边数。无向图的每条边两个方向都能走,所以 $a_{ij} = a_{ji}$,$A$ 是对称的(symmetric)。有向图的 $a_{ij}$ 只数从 $i$ 指向 $j$ 的弧,所以 $A$ 通常不对称;它的行和是出度,列和是入度。重边使元素大于 $1$。本指南中顶点 $i$ 处的环在 $a_{ii}$ 中记为 $1$(它是从 $i$ 回到 $i$ 的一种走法,这正是通路计数所需要的),尽管它使度加 $2$;做题时要看题目说明采用哪种约定。
Walks and powers of the adjacency matrix通路与邻接矩阵的幂
A walk is a sequence of vertices in which each consecutive pair is joined by an edge; vertices and edges may repeat. A walk of length $k$ uses $k$ edges. The key result is:
通路(walk)是一串顶点,其中每相邻两个顶点之间都有边相连;顶点和边都可以重复。长度为 $k$ 的通路(walk of length k)经过 $k$ 条边。核心结论是:
Why it works. A walk of length $2$ from $i$ to $j$ goes $i \to m \to j$ through some middle vertex $m$. There are $a_{im}$ ways to make the first step and $a_{mj}$ ways to make the second, so $a_{im} a_{mj}$ walks pass through $m$. Adding over every $m$ gives $\sum_m a_{im} a_{mj}$, which is exactly the $(i, j)$ entry of $A \times A$. The same argument, one step at a time, gives $A^3, A^4, \dots$. To count walks of length at most $k$, add the matrices: $A + A^2 + \dots + A^k$. A GDC does the matrix powers and the sum; your job is to set up $A$ in the right vertex order and to read the right entry.
为什么成立。从 $i$ 到 $j$ 长度为 $2$ 的通路形如 $i \to m \to j$,经过某个中间顶点 $m$。第一步有 $a_{im}$ 种走法,第二步有 $a_{mj}$ 种,所以经过 $m$ 的通路有 $a_{im} a_{mj}$ 条。对所有 $m$ 求和得 $\sum_m a_{im} a_{mj}$,恰好是 $A \times A$ 的 $(i, j)$ 元素。同样的论证一步一步推下去,就得到 $A^3, A^4, \dots$。要数长度不超过 $k$ 的通路,把矩阵相加:$A + A^2 + \dots + A^k$。矩阵的幂和求和由 GDC 完成;你的任务是按正确的顶点顺序建立 $A$,并读出正确的元素。
Common misconception. $(A^k)_{ij}$ counts walks, not paths: a walk may revisit vertices and reuse edges. In graph G (Figure C5.1), $(A^2)_{CC} = 3$ counts $C \to A \to C$, $C \to B \to C$ and $C \to D \to C$, each of which goes out and straight back along the same edge.
常见误解。$(A^k)_{ij}$ 数的是通路,不是路径:通路可以重复经过顶点、重复使用边。在图 G(图 C5.1)中,$(A^2)_{CC} = 3$ 数的是 $C \to A \to C$、$C \to B \to C$ 和 $C \to D \to C$,每一条都是沿同一条边出去再原路返回。
Worked Example C5.2a: counting walks in graph G例题 C5.2a:在图 G 中计数通路
For graph G of Figure C5.1 (edges $AB, AC, BC, CD$): (a) write down the adjacency matrix $A$ with the vertices in the order $A, B, C, D$; (b) find the number of walks of length $3$ from $A$ to $D$ and list them; (c) find the number of walks of length $3$ that start and end at $C$; (d) find the number of walks of length at most $3$ from $A$ to $D$.对图 C5.1 的图 G(边为 $AB, AC, BC, CD$):(a) 按顶点顺序 $A, B, C, D$ 写出邻接矩阵 $A$;(b) 求从 $A$ 到 $D$ 长度为 $3$ 的通路数并列出;(c) 求起点和终点都是 $C$ 的长度为 $3$ 的通路数;(d) 求从 $A$ 到 $D$ 长度不超过 $3$ 的通路数。
(a) Row $A$: $A$ is joined to $B$ and $C$. Row $B$: joined to $A$ and $C$. Row $C$: joined to $A$, $B$, $D$. Row $D$: joined to $C$.
(a) $A$ 行:$A$ 与 $B$、$C$ 相连。$B$ 行:与 $A$、$C$ 相连。$C$ 行:与 $A$、$B$、$D$ 相连。$D$ 行:与 $C$ 相连。
$$ A = \begin{pmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} $$It is symmetric, and each row sum is a degree ($2, 2, 3, 1$).
它是对称的,各行之和就是各顶点的度($2, 2, 3, 1$)。
(b) With the GDC:
(b) 用 GDC 计算:
$$ A^2 = \begin{pmatrix} 2 & 1 & 1 & 1 \\ 1 & 2 & 1 & 1 \\ 1 & 1 & 3 & 0 \\ 1 & 1 & 0 & 1 \end{pmatrix}, \qquad A^3 = \begin{pmatrix} 2 & 3 & 4 & 1 \\ 3 & 2 & 4 & 1 \\ 4 & 4 & 2 & 3 \\ 1 & 1 & 3 & 0 \end{pmatrix} $$The entry in row $A$, column $D$ of $A^3$ is $1$. Check by listing: the last step into $D$ must come from $C$, so the walk is $A \to ? \to C \to D$ with $?$ adjacent to both $A$ and $C$, which leaves only $B$. The one walk is $A \to B \to C \to D$.
$A^3$ 中 $A$ 行 $D$ 列的元素为 $1$。列举检验:进入 $D$ 的最后一步只能来自 $C$,所以通路形如 $A \to ? \to C \to D$,其中 $?$ 要同时与 $A$ 和 $C$ 相邻,只能是 $B$。唯一的通路是 $A \to B \to C \to D$。
(c) $(A^3)_{CC} = 2$: the walks $C \to A \to B \to C$ and $C \to B \to A \to C$, the triangle in each direction.
(c) $(A^3)_{CC} = 2$:通路 $C \to A \to B \to C$ 和 $C \to B \to A \to C$,即沿三角形的两个方向各走一圈。
(d) Add the $(A, D)$ entries of $A$, $A^2$ and $A^3$: $0 + 1 + 1 = 2$. They are $A \to C \to D$ (length 2) and $A \to B \to C \to D$ (length 3).
(d) 把 $A$、$A^2$、$A^3$ 的 $(A, D)$ 元素相加:$0 + 1 + 1 = 2$。即 $A \to C \to D$(长度 2)和 $A \to B \to C \to D$(长度 3)。
Why this works. Each entry of $A^k$ adds up, over every possible sequence of intermediate vertices, the number of ways to take each step; a small listing is a quick check that you read the right row and column.
为什么可行。$A^k$ 的每个元素都是对所有可能的中间顶点序列,把每一步的走法数相乘后求和;简单列举一下,可以快速确认自己读对了行和列。
Worked Example C5.2b: walks in a directed graph例题 C5.2b:有向图中的通路
Use the directed graph of Worked Example C5.1b (arcs $P \to Q$, $Q \to R$, $R \to P$, $P \to R$ and the loop $R \to R$). (a) Write down its adjacency matrix $M$ in the order $P, Q, R$. (b) Find the number of walks of length $3$ from $P$ to $R$ and list them. (c) Find the number of walks of length at most $3$ from $P$ to $R$.使用例题 C5.1b 的有向图(弧 $P \to Q$、$Q \to R$、$R \to P$、$P \to R$ 以及环 $R \to R$)。(a) 按顺序 $P, Q, R$ 写出其邻接矩阵 $M$。(b) 求从 $P$ 到 $R$ 长度为 $3$ 的通路数并列出。(c) 求从 $P$ 到 $R$ 长度不超过 $3$ 的通路数。
(a) Row $i$ lists the arcs leaving $i$. Row $P$: arcs to $Q$ and $R$. Row $Q$: arc to $R$. Row $R$: arcs to $P$ and to $R$ (the loop).
(a) 第 $i$ 行列出从 $i$ 出发的弧。$P$ 行:指向 $Q$ 和 $R$。$Q$ 行:指向 $R$。$R$ 行:指向 $P$ 和 $R$(环)。
$$ M = \begin{pmatrix} 0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 1 \end{pmatrix}, \quad M^2 = \begin{pmatrix} 1 & 0 & 2 \\ 1 & 0 & 1 \\ 1 & 1 & 2 \end{pmatrix}, \quad M^3 = \begin{pmatrix} 2 & 1 & 3 \\ 1 & 1 & 2 \\ 2 & 1 & 4 \end{pmatrix} $$$M$ is not symmetric: there is an arc $P \to Q$ but none $Q \to P$. Row sums $2, 1, 2$ are the out-degrees and column sums $1, 1, 3$ are the in-degrees found in C5.1b.
$M$ 不对称:有弧 $P \to Q$,却没有 $Q \to P$。行和 $2, 1, 2$ 是出度,列和 $1, 1, 3$ 是入度,与 C5.1b 的结果一致。
(b) $(M^3)_{PR} = 3$. Listing them: $P \to Q \to R \to R$, $P \to R \to R \to R$ and $P \to R \to P \to R$. No other sequence works, because from $Q$ the only arc goes to $R$, and $R \to Q$ is not an arc.
(b) $(M^3)_{PR} = 3$。列出:$P \to Q \to R \to R$、$P \to R \to R \to R$ 和 $P \to R \to P \to R$。没有其他序列,因为从 $Q$ 出发唯一的弧指向 $R$,而 $R \to Q$ 不是弧。
(c) $(M)_{PR} + (M^2)_{PR} + (M^3)_{PR} = 1 + 2 + 3 = 6$.
(c) $(M)_{PR} + (M^2)_{PR} + (M^3)_{PR} = 1 + 2 + 3 = 6$。
Why this works. In a directed graph a step is allowed only along an arrow, and the matrix records exactly the allowed steps, so the powers still count walks; the order $P, Q, R$ must be the same for rows and columns.
为什么可行。在有向图中每一步只能顺着箭头走,矩阵恰好记录了允许的步,所以它的幂仍然在数通路;行与列都必须使用相同的顺序 $P, Q, R$。
State the vertex order next to the matrix, and use the same order for rows and columns. When asked for "the number of walks of length $k$", write the matrix power you used and the entry you read (for example "$(A^3)_{AD} = 1$"), not just the number; the GDC does the arithmetic but the reader needs to see which entry it is. For "at most $k$", say which powers you added. For a directed graph, row $i$ is "from $i$".
在矩阵旁写明顶点顺序,行与列使用同一顺序。被问到"长度为 $k$ 的通路数"时,写出所用的矩阵幂和读取的元素(例如"$(A^3)_{AD} = 1$"),不要只写一个数字;GDC 负责计算,但读者需要看到你读的是哪个元素。对"不超过 $k$"(at most k),写明加了哪些幂。对有向图,第 $i$ 行表示"从 $i$ 出发"。
Using $A^2$ for graph G above, how many walks of length $2$ go from $A$ to $B$? List them.利用上面图 G 的 $A^2$,从 $A$ 到 $B$ 长度为 $2$ 的通路有几条?列出它们。
$(A^2)_{AB} = 1$: the walk $A \to C \to B$. ($A$ and $B$ have only $C$ as a common neighbour.)
$(A^2)_{AB} = 1$:通路 $A \to C \to B$。($A$ 与 $B$ 唯一的公共邻点是 $C$。)
Explain why the adjacency matrix of an undirected graph is symmetric, but that of a directed graph need not be.解释为什么无向图的邻接矩阵是对称的,而有向图的邻接矩阵不一定对称。
An undirected edge between $i$ and $j$ can be travelled from $i$ to $j$ and from $j$ to $i$, so it is counted in both $a_{ij}$ and $a_{ji}$, giving $a_{ij} = a_{ji}$. An arc $i \to j$ is counted only in $a_{ij}$, so if there is no arc $j \to i$ the two entries differ.
$i$ 与 $j$ 之间的无向边既能从 $i$ 走到 $j$,也能从 $j$ 走到 $i$,所以同时计入 $a_{ij}$ 和 $a_{ji}$,得 $a_{ij} = a_{ji}$。弧 $i \to j$ 只计入 $a_{ij}$,若没有弧 $j \to i$,两个元素就不相等。
For the triangle $K_3$, find $A^2$ and $A^3$ and state the number of walks of length $3$ between two different vertices. List them for vertices $X$ and $Y$ (third vertex $Z$).对三角形 $K_3$,求 $A^2$ 和 $A^3$,并写出两个不同顶点之间长度为 $3$ 的通路数。对顶点 $X$ 与 $Y$(第三个顶点为 $Z$)列出这些通路。
$A^2$ has $2$ on the diagonal and $1$ elsewhere; $A^3$ has $2$ on the diagonal and $3$ elsewhere. So there are $3$ walks of length $3$ from $X$ to $Y$: $X \to Y \to X \to Y$, $X \to Y \to Z \to Y$ and $X \to Z \to X \to Y$.
$A^2$ 对角线为 $2$,其余为 $1$;$A^3$ 对角线为 $2$,其余为 $3$。所以从 $X$ 到 $Y$ 长度为 $3$ 的通路有 $3$ 条:$X \to Y \to X \to Y$、$X \to Y \to Z \to Y$ 和 $X \to Z \to X \to Y$。
Weighted Adjacency Tables and Transition Matrices带权邻接表与转移矩阵 HL AHL 3.15
- Construct a weighted adjacency table from a weighted graph, and draw the graph from a table.
- Find the weight of a route and compare a direct edge with a route through other vertices.
- Construct the transition matrix of a random walk on a graph, with columns that sum to $1$.
- Calculate the probability of being at a vertex after $n$ steps using $T^n s_0$.
- Find and interpret the steady state of a random walk on a connected graph.
- 由带权图构造(
construct)带权邻接表,并由表画出图。 - 求一条路线的权,并比较直接的边与经过其他顶点的路线。
- 构造图上随机游走的转移矩阵,使每一列之和为 $1$。
- 用 $T^n s_0$ 计算 $n$ 步后位于某顶点的概率。
- 求出并解读(
interpret)连通图上随机游走的稳态。
Weighted adjacency tables带权邻接表
A weighted adjacency table lists the vertices along the top and down the side; the entry in row $i$, column $j$ is the weight of the edge joining $i$ and $j$, and a dash (or a blank) means there is no edge. For an undirected graph the table is symmetric, so every edge appears twice; count only the entries above the diagonal when you add up the edges. The table is the natural input for Prim's algorithm (C5.5) and for the travelling salesman bounds (C5.6).
带权邻接表(weighted adjacency table)把顶点列在表头和左侧;第 $i$ 行第 $j$ 列的元素是连接 $i$ 与 $j$ 的边的权,短横线(或空白)表示没有边。无向图的表是对称的,每条边出现两次;统计边时只数对角线上方的元素。这种表正是 Prim 算法(C5.5)和旅行商上下界(C5.6)的自然输入。
Common misconception. The entry for an edge is the weight of that edge, not the shortest distance between the two vertices. A direct road can be longer than a route through another town, as the next example shows.
常见误解。表中某条边的元素是那条边的权,而不是两个顶点之间的最短距离。直达的道路可能比经过别的城镇的路线还长,下一个例题就是这样。
Worked Example C5.3a: reading a weighted adjacency table例题 C5.3a:读带权邻接表
The table gives road lengths in km between four villages; a dash means no direct road. (a) Write down the number of roads and their total length. (b) Find the shortest route from $W$ to $Z$.下表给出四个村庄之间道路的长度(km);短横线表示没有直达道路。(a) 写出道路的条数及总长度。(b) 求从 $W$ 到 $Z$ 的最短路线。
| W | X | Y | Z | |
|---|---|---|---|---|
| W | - | 4 | 7 | - |
| X | 4 | - | 2 | 6 |
| Y | 7 | 2 | - | 3 |
| Z | - | 6 | 3 | - |
(a) Entries above the diagonal: $WX = 4$, $WY = 7$, $XY = 2$, $XZ = 6$, $YZ = 3$. That is $5$ roads with total length $4 + 7 + 2 + 6 + 3 = 22$ km.
(a) 对角线上方的元素:$WX = 4$、$WY = 7$、$XY = 2$、$XZ = 6$、$YZ = 3$。共 $5$ 条道路,总长 $4 + 7 + 2 + 6 + 3 = 22$ km。
(b) There is no direct road $WZ$. List the routes that do not revisit a village: $W \to X \to Z = 4 + 6 = 10$; $W \to Y \to Z = 7 + 3 = 10$; $W \to X \to Y \to Z = 4 + 2 + 3 = 9$; $W \to Y \to X \to Z = 7 + 2 + 6 = 15$. The shortest is $W \to X \to Y \to Z$, $9$ km.
(b) 没有直达道路 $WZ$。列出不重复经过村庄的路线:$W \to X \to Z = 4 + 6 = 10$;$W \to Y \to Z = 7 + 3 = 10$;$W \to X \to Y \to Z = 4 + 2 + 3 = 9$;$W \to Y \to X \to Z = 7 + 2 + 6 = 15$。最短的是 $W \to X \to Y \to Z$,$9$ km。
Why this works. The route with the fewest edges is not always the lightest: here three short roads beat two longer ones. Also note $XZ = 6$ is longer than $X \to Y \to Z = 5$; tables like this matter for the travelling salesman problem in C5.6.
为什么可行。边数最少的路线不一定最轻:这里三条短路胜过两条长路。还要注意 $XZ = 6$ 比 $X \to Y \to Z = 5$ 更长;这类表格在 C5.6 的旅行商问题中很重要。
Transition matrices for a random walk on a graph图上随机游走的转移矩阵
In a random walk on a graph, a walker at a vertex moves at each step along one of the edges at that vertex, each edge being equally likely. From a vertex of degree $d$ in a simple graph, each neighbour is chosen with probability $\tfrac{1}{d}$. The transition matrix $T$ records these probabilities. In this guide (as in Unit B5) column $j$ holds the probabilities of moving from vertex $j$, so $T_{ij} = P(\text{next at } i \mid \text{now at } j)$ and every column sums to $1$. If the column vector $s_0$ gives the starting probabilities, then after $n$ steps
在图上的随机游走(random walk)中,位于某顶点的游走者每一步沿该顶点处的某一条边移动,各条边的可能性相同。在简单图中,从度为 $d$ 的顶点出发,每个邻点被选中的概率为 $\tfrac{1}{d}$。转移矩阵(transition matrix)$T$ 记录这些概率。本指南(与单元 B5 一致)用第 $j$ 列表示从顶点 $j$ 出发的概率,所以 $T_{ij} = P(\text{next at } i \mid \text{now at } j)$,并且每一列之和为 $1$。若列向量 $s_0$ 给出初始概率,则 $n$ 步之后
A steady state is a probability vector $s$ with $Ts = s$. For a random walk on a connected graph there is exactly one, and its entries are proportional to the degrees: $s_i = \tfrac{\deg(i)}{\sum \deg} = \tfrac{\deg(i)}{2 \times \text{edges}}$. It gives the long-run proportion of time the walker spends at each vertex. If the graph also contains a cycle of odd length (for example a triangle), $T^n s_0$ approaches the steady state from any start; on a graph with no odd cycle, such as a square, the walker alternates between two sides and $T^n s_0$ need not settle. Markov chains in general are the subject of Unit B5; a random walk on a graph is the special case whose matrix is built from the graph.
稳态(steady state)是满足 $Ts = s$ 的概率向量 $s$。连通图上的随机游走恰有一个稳态,其各分量与度成正比:$s_i = \tfrac{\deg(i)}{\sum \deg} = \tfrac{\deg(i)}{2 \times \text{edges}}$。它给出长期来看游走者在每个顶点停留的时间比例。若图还含有奇数长度的圈(例如三角形),则从任何初始状态出发,$T^n s_0$ 都趋于稳态;在没有奇圈的图上(例如正方形),游走者在两侧之间来回交替,$T^n s_0$ 不一定稳定下来。一般的马尔可夫链(Markov chains)是单元 B5 的内容;图上的随机游走是由图构造矩阵的特例。
Worked Example C5.3b: a random walk on graph G例题 C5.3b:图 G 上的随机游走
A walker moves randomly on graph G (Figure C5.1), starting at $A$. (a) Write down the transition matrix $T$ (order $A, B, C, D$). (b) Find the probability that the walker is at $D$ after $2$ steps. (c) Find the steady state and verify it.游走者在图 G(图 C5.1)上随机移动,从 $A$ 出发。(a) 写出转移矩阵 $T$(顺序 $A, B, C, D$)。(b) 求 $2$ 步后游走者位于 $D$ 的概率。(c) 求稳态并验证。
(a) One column per starting vertex. From $A$ (degree 2): to $B$ or $C$, each $\tfrac12$. From $B$ (degree 2): to $A$ or $C$, each $\tfrac12$. From $C$ (degree 3): to $A$, $B$ or $D$, each $\tfrac13$. From $D$ (degree 1): to $C$ with probability $1$.
(a) 每个出发顶点占一列。从 $A$(度 2):到 $B$ 或 $C$,各 $\tfrac12$。从 $B$(度 2):到 $A$ 或 $C$,各 $\tfrac12$。从 $C$(度 3):到 $A$、$B$ 或 $D$,各 $\tfrac13$。从 $D$(度 1):以概率 $1$ 到 $C$。
$$ T = \begin{pmatrix} 0 & \tfrac12 & \tfrac13 & 0 \\ \tfrac12 & 0 & \tfrac13 & 0 \\ \tfrac12 & \tfrac12 & 0 & 1 \\ 0 & 0 & \tfrac13 & 0 \end{pmatrix}, \qquad s_0 = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} $$Check: each column sums to $1$.
检验:每一列之和都为 $1$。
(b) $s_1 = T s_0 = \left(0, \tfrac12, \tfrac12, 0\right)^{T}$. Then $s_2 = T s_1$; its $D$ entry is $\tfrac13 \times \tfrac12 = \tfrac16$ (the only way into $D$ is from $C$). The full vector is $s_2 = \left(\tfrac{5}{12}, \tfrac16, \tfrac14, \tfrac16\right)^{T}$, which sums to $1$. So $P(\text{at } D \text{ after 2 steps}) = \tfrac16 \approx 0.167$. On a GDC, enter $T$ and $s_0$ and compute $T^2 s_0$ directly.
(b) $s_1 = T s_0 = \left(0, \tfrac12, \tfrac12, 0\right)^{T}$。再求 $s_2 = T s_1$;其 $D$ 分量为 $\tfrac13 \times \tfrac12 = \tfrac16$(进入 $D$ 的唯一途径是从 $C$ 来)。完整向量为 $s_2 = \left(\tfrac{5}{12}, \tfrac16, \tfrac14, \tfrac16\right)^{T}$,各分量之和为 $1$。所以 $P(\text{at } D \text{ after 2 steps}) = \tfrac16 \approx 0.167$。在 GDC 上输入 $T$ 和 $s_0$,直接计算 $T^2 s_0$ 即可。
(c) The graph is connected with degrees $2, 2, 3, 1$ (sum $8$), so the steady state is $s = \left(\tfrac28, \tfrac28, \tfrac38, \tfrac18\right)^{T} = (0.25, 0.25, 0.375, 0.125)^{T}$. Verify the first row of $Ts$: $\tfrac12 \times 0.25 + \tfrac13 \times 0.375 = 0.125 + 0.125 = 0.25$. Third row: $\tfrac12 \times 0.25 + \tfrac12 \times 0.25 + 1 \times 0.125 = 0.375$. The other rows check the same way. Because G contains the triangle $ABC$, $T^n s_0$ approaches this vector: a GDC gives $T^{30} s_0 \approx (0.25, 0.25, 0.375, 0.125)^{T}$.
(c) 图是连通的,度为 $2, 2, 3, 1$(和为 $8$),所以稳态为 $s = \left(\tfrac28, \tfrac28, \tfrac38, \tfrac18\right)^{T} = (0.25, 0.25, 0.375, 0.125)^{T}$。验证 $Ts$ 的第一行:$\tfrac12 \times 0.25 + \tfrac13 \times 0.375 = 0.125 + 0.125 = 0.25$。第三行:$\tfrac12 \times 0.25 + \tfrac12 \times 0.25 + 1 \times 0.125 = 0.375$。其余各行同样可验。由于 G 含有三角形 $ABC$,$T^n s_0$ 趋于这个向量:GDC 给出 $T^{30} s_0 \approx (0.25, 0.25, 0.375, 0.125)^{T}$。
Why this works. In the long run each edge is crossed equally often in each direction, so a vertex is visited in proportion to the number of edges at it. Interpretation: the walker spends $37.5\%$ of the time at $C$.
为什么可行。长期来看,每条边在两个方向上被经过的频率相同,所以顶点被访问的频率与它所连的边数成正比。解读:游走者有 $37.5\%$ 的时间位于 $C$。
Before using a transition matrix, check that each column adds to $1$; if the rows add to $1$ instead, the question is using the transposed convention and you must write $s_n$ as a row vector multiplied on the right. Give probabilities as exact fractions or to three significant figures, and state what the vector entries mean ("the probability that the walker is at $C$ after $3$ steps"). For a steady state, show the equation $Ts = s$ with entries adding to $1$, or a high power of $T$ from the GDC, and interpret it as a long-run proportion.
使用转移矩阵前先检查每一列之和是否为 $1$;如果是每一行之和为 $1$,说明题目用的是转置约定,你必须把 $s_n$ 写成行向量并右乘矩阵。概率写成精确分数或保留三位有效数字,并说明向量分量的含义("$3$ 步后游走者位于 $C$ 的概率")。求稳态时,写出方程 $Ts = s$ 且分量之和为 $1$,或写出 GDC 算出的 $T$ 的高次幂,并把结果解读为长期比例。
Explain why every column of the transition matrix of a random walk sums to $1$.解释为什么随机游走转移矩阵的每一列之和都为 $1$。
Column $j$ lists the probabilities of every possible next vertex given that the walker is at $j$ now. The walker must move somewhere, so these probabilities are exhaustive and add to $1$.
第 $j$ 列列出了"现在位于 $j$"时下一步到达各顶点的概率。游走者一定会移动到某处,这些情况穷尽了所有可能,所以概率之和为 $1$。
A walker moves randomly on the complete graph $K_4$. Write down the steady state and explain it.游走者在完全图 $K_4$ 上随机移动。写出稳态并加以解释。
Every vertex of $K_4$ has degree $3$, so the steady state is $\left(\tfrac14, \tfrac14, \tfrac14, \tfrac14\right)^{T}$: by symmetry the walker spends equal time at each vertex. ($K_4$ contains triangles, so the walk settles to it from any start.)
$K_4$ 的每个顶点的度都是 $3$,所以稳态为 $\left(\tfrac14, \tfrac14, \tfrac14, \tfrac14\right)^{T}$:由对称性,游走者在每个顶点停留的时间相同。($K_4$ 含有三角形,所以从任何起点出发都会趋于这个稳态。)
For the walk on graph G starting at $A$, find the probability that the walker is at $C$ after $3$ steps.对图 G 上从 $A$ 出发的随机游走,求 $3$ 步后游走者位于 $C$ 的概率。
$s_3 = T s_2$ with $s_2 = \left(\tfrac{5}{12}, \tfrac16, \tfrac14, \tfrac16\right)^{T}$. The $C$ entry is $\tfrac12 \times \tfrac{5}{12} + \tfrac12 \times \tfrac16 + 1 \times \tfrac16 = \tfrac{5}{24} + \tfrac{2}{24} + \tfrac{4}{24} = \tfrac{11}{24} \approx 0.458$. (GDC: $T^3 s_0 = \left(\tfrac16, \tfrac{7}{24}, \tfrac{11}{24}, \tfrac{1}{12}\right)^{T}$.)
$s_3 = T s_2$,其中 $s_2 = \left(\tfrac{5}{12}, \tfrac16, \tfrac14, \tfrac16\right)^{T}$。$C$ 分量为 $\tfrac12 \times \tfrac{5}{12} + \tfrac12 \times \tfrac16 + 1 \times \tfrac16 = \tfrac{5}{24} + \tfrac{2}{24} + \tfrac{4}{24} = \tfrac{11}{24} \approx 0.458$。(GDC:$T^3 s_0 = \left(\tfrac16, \tfrac{7}{24}, \tfrac{11}{24}, \tfrac{1}{12}\right)^{T}$。)
Walks, Trails, Paths and Circuits; Eulerian and Hamiltonian Graphs通路、迹、路径与回路;欧拉图与哈密顿图 HL AHL 3.16
- Define walk, trail, path, circuit and cycle, and classify a given route.
- State the degree conditions for an Eulerian circuit and for an Eulerian trail in a connected graph.
- Determine whether a graph has an Eulerian trail or circuit, and write one down.
- Define Hamiltonian path and Hamiltonian cycle, and show that one exists by writing it down.
- Explain why a particular graph has no Hamiltonian cycle.
- 定义通路、迹、路径、回路和圈,并对给定路线分类。
- 写出(
state)连通图有欧拉回路和欧拉迹的度条件。 - 判断(
determine)图是否有欧拉迹或欧拉回路,并写出一条。 - 定义哈密顿路径与哈密顿圈,并通过写出一条来说明其存在。
- 解释(
explain)为什么某个图没有哈密顿圈。
Five kinds of route五种路线
Every route below is a walk (a sequence of vertices with consecutive vertices adjacent). The names say what may repeat. A route is closed if it ends where it started.
下面每种路线都是通路(一串顶点,相邻两个顶点之间有边)。名称说明了什么可以重复。若路线的终点就是起点,则称其为闭合的(closed)。
| Route | Edges may repeat? | Vertices may repeat? | Closed? |
|---|---|---|---|
| Walk | Yes | Yes | Either |
| Trail | No | Yes | Either |
| Path | No | No | No |
| Circuit | No | Yes | Yes |
| Cycle | No | Only start = end | Yes |
| 路线 | 边可重复? | 顶点可重复? | 闭合? |
|---|---|---|---|
通路(walk) | 是 | 是 | 均可 |
迹(trail) | 否 | 是 | 均可 |
路径(path) | 否 | 否 | 否 |
回路(circuit) | 否 | 是 | 是 |
圈(cycle) | 否 | 仅起点 = 终点 | 是 |
In graph G (Figure C5.1), $C \to A \to B \to C \to D$ is a trail (no edge repeats) but not a path ($C$ repeats); $A \to B \to C \to A$ is a cycle; $A \to C \to A \to B$ is a walk that is not a trail (edge $AC$ is used twice).
在图 G(图 C5.1)中,$C \to A \to B \to C \to D$ 是迹(边不重复),但不是路径($C$ 重复);$A \to B \to C \to A$ 是圈;$A \to C \to A \to B$ 是通路但不是迹(边 $AC$ 用了两次)。
Eulerian trails and circuits欧拉迹与欧拉回路
An Eulerian trail is a trail that uses every edge of the graph exactly once. An Eulerian circuit is an Eulerian trail that starts and ends at the same vertex. Whether they exist is settled by the degrees, for a connected graph:
欧拉迹(Eulerian trail)是恰好经过图中每条边一次的迹。欧拉回路(Eulerian circuit)是起点与终点相同的欧拉迹。对连通图,它们是否存在由度决定:
- Every vertex even: if a connected graph has every vertex of even degree, it has an Eulerian circuit, and the circuit can start at any vertex. Conversely, if a graph has an Eulerian circuit, every vertex has even degree.
- Exactly two odd vertices: if a connected graph has exactly two vertices of odd degree, it has an Eulerian trail, every Eulerian trail starts at one odd vertex and ends at the other, and there is no Eulerian circuit. Conversely, if a graph has an Eulerian trail that is not closed, its start and end are the only odd vertices.
- More than two odd vertices: there is no Eulerian trail and no Eulerian circuit.
- 所有顶点都是偶顶点:若连通图的每个顶点的度都是偶数,则它有欧拉回路,且回路可以从任一顶点出发。反过来,若一个图有欧拉回路,则它的每个顶点的度都是偶数。
- 恰有两个奇顶点:若连通图恰有两个奇顶点,则它有欧拉迹,每条欧拉迹都从一个奇顶点出发、在另一个奇顶点结束,并且没有欧拉回路。反过来,若一个图有不闭合的欧拉迹,则其起点和终点是仅有的两个奇顶点。
- 奇顶点多于两个:没有欧拉迹,也没有欧拉回路。
Why the degrees decide it. Each time a trail passes through a vertex it uses two edges there, one in and one out. So at every vertex other than the start and end, the edges are used in pairs and the degree must be even. In a closed trail the start and end are the same vertex, whose first edge out pairs with its last edge in, so every degree is even. In an open trail the start and end each have one unpaired edge, so exactly those two vertices are odd. The graph must be connected: two separate triangles have every degree even but no single trail can cover both.
为什么由度决定。迹每经过一个顶点一次,就在该处用掉两条边,一进一出。所以除起点和终点以外,每个顶点处的边都是成对使用的,度必须是偶数。闭合的迹起点和终点是同一个顶点,它的第一条出边与最后一条入边配成一对,所以每个度都是偶数。不闭合的迹起点和终点各有一条不成对的边,所以恰好这两个顶点是奇顶点。图必须连通:两个分开的三角形每个度都是偶数,但没有一条迹能同时覆盖两者。
Hamiltonian paths and cycles哈密顿路径与哈密顿圈
A Hamiltonian path visits every vertex of the graph exactly once. A Hamiltonian cycle visits every vertex exactly once and returns to its start (the start vertex is the only one repeated). Unlike the Eulerian case, no simple degree condition decides whether a Hamiltonian cycle exists. To show one exists, write it down and check it. To show one does not, give a reason: for example, a vertex of degree $1$ cannot lie on any cycle (a cycle enters and leaves each of its vertices along two different edges), so a graph with a vertex of degree $1$ has no Hamiltonian cycle. Every complete graph $K_n$ with $n \ge 3$ has a Hamiltonian cycle: visit the vertices in any order and return.
哈密顿路径(Hamiltonian path)恰好经过图的每个顶点一次。哈密顿圈(Hamiltonian cycle)恰好经过每个顶点一次并回到起点(只有起点重复)。与欧拉情形不同,没有简单的度条件能判定哈密顿圈是否存在。要说明存在,就写出一个并检验。要说明不存在,就给出理由:例如度为 $1$ 的顶点不可能在任何圈上(圈进入和离开它的每个顶点要用两条不同的边),所以有度为 $1$ 的顶点的图没有哈密顿圈。每个 $n \ge 3$ 的完全图 $K_n$ 都有哈密顿圈:按任意顺序访问各顶点再返回即可。
Common misconception. Mixing up the two names. Euler covers every Edge; Hamilton visits every vertex. A graph can have one kind of route and not the other.
常见误解。把两个名称混淆。欧拉(Euler)覆盖每一条边(Edge);哈密顿(Hamilton)访问每一个顶点。一个图可以只有其中一种路线。
Worked Example C5.4a: the house graph例题 C5.4a:"房子"图
A graph has vertices $A, B, C, D, E$ and edges $AB, BC, CD, DA, AE, BE$ (a square $ABCD$ with a roof $E$). (a) Decide whether it has an Eulerian circuit or an Eulerian trail, and write one down. (b) Find a Hamiltonian cycle.某图的顶点为 $A, B, C, D, E$,边为 $AB, BC, CD, DA, AE, BE$(正方形 $ABCD$ 加屋顶 $E$)。(a) 判断它有欧拉回路还是欧拉迹,并写出一条。(b) 求一个哈密顿圈。
(a) Degrees first. $\deg(A) = 3$ ($AB, AD, AE$), $\deg(B) = 3$ ($AB, BC, BE$), $\deg(C) = 2$, $\deg(D) = 2$, $\deg(E) = 2$. Check: $3 + 3 + 2 + 2 + 2 = 12 = 2 \times 6$. The graph is connected and has exactly two odd vertices, $A$ and $B$. So there is no Eulerian circuit, but there is an Eulerian trail from $A$ to $B$.
(a) 先求度。$\deg(A) = 3$($AB, AD, AE$),$\deg(B) = 3$($AB, BC, BE$),$\deg(C) = 2$,$\deg(D) = 2$,$\deg(E) = 2$。检验:$3 + 3 + 2 + 2 + 2 = 12 = 2 \times 6$。图是连通的,恰有两个奇顶点 $A$ 和 $B$。所以没有欧拉回路,但有从 $A$ 到 $B$ 的欧拉迹。
Write one down: $A \to E \to B \to A \to D \to C \to B$. Check: it uses $AE, EB, BA, AD, DC, CB$, which is all $6$ edges, each once.
写出一条:$A \to E \to B \to A \to D \to C \to B$。检验:它经过 $AE, EB, BA, AD, DC, CB$,正好是全部 $6$ 条边,各一次。
(b) $A \to E \to B \to C \to D \to A$. Check: the edges $AE, EB, BC, CD, DA$ all exist, and each of the $5$ vertices appears exactly once before returning to $A$.
(b) $A \to E \to B \to C \to D \to A$。检验:边 $AE, EB, BC, CD, DA$ 都存在,且 $5$ 个顶点在回到 $A$ 之前各出现恰好一次。
Why this works. The degree conditions say where an Eulerian trail must start and end; you still have to produce the trail and tick off the edges.
为什么可行。度条件告诉你欧拉迹必须在哪里开始和结束;你仍然需要写出这条迹,并逐条核对边。
Worked Example C5.4b: graph G, Euler yes, Hamilton cycle no例题 C5.4b:图 G,有欧拉迹,无哈密顿圈
For graph G (Figure C5.1): (a) find an Eulerian trail; (b) find a Hamiltonian path; (c) explain why G has no Hamiltonian cycle.对图 G(图 C5.1):(a) 求一条欧拉迹;(b) 求一条哈密顿路径;(c) 解释为什么 G 没有哈密顿圈。
(a) Degrees $2, 2, 3, 1$: G is connected with exactly two odd vertices, $C$ and $D$, so an Eulerian trail runs from $C$ to $D$: $C \to A \to B \to C \to D$. It uses $CA, AB, BC, CD$, all four edges once.
(a) 度为 $2, 2, 3, 1$:G 连通且恰有两个奇顶点 $C$ 和 $D$,所以欧拉迹从 $C$ 走到 $D$:$C \to A \to B \to C \to D$。它经过 $CA, AB, BC, CD$,四条边各一次。
(b) $D \to C \to A \to B$ visits all four vertices once along existing edges $DC, CA, AB$.
(b) $D \to C \to A \to B$ 沿已有的边 $DC, CA, AB$ 把四个顶点各访问一次。
(c) $\deg(D) = 1$. A cycle through $D$ would have to arrive at $D$ along one edge and leave along a different edge, which needs at least two edges at $D$. So no cycle contains $D$, and in particular no cycle visits every vertex.
(c) $\deg(D) = 1$。经过 $D$ 的圈必须沿一条边到达 $D$、再沿另一条不同的边离开,这需要 $D$ 处至少有两条边。所以没有圈包含 $D$,自然也没有圈能访问所有顶点。
Why this works. Existence is shown by an example; non-existence needs an argument that rules out every possibility at once, here a single vertex that no cycle can pass through.
为什么可行。存在性用一个例子说明;不存在则需要一个能一次排除所有可能的论证,这里就是一个任何圈都无法经过的顶点。
For "does the graph have an Eulerian circuit?", list every degree, say the graph is connected, and then quote the condition ("all vertices even" or "exactly two odd vertices, so an Eulerian trail but not a circuit"). For Hamiltonian questions there is no degree rule to quote: either write the cycle as a vertex sequence that returns to its start, or give a specific reason why none exists. Write routes as vertex sequences such as $A \to E \to B \to A$, so each edge can be checked.
遇到"该图是否有欧拉回路?"时,列出每个顶点的度,说明图是连通的,再引用条件("所有顶点都是偶顶点"或"恰有两个奇顶点,所以有欧拉迹而没有欧拉回路")。哈密顿问题没有可引用的度规则:要么写出回到起点的顶点序列作为圈,要么给出不存在的具体理由。路线要写成顶点序列,如 $A \to E \to B \to A$,便于逐条核对边。
Does $K_5$ have an Eulerian circuit? Does $K_4$ have an Eulerian trail?$K_5$ 有欧拉回路吗?$K_4$ 有欧拉迹吗?
$K_5$: connected, every vertex has degree $4$ (even), so yes, it has an Eulerian circuit. $K_4$: every vertex has degree $3$, so there are four odd vertices; more than two odd vertices means no Eulerian trail.
$K_5$:连通,每个顶点的度为 $4$(偶数),所以有欧拉回路。$K_4$:每个顶点的度为 $3$,共有四个奇顶点;奇顶点多于两个,所以没有欧拉迹。
State the difference between a trail and a path, and between a circuit and a cycle.说明迹与路径的区别,以及回路与圈的区别。
A trail may not repeat an edge but may revisit a vertex; a path may repeat neither. A circuit is a closed trail (no repeated edge, vertices may repeat); a cycle is a closed route in which no vertex repeats except that the start is also the end.
迹不能重复边,但可以重复经过顶点;路径既不能重复边也不能重复顶点。回路是闭合的迹(边不重复,顶点可以重复);圈是除起点与终点相同外不重复任何顶点的闭合路线。
A connected graph has vertices of degrees $4, 4, 3, 3, 2$. Which route exists, and where must it start and end?某连通图各顶点的度为 $4, 4, 3, 3, 2$。存在哪种路线?它必须从哪里开始、在哪里结束?
Exactly two odd vertices (the two of degree $3$), so there is an Eulerian trail but no Eulerian circuit. The trail starts at one degree-3 vertex and ends at the other.
恰有两个奇顶点(两个度为 $3$ 的顶点),所以有欧拉迹而没有欧拉回路。这条迹从一个度为 3 的顶点出发,在另一个度为 3 的顶点结束。
Minimum Spanning Trees: Kruskal's and Prim's Algorithms最小生成树:Kruskal 算法与 Prim 算法 HL AHL 3.16
- Define a minimum spanning tree of a connected weighted graph and state how many edges it has.
- Apply Kruskal's algorithm, showing the order in which edges are considered, added or rejected.
- Apply Prim's algorithm from a given vertex on a drawn graph.
- Apply Prim's algorithm to a weighted adjacency table.
- Check a minimum spanning tree by its edge count and by running the other algorithm.
- 定义连通带权图的最小生成树,并写出它的边数。
- 应用 Kruskal 算法,写明考虑各边的顺序以及加入或拒绝的结果。
- 从给定顶点出发,在画好的图上应用 Prim 算法。
- 在带权邻接表上应用 Prim 算法。
- 用边数以及另一种算法检验最小生成树。
What a minimum spanning tree is什么是最小生成树
A minimum spanning tree (MST) of a connected weighted graph is a spanning tree (a tree containing every vertex, C5.1) whose total weight is as small as possible. It answers questions such as "which cables connect every building for the least total length?". With $n$ vertices it always has $n - 1$ edges. If all the edge weights are different, the minimum spanning tree is unique; with equal weights there may be several, all with the same total.
连通带权图的最小生成树(minimum spanning tree,MST)是总权尽可能小的生成树(包含全部顶点的树,见 C5.1)。它回答诸如"用哪些电缆把所有建筑连起来、总长度最短?"的问题。有 $n$ 个顶点时,它总有 $n - 1$ 条边。若所有边的权互不相同,最小生成树是唯一的;若有相等的权,可能有多棵,但总权相同。
Kruskal's algorithmKruskal 算法
- List the edges in order of increasing weight.
- Take the next edge in the list. Add it to the tree unless it would form a cycle with edges already chosen; in that case reject it.
- Stop when $n - 1$ edges have been added.
- 把所有边按权从小到大排列。
- 取列表中的下一条边。若它与已选的边构成圈,则拒绝它;否则把它加入树中。
- 加入 $n - 1$ 条边后停止。
The chosen edges may be in separate pieces in the middle of the algorithm; they join into one tree by the end.
算法进行到中途时,已选的边可能分成几块;到最后它们会连成一棵树。
Prim's algorithmPrim 算法
- Choose a starting vertex; it is the tree so far.
- Among all edges joining a vertex in the tree to a vertex not yet in the tree, add the one of least weight (and its new vertex).
- Repeat until every vertex is in the tree.
- 选一个起始顶点,它就是目前的树。
- 在所有连接"树内顶点"与"树外顶点"的边中,加入权最小的那条(连同它的新顶点)。
- 重复,直到所有顶点都在树中。
Prim's tree is connected at every stage, so it can never form a cycle: the new edge always reaches a vertex outside the tree. This is why Prim's algorithm works well on a table, where cycles are hard to see.
Prim 算法的树在每一步都是连通的,所以永远不会形成圈:新加的边总是通向树外的顶点。这也是 Prim 算法适合在表格上操作的原因,因为在表格中很难看出圈。
Worked Example C5.5a: Kruskal's and Prim's algorithms on Figure C5.2例题 C5.5a:在图 C5.2 上用 Kruskal 与 Prim 算法
The graph in Figure C5.2 has edges $AB = 7$, $BC = 8$, $AD = 5$, $DE = 6$, $EF = 9$, $CF = 4$, $BE = 3$, $AE = 10$, $CE = 11$. (a) Use Kruskal's algorithm to find a minimum spanning tree, showing each step. (b) Check the answer with Prim's algorithm starting at $A$.图 C5.2 中的边为 $AB = 7$、$BC = 8$、$AD = 5$、$DE = 6$、$EF = 9$、$CF = 4$、$BE = 3$、$AE = 10$、$CE = 11$。(a) 用 Kruskal 算法求最小生成树,写出每一步。(b) 用从 $A$ 出发的 Prim 算法检验答案。
(a) Sort the edges: $BE\,3$, $CF\,4$, $AD\,5$, $DE\,6$, $AB\,7$, $BC\,8$, $EF\,9$, $AE\,10$, $CE\,11$. There are $6$ vertices, so the tree needs $5$ edges.
(a) 把边排序:$BE\,3$、$CF\,4$、$AD\,5$、$DE\,6$、$AB\,7$、$BC\,8$、$EF\,9$、$AE\,10$、$CE\,11$。共 $6$ 个顶点,所以树需要 $5$ 条边。
| Step | Edge | Action | Pieces after the step |
|---|---|---|---|
| 1 | BE 3 | add | {B, E} |
| 2 | CF 4 | add | {B, E}, {C, F} |
| 3 | AD 5 | add | {B, E}, {C, F}, {A, D} |
| 4 | DE 6 | add | {A, B, D, E}, {C, F} |
| 5 | AB 7 | reject: A and B are already joined (A, D, E, B), so AB would form the cycle A, B, E, D, A | unchanged |
| 6 | BC 8 | add (joins the two pieces) | {A, B, C, D, E, F} |
| 步骤 | 边 | 操作 | 该步之后的各块 |
|---|---|---|---|
| 1 | BE 3 | 加入 | {B, E} |
| 2 | CF 4 | 加入 | {B, E}, {C, F} |
| 3 | AD 5 | 加入 | {B, E}, {C, F}, {A, D} |
| 4 | DE 6 | 加入 | {A, B, D, E}, {C, F} |
| 5 | AB 7 | 拒绝:A 与 B 已经相连(A, D, E, B),加入 AB 会形成圈 A, B, E, D, A | 不变 |
| 6 | BC 8 | 加入(把两块连起来) | {A, B, C, D, E, F} |
Five edges are chosen, so stop. The minimum spanning tree is $\{BE, CF, AD, DE, BC\}$ with weight $3 + 4 + 5 + 6 + 8 = 26$. $EF$, $AE$ and $CE$ are never needed.
已选五条边,停止。最小生成树为 $\{BE, CF, AD, DE, BC\}$,权为 $3 + 4 + 5 + 6 + 8 = 26$。$EF$、$AE$、$CE$ 都用不到。
(b) Prim from $A$. Tree $\{A\}$: edges out are $AD\,5$, $AB\,7$, $AE\,10$; add $AD$. Tree $\{A, D\}$: cheapest edge out is $DE\,6$; add it. Tree $\{A, D, E\}$: candidates $BE\,3$, $AB\,7$, $EF\,9$, $CE\,11$; add $BE$. Tree $\{A, B, D, E\}$: candidates $BC\,8$, $EF\,9$, $CE\,11$ ($AB$ now joins two tree vertices, so it is not a candidate); add $BC$. Tree $\{A, B, C, D, E\}$: candidates $CF\,4$, $EF\,9$; add $CF$. Order: $AD, DE, BE, BC, CF$, total $5 + 6 + 3 + 8 + 4 = 26$. Same tree, same total.
(b) 从 $A$ 出发用 Prim 算法。树 $\{A\}$:向外的边为 $AD\,5$、$AB\,7$、$AE\,10$;加入 $AD$。树 $\{A, D\}$:向外最便宜的边是 $DE\,6$;加入。树 $\{A, D, E\}$:候选 $BE\,3$、$AB\,7$、$EF\,9$、$CE\,11$;加入 $BE$。树 $\{A, B, D, E\}$:候选 $BC\,8$、$EF\,9$、$CE\,11$($AB$ 此时连接两个树内顶点,不再是候选);加入 $BC$。树 $\{A, B, C, D, E\}$:候选 $CF\,4$、$EF\,9$;加入 $CF$。顺序:$AD, DE, BE, BC, CF$,总权 $5 + 6 + 3 + 8 + 4 = 26$。同一棵树,总权相同。
Why this works. Both algorithms add the cheapest edge that keeps the chosen set free of cycles, so they reach a tree of the same least weight; all weights here are different, so it is the same tree.
为什么可行。两种算法都在不产生圈的前提下加入最便宜的边,所以得到总权同为最小的树;这里所有权都不同,所以是同一棵树。
Prim's algorithm on a table在表格上用 Prim 算法
When the graph is given as a weighted adjacency table, run Prim's algorithm on the table itself. (1) Choose a start vertex: cross out its row and number its column $1$. (2) Look down every numbered column for the smallest entry that is not crossed out; that entry is the next edge, and its row gives the new vertex. (3) Cross out the new vertex's row and give its column the next number. Repeat (2) and (3) until every column is numbered. Crossing out rows stops you from choosing an edge back into the tree, so no cycle can form.
当图以带权邻接表给出时,直接在表上运行 Prim 算法。(1) 选起始顶点:划掉它所在的行,并把它的列编号为 $1$。(2) 在所有已编号的列中找出未被划掉的最小元素;这个元素就是下一条边,它所在的行给出新顶点。(3) 划掉新顶点所在的行,并给它的列编下一个号。重复 (2)(3),直到所有列都编了号。划掉行可以防止选到通回树内的边,所以不会形成圈。
Worked Example C5.5b: Prim's algorithm on a table例题 C5.5b:在表格上用 Prim 算法
Five warehouses $P, Q, R, S, T$ are joined by roads whose lengths in km are given in the table (every pair is joined, so the graph is $K_5$). Use Prim's algorithm on the table, starting at $P$, to find a minimum spanning tree, and check it with Kruskal's algorithm.五个仓库 $P, Q, R, S, T$ 之间都有道路相连,长度(km)见下表(每对之间都有路,所以图为 $K_5$)。从 $P$ 出发,在表格上用 Prim 算法求最小生成树,并用 Kruskal 算法检验。
| P | Q | R | S | T | |
|---|---|---|---|---|---|
| P | - | 8 | 5 | 9 | 12 |
| Q | 8 | - | 4 | 7 | 10 |
| R | 5 | 4 | - | 6 | 9 |
| S | 9 | 7 | 6 | - | 3 |
| T | 12 | 10 | 9 | 3 | - |
Step 1. Start at $P$: cross out row $P$, number column $P$ as $1$.
第 1 步。从 $P$ 出发:划掉 $P$ 行,把 $P$ 列编号为 $1$。
Step 2. Column $P$, rows not crossed out: $Q\,8$, $R\,5$, $S\,9$, $T\,12$. Smallest is $5$ in row $R$: choose $PR$. Cross out row $R$; number column $R$ as $2$.
第 2 步。$P$ 列中未划掉的行:$Q\,8$、$R\,5$、$S\,9$、$T\,12$。最小的是 $R$ 行的 $5$:选 $PR$。划掉 $R$ 行;把 $R$ 列编号为 $2$。
Step 3. Columns $P$ and $R$, rows $Q, S, T$: column $P$ gives $8, 9, 12$; column $R$ gives $4, 6, 9$. Smallest is $4$ (column $R$, row $Q$): choose $RQ$. Cross out row $Q$; number column $Q$ as $3$.
第 3 步。$P$ 列和 $R$ 列中 $Q, S, T$ 行:$P$ 列为 $8, 9, 12$;$R$ 列为 $4, 6, 9$。最小的是 $4$($R$ 列 $Q$ 行):选 $RQ$。划掉 $Q$ 行;把 $Q$ 列编号为 $3$。
Step 4. Columns $P, R, Q$, rows $S, T$: $9, 12$; $6, 9$; $7, 10$. Smallest is $6$ (column $R$, row $S$): choose $RS$. Cross out row $S$; number column $S$ as $4$.
第 4 步。$P, R, Q$ 列中 $S, T$ 行:$9, 12$;$6, 9$;$7, 10$。最小的是 $6$($R$ 列 $S$ 行):选 $RS$。划掉 $S$ 行;把 $S$ 列编号为 $4$。
Step 5. Only row $T$ is left: columns $P, R, Q, S$ give $12, 9, 10, 3$. Smallest is $3$: choose $ST$. Number column $T$ as $5$. Every column is numbered, so stop.
第 5 步。只剩 $T$ 行:$P, R, Q, S$ 列分别为 $12, 9, 10, 3$。最小的是 $3$:选 $ST$。把 $T$ 列编号为 $5$。所有列都已编号,停止。
Result. Edges $PR, RQ, RS, ST$; total $5 + 4 + 6 + 3 = 18$ km. Check: $4 = 5 - 1$ edges.
结果。边 $PR, RQ, RS, ST$;总长 $5 + 4 + 6 + 3 = 18$ km。检验:$4 = 5 - 1$ 条边。
Kruskal check. Sorted: $ST\,3$ add, $QR\,4$ add, $PR\,5$ add, $RS\,6$ add (joins $\{P, Q, R\}$ to $\{S, T\}$); four edges, stop. Same tree, $18$ km.
用 Kruskal 检验。排序后:$ST\,3$ 加入,$QR\,4$ 加入,$PR\,5$ 加入,$RS\,6$ 加入(把 $\{P, Q, R\}$ 与 $\{S, T\}$ 连起来);已有四条边,停止。同一棵树,$18$ km。
Why this works. The numbered columns are the vertices already in the tree and the rows not crossed out are the vertices outside it, so each step picks the cheapest edge from inside to outside, which is exactly Prim's rule.
为什么可行。已编号的列是树内的顶点,未划掉的行是树外的顶点,所以每一步选的都是从树内到树外最便宜的边,这正是 Prim 算法的规则。
The algorithm is the method, so show it: for Kruskal list the edges in the order considered and write "add" or "reject (forms a cycle)" for each; for Prim list the edges in the order added. A correct tree with no order shown is an incomplete answer when the question names the algorithm. Use the starting vertex the question gives for Prim, state the total weight with units, and check that you have $n - 1$ edges.
算法本身就是方法,所以要写出来:用 Kruskal 算法时按考虑顺序列出各边,并对每条写"加入"或"拒绝(形成圈)";用 Prim 算法时按加入顺序列出各边。题目指定了算法时,只给出正确的树而不写顺序是不完整的答案。用 Prim 算法要从题目给定的顶点出发,写出带单位的总权,并检查是否有 $n - 1$ 条边。
In Worked Example C5.5a, explain why Kruskal's algorithm rejects $AB$ even though it is the fifth-cheapest edge.在例题 C5.5a 中,解释为什么 Kruskal 算法拒绝 $AB$,尽管它是第五便宜的边。
After $BE$, $AD$ and $DE$ are chosen, $A$ and $B$ are already joined by the route $A, D, E, B$. Adding $AB$ would close the cycle $A, B, E, D, A$, and a tree has no cycles.
选了 $BE$、$AD$、$DE$ 之后,$A$ 与 $B$ 已经由路线 $A, D, E, B$ 相连。加入 $AB$ 会形成圈 $A, B, E, D, A$,而树中没有圈。
Apply Prim's algorithm to the graph of Figure C5.2 starting at $F$. List the edges in the order added.从 $F$ 出发,对图 C5.2 的图应用 Prim 算法。按加入顺序列出各边。
From $\{F\}$: $CF\,4$ (vs $EF\,9$). From $\{C, F\}$: $BC\,8$ (vs $EF\,9$, $CE\,11$). From $\{B, C, F\}$: $BE\,3$. From $\{B, C, E, F\}$: $DE\,6$ (vs $AB\,7$, $AE\,10$). From $\{B, C, D, E, F\}$: $AD\,5$. Order $CF, BC, BE, DE, AD$; total $26$, the same tree.
从 $\{F\}$:$CF\,4$(对比 $EF\,9$)。从 $\{C, F\}$:$BC\,8$(对比 $EF\,9$、$CE\,11$)。从 $\{B, C, F\}$:$BE\,3$。从 $\{B, C, E, F\}$:$DE\,6$(对比 $AB\,7$、$AE\,10$)。从 $\{B, C, D, E, F\}$:$AD\,5$。顺序 $CF, BC, BE, DE, AD$;总权 $26$,同一棵树。
In the warehouse table, the road $RT$ is closed for repairs (delete the entry $9$). Does the minimum spanning tree change? Explain.在仓库表中,道路 $RT$ 因维修封闭(删去元素 $9$)。最小生成树会改变吗?请解释。
No. The tree $PR, RQ, RS, ST$ does not use $RT$, and deleting an edge cannot make any other spanning tree lighter, so the same tree (weight $18$ km) is still minimal.
不会。树 $PR, RQ, RS, ST$ 没有用到 $RT$,而删去一条边不会让其他生成树变得更轻,所以同一棵树(权 $18$ km)仍然是最小的。
Chinese Postman and Travelling Salesman Problems, Upper and Lower Bounds中国邮递员问题与旅行商问题,上界与下界 HL AHL 3.16
- Solve the Chinese postman problem by pairing the odd vertices and choosing the pairing of least total weight.
- Adapt the Chinese postman route when the start and end vertices may differ.
- Distinguish the classical and practical travelling salesman problems.
- Calculate an upper bound for the travelling salesman problem with the nearest-neighbour algorithm.
- Calculate a lower bound with the deleted-vertex algorithm and interpret both bounds.
- 通过给奇顶点配对、选总权最小的配对,求解中国邮递员问题。
- 当起点与终点可以不同时,调整中国邮递员路线。
- 区分(
distinguish)经典旅行商问题与实际旅行商问题。 - 用最近邻算法计算(
calculate)旅行商问题的上界。 - 用删点算法计算下界,并解读(
interpret)上下两个界。
The Chinese postman problem中国邮递员问题
A postman, a snow plough or a road inspector must travel along every edge at least once and return to the start, for the least total weight. This is the Chinese postman problem (also called the route inspection problem). If every vertex is even, an Eulerian circuit (C5.4) does the job and the least weight is simply the total weight of the graph. Otherwise some edges must be travelled twice. Repeating the edges of a route between two odd vertices makes both of them even, so the method is:
邮递员、扫雪车或道路巡查员必须把每一条边至少走一次并回到起点,且总权最小。这就是中国邮递员问题(Chinese postman problem,也叫道路巡查问题 route inspection)。若每个顶点都是偶顶点,一条欧拉回路(C5.4)即可完成,最小权就是图的总权。否则必须有一些边走两次。把两个奇顶点之间一条路线上的边重复一遍,就能使这两个顶点都变成偶顶点,所以方法是:
- List the odd vertices (there is always an even number of them).
- List every way of pairing them up. Four odd vertices $W, X, Y, Z$ give three pairings: $WX\,|\,YZ$, $WY\,|\,XZ$, $WZ\,|\,XY$.
- For each pair, find the shortest route between the two vertices (it need not be the direct edge). Add the two shortest routes for each pairing.
- Choose the pairing with the least sum. Least route weight $=$ total weight of the graph $+$ that sum. The repeated edges are the edges of the chosen shortest routes.
- 列出奇顶点(奇顶点总是偶数个)。
- 列出所有配对方式。四个奇顶点 $W, X, Y, Z$ 有三种配对:$WX\,|\,YZ$、$WY\,|\,XZ$、$WZ\,|\,XY$。
- 对每一对,求两顶点之间的最短路线(不一定是直接的边)。把每种配对中两条最短路线的长度相加。
- 选总和最小的配对。最小路线权 $=$ 图的总权 $+$ 该总和。重复走的边就是所选最短路线上的边。
With exactly two odd vertices there is only one pair: add the shortest route between them. If the route may start and end at different vertices, start at one odd vertex and finish at another; then only the remaining odd vertices need pairing, so leave unrepeated the pair whose removal saves the most.
若恰有两个奇顶点,只有一对:加上二者之间的最短路线即可。若路线可以在不同顶点开始和结束,就从一个奇顶点出发、在另一个奇顶点结束;这样只有其余的奇顶点需要配对,因此应选择使节省最多的那一对不重复。
Worked Example C5.6a: Chinese postman on Figure C5.3例题 C5.6a:图 C5.3 上的中国邮递员问题
An inspector must drive along every road in Figure C5.3 (lengths in km), starting and finishing at $A$. Find the length of the shortest possible route, state which roads are driven twice, and write down a route.巡查员必须驶过图 C5.3 中的每一条道路(长度单位 km),起点和终点都是 $A$。求最短可能路线的长度,写出哪些道路要走两次,并写出一条路线。
Total weight. $6 + 5 + 12 + 7 + 8 + 3 + 5 + 6 = 52$ km.
总权。$6 + 5 + 12 + 7 + 8 + 3 + 5 + 6 = 52$ km。
Odd vertices. $\deg(B) = \deg(C) = \deg(D) = \deg(E) = 3$; $\deg(A) = \deg(F) = 2$. Four odd vertices: $B, C, D, E$.
奇顶点。$\deg(B) = \deg(C) = \deg(D) = \deg(E) = 3$;$\deg(A) = \deg(F) = 2$。四个奇顶点:$B, C, D, E$。
Shortest routes between odd vertices. $BC$: direct $12$, or $B \to A \to C = 11$, so $11$. $DE$: direct $3$. $BD$: direct $7$. $CE$: direct $8$. $BE$: $B \to D \to E = 10$ (vs $B \to C \to E = 20$, $B \to A \to C \to E = 19$), so $10$. $CD$: $C \to E \to D = 11$ (vs $C \to A \to B \to D = 18$), so $11$.
奇顶点之间的最短路线。$BC$:直接 $12$,或 $B \to A \to C = 11$,取 $11$。$DE$:直接 $3$。$BD$:直接 $7$。$CE$:直接 $8$。$BE$:$B \to D \to E = 10$(对比 $B \to C \to E = 20$、$B \to A \to C \to E = 19$),取 $10$。$CD$:$C \to E \to D = 11$(对比 $C \to A \to B \to D = 18$),取 $11$。
| Pairing | Shortest routes | Sum |
|---|---|---|
| BC | DE | 11 + 3 | 14 |
| BD | CE | 7 + 8 | 15 |
| BE | CD | 10 + 11 | 21 |
| 配对 | 最短路线 | 和 |
|---|---|---|
| BC | DE | 11 + 3 | 14 |
| BD | CE | 7 + 8 | 15 |
| BE | CD | 10 + 11 | 21 |
Result. The best pairing is $BC\,|\,DE$, adding $14$ km: the roads $BA$, $AC$ and $DE$ are driven twice. Shortest route length $= 52 + 14 = 66$ km.
结果。最优配对为 $BC\,|\,DE$,增加 $14$ km:道路 $BA$、$AC$、$DE$ 走两次。最短路线长度 $= 52 + 14 = 66$ km。
A route. With the repeats added every vertex is even ($A$ now has degree $4$, $B, C, D, E$ have degree $4$, $F$ has $2$), so an Eulerian circuit exists: $A \to B \to C \to A \to B \to D \to E \to D \to F \to E \to C \to A$. Check: $6 + 12 + 5 + 6 + 7 + 3 + 3 + 5 + 6 + 8 + 5 = 66$ km, and every road appears.
一条路线。加上重复的边后每个顶点都是偶顶点($A$ 的度变为 $4$,$B, C, D, E$ 的度为 $4$,$F$ 为 $2$),所以存在欧拉回路:$A \to B \to C \to A \to B \to D \to E \to D \to F \to E \to C \to A$。检验:$6 + 12 + 5 + 6 + 7 + 3 + 3 + 5 + 6 + 8 + 5 = 66$ km,且每条道路都出现了。
Why this works. Every odd vertex needs one extra edge end, and repeating a shortest route between two odd vertices supplies exactly that while leaving every vertex on the route even; the cheapest pairing adds the least extra distance.
为什么可行。每个奇顶点都需要多一个边端点,在两个奇顶点之间重复一条最短路线正好提供这一点,而路线经过的其他顶点仍保持偶数度;最便宜的配对增加的额外距离最少。
The travelling salesman problem旅行商问题
In the travelling salesman problem (TSP) a salesperson must visit every vertex and return to the start for the least total weight. In the classical problem each vertex is visited exactly once, so the answer is a Hamiltonian cycle of least weight. In the practical problem each vertex is visited at least once, so passing through a vertex again is allowed when it is shorter. If a table has an entry longer than a route through another vertex (as $XZ = 6$ against $X \to Y \to Z = 5$ in C5.3), first replace every entry by the least distance between the two vertices; the bounds below are then found on that table of least distances. For $n$ vertices there are $\tfrac{(n-1)!}{2}$ different Hamiltonian cycles in $K_n$, which grows too fast to check them all, so we trap the answer between two bounds.
在旅行商问题(travelling salesman problem,TSP)中,推销员必须访问每一个顶点并回到起点,且总权最小。在经典(classical)问题中每个顶点恰好访问一次,所以答案是权最小的哈密顿圈。在实际(practical)问题中每个顶点至少访问一次,所以若更短,允许再次经过某个顶点。若表中某个元素比经过另一个顶点的路线还长(如 C5.3 中 $XZ = 6$ 而 $X \to Y \to Z = 5$),先把每个元素替换为两顶点之间的最短距离;下面的界就在这张最短距离表上求。对 $n$ 个顶点,$K_n$ 中有 $\tfrac{(n-1)!}{2}$ 个不同的哈密顿圈,增长太快无法逐一检查,所以我们用两个界把答案夹住。
- Upper bound: nearest-neighbour algorithm. Start at a vertex. Repeatedly move to the nearest vertex not yet visited. When every vertex has been visited, return to the start. The length of this tour is an upper bound: it is a real tour, so the best tour is no longer. Different starting vertices can give different tours; the smallest is the best upper bound.
- Lower bound: deleted-vertex algorithm. Delete one vertex $X$ and every edge at it. Find the weight of a minimum spanning tree of what remains. Add the two smallest weights of edges at $X$. The total is a lower bound. Deleting different vertices can give different values; the largest is the best lower bound.
- 上界:最近邻算法(
nearest-neighbour algorithm)。从一个顶点出发,每次移动到尚未访问的最近顶点。所有顶点都访问后回到起点。这条回路的长度是上界(upper bound):它是一条真实的回路,所以最优回路不会更长。不同的起点可能给出不同的回路;其中最小的是最好的上界。 - 下界:删点算法(
deleted-vertex algorithm)。删去一个顶点 $X$ 以及与它相连的所有边。求剩余部分最小生成树的权。再加上 $X$ 处两条最小边的权。总和就是下界(lower bound)。删去不同的顶点可能得到不同的值;其中最大的是最好的下界。
Why the lower bound works. Take an optimal tour and remove $X$ from it. What is left is a path through all the other vertices, which is a spanning tree of them, so its weight is at least the minimum spanning tree weight. The two tour edges at $X$ weigh at least the two smallest edges at $X$. So the optimal tour weighs at least the sum. Together: lower bound $\le$ optimal tour $\le$ upper bound. If a lower bound equals an upper bound, the tour that gave the upper bound is optimal.
为什么下界成立。取一条最优回路并从中去掉 $X$。剩下的是经过其余所有顶点的一条路径,它是这些顶点的一棵生成树,所以其权不小于最小生成树的权。回路在 $X$ 处的两条边的权不小于 $X$ 处最小的两条边。所以最优回路的权不小于这个和。合起来:下界 $\le$ 最优回路 $\le$ 上界。若某个下界等于某个上界,则给出该上界的回路就是最优的。
Worked Example C5.6b: nearest-neighbour upper bound例题 C5.6b:最近邻上界
A driver must visit the five warehouses of Worked Example C5.5b (same table) and return. Each entry is no longer than any route through another warehouse, so this is a classical problem. Use the nearest-neighbour algorithm starting at $P$, and then starting at $S$, to find upper bounds.司机必须访问例题 C5.5b 中的五个仓库(同一张表)并返回。表中每个元素都不长于经过另一仓库的路线,所以这是经典问题。分别从 $P$ 和 $S$ 出发,用最近邻算法求上界。
From $P$. Nearest to $P$: $R\,(5)$. From $R$, unvisited $Q\,4$, $S\,6$, $T\,9$: go to $Q\,(4)$. From $Q$, unvisited $S\,7$, $T\,10$: go to $S\,(7)$. From $S$: only $T$ is left, $T\,(3)$. Return $T \to P\,(12)$. Tour $P \to R \to Q \to S \to T \to P$, length $5 + 4 + 7 + 3 + 12 = 31$ km.
从 $P$ 出发。离 $P$ 最近的是 $R\,(5)$。从 $R$ 出发,未访问的有 $Q\,4$、$S\,6$、$T\,9$:去 $Q\,(4)$。从 $Q$ 出发,未访问的有 $S\,7$、$T\,10$:去 $S\,(7)$。从 $S$ 出发只剩 $T$:$T\,(3)$。返回 $T \to P\,(12)$。回路 $P \to R \to Q \to S \to T \to P$,长度 $5 + 4 + 7 + 3 + 12 = 31$ km。
From $S$. $S \to T\,(3)$; from $T$: $R\,9$, $Q\,10$, $P\,12$, go to $R\,(9)$; from $R$: $Q\,4$, $P\,5$, go to $Q\,(4)$; from $Q$: $P\,(8)$; return $P \to S\,(9)$. Tour $S \to T \to R \to Q \to P \to S$, length $3 + 9 + 4 + 8 + 9 = 33$ km.
从 $S$ 出发。$S \to T\,(3)$;从 $T$:$R\,9$、$Q\,10$、$P\,12$,去 $R\,(9)$;从 $R$:$Q\,4$、$P\,5$,去 $Q\,(4)$;从 $Q$:$P\,(8)$;返回 $P \to S\,(9)$。回路 $S \to T \to R \to Q \to P \to S$,长度 $3 + 9 + 4 + 8 + 9 = 33$ km。
Conclusion. Both are upper bounds; the better (smaller) one is $31$ km, so the optimal tour is at most $31$ km.
结论。两者都是上界;较好(较小)的是 $31$ km,所以最优回路不超过 $31$ km。
Why this works. Nearest neighbour is greedy: it never looks ahead, so the last edge back to the start can be long (here $TP = 12$). That is why it gives only a bound, and why trying other starts can help.
为什么可行。最近邻算法是贪心的:它从不往前看,所以回到起点的最后一条边可能很长(这里 $TP = 12$)。这就是它只能给出一个界的原因,也是换其他起点可能有帮助的原因。
Worked Example C5.6c: deleted-vertex lower bound例题 C5.6c:删点下界
For the same five warehouses: (a) delete $P$ and find a lower bound; (b) delete $R$ and find a lower bound; (c) state the best interval for the length $L$ of the optimal tour and comment.对同样五个仓库:(a) 删去 $P$ 求一个下界;(b) 删去 $R$ 求一个下界;(c) 写出最优回路长度 $L$ 的最佳区间并作评论。
(a) Delete $P$. Remaining edges sorted: $ST\,3$, $QR\,4$, $RS\,6$, $QS\,7$, $RT\,9$, $QT\,10$. Kruskal: add $ST$, add $QR$, add $RS$ (joins the two pieces); three edges for four vertices, stop. MST weight $3 + 4 + 6 = 13$. The two smallest edges at $P$ are $PR = 5$ and $PQ = 8$. Lower bound $= 13 + 5 + 8 = 26$ km.
(a) 删去 $P$。剩余的边排序:$ST\,3$、$QR\,4$、$RS\,6$、$QS\,7$、$RT\,9$、$QT\,10$。Kruskal:加入 $ST$,加入 $QR$,加入 $RS$(把两块连起来);四个顶点已有三条边,停止。最小生成树的权 $3 + 4 + 6 = 13$。$P$ 处最小的两条边为 $PR = 5$ 和 $PQ = 8$。下界 $= 13 + 5 + 8 = 26$ km。
(b) Delete $R$. Remaining edges sorted: $ST\,3$, $QS\,7$, $PQ\,8$, $PS\,9$, $QT\,10$, $PT\,12$. Kruskal: add $ST$, add $QS$, add $PQ$; stop. MST weight $3 + 7 + 8 = 18$. Two smallest edges at $R$: $RQ = 4$ and $RP = 5$. Lower bound $= 18 + 4 + 5 = 27$ km.
(b) 删去 $R$。剩余的边排序:$ST\,3$、$QS\,7$、$PQ\,8$、$PS\,9$、$QT\,10$、$PT\,12$。Kruskal:加入 $ST$,加入 $QS$,加入 $PQ$;停止。最小生成树的权 $3 + 7 + 8 = 18$。$R$ 处最小的两条边:$RQ = 4$ 和 $RP = 5$。下界 $= 18 + 4 + 5 = 27$ km。
(c) The better lower bound is the larger one, $27$; the best upper bound found is $31$. So $27 \le L \le 31$ km. (Deleting $S$ or $T$ also gives $27$, and deleting $Q$ gives $25$.) Check: $K_5$ has only $\tfrac{4!}{2} = 12$ different tours; listing them shows that the least is $31$ km, so here the nearest-neighbour tour from $P$ is in fact optimal. The bounds alone could not prove that, because $27 \ne 31$.
(c) 较好的下界是较大的那个,$27$;找到的最好上界是 $31$。所以 $27 \le L \le 31$ km。(删去 $S$ 或 $T$ 也得 $27$,删去 $Q$ 得 $25$。)检验:$K_5$ 只有 $\tfrac{4!}{2} = 12$ 条不同的回路;把它们列出来可知最小的是 $31$ km,所以这里从 $P$ 出发的最近邻回路其实就是最优的。仅凭上下界无法证明这一点,因为 $27 \ne 31$。
Why this works. Each deletion gives a valid lower bound, so the largest of them is the tightest; with the smallest upper bound it gives the narrowest interval for $L$.
为什么可行。每次删点都给出一个有效的下界,所以其中最大的最紧;与最小的上界合起来,就得到 $L$ 最窄的区间。
In a Chinese postman answer, list the odd vertices, all the pairings with their shortest-route sums, the chosen pairing, the repeated edges and the final total. In a travelling salesman answer, write the nearest-neighbour tour as a vertex sequence with each edge weight, and for the deleted-vertex method name the deleted vertex, show the spanning tree weight and the two added edges. Keep the words straight: the best upper bound is the smallest upper bound, and the best lower bound is the largest lower bound.
回答中国邮递员问题时,列出奇顶点、所有配对及其最短路线之和、所选配对、重复的边以及最终总长。回答旅行商问题时,把最近邻回路写成顶点序列并标出每条边的权;用删点法时写明删去的顶点、生成树的权以及加上的两条边。注意用词:最好的上界是最小的上界,最好的下界是最大的下界。
In Figure C5.3, the inspector may now start and finish at different vertices. Find the shortest route length and where it starts and ends.在图 C5.3 中,巡查员现在可以在不同顶点开始和结束。求最短路线长度以及起点和终点。
Start and end at two odd vertices and repeat only the shortest route between the other two. The options add $DE = 3$ (start and end at $B$ and $C$), $BC = 11$, $CE = 8$, $BD = 7$, $CD = 11$ or $BE = 10$. The least is $3$: start at $B$ and end at $C$ (or the reverse), length $52 + 3 = 55$ km.
在两个奇顶点开始和结束,只重复另外两个奇顶点之间的最短路线。可选的增加量为 $DE = 3$(在 $B$ 和 $C$ 开始与结束)、$BC = 11$、$CE = 8$、$BD = 7$、$CD = 11$ 或 $BE = 10$。最小为 $3$:从 $B$ 出发在 $C$ 结束(或反过来),长度 $52 + 3 = 55$ km。
Every edge of graph G (Figure C5.1) has length $1$ km. Find the length of the shortest closed route that travels every edge.图 G(图 C5.1)的每条边长 $1$ km。求经过每条边的最短闭合路线的长度。
Total weight $4$. The only odd vertices are $C$ and $D$, and the shortest route between them is the edge $CD$ ($1$). Shortest route $= 4 + 1 = 5$ km, for example $C \to A \to B \to C \to D \to C$.
总权为 $4$。只有 $C$ 和 $D$ 是奇顶点,二者之间的最短路线是边 $CD$($1$)。最短路线 $= 4 + 1 = 5$ km,例如 $C \to A \to B \to C \to D \to C$。
Use the nearest-neighbour algorithm from $Q$ on the warehouse table. What does the result tell you?在仓库表上从 $Q$ 出发使用最近邻算法。结果说明了什么?
$Q \to R\,(4)$, $R \to P\,(5)$, $P \to S\,(9)$, $S \to T\,(3)$, $T \to Q\,(10)$: length $4 + 5 + 9 + 3 + 10 = 31$ km. It is another upper bound of $31$, so the interval stays $27 \le L \le 31$ km.
$Q \to R\,(4)$、$R \to P\,(5)$、$P \to S\,(9)$、$S \to T\,(3)$、$T \to Q\,(10)$:长度 $4 + 5 + 9 + 3 + 10 = 31$ km。它是又一个等于 $31$ 的上界,所以区间仍为 $27 \le L \le 31$ km。
Exam Strategy and Common Pitfalls考试策略与常见陷阱
- Connect every vertex as cheaply as possible (cables, pipes): minimum spanning tree, by Kruskal's or Prim's algorithm.
- Travel every edge (post, snow ploughs, inspections): Chinese postman; look at the odd vertices.
- Visit every vertex (deliveries, tours): travelling salesman; give the nearest-neighbour upper bound and the deleted-vertex lower bound.
- Count routes of a given length: powers of the adjacency matrix. Long-run behaviour of a random walk: transition matrix and steady state.
- 以最低代价连接所有顶点(电缆、管道):最小生成树,用 Kruskal 或 Prim 算法。
- 走遍每一条边(投递、扫雪、巡查):中国邮递员问题;先看奇顶点。
- 访问每一个顶点(送货、巡回):旅行商问题;给出最近邻上界和删点下界。
- 计数给定长度的路线:邻接矩阵的幂。随机游走的长期行为:转移矩阵与稳态。
- Counting a loop as $1$ in a degree (it adds $2$), or forgetting that "simple" forbids loops and multiple edges.
- Reading $(A^k)_{ij}$ as a number of paths: it counts walks, which may repeat vertices and edges.
- Building a transition matrix with rows from and columns to, then multiplying $T s_0$ as if the columns summed to $1$.
- Saying a graph is Eulerian without checking it is connected, or confusing Eulerian (edges) with Hamiltonian (vertices).
- In Chinese postman, using the direct edge between two odd vertices when a route through another vertex is shorter.
- Calling the larger nearest-neighbour tour the "better" upper bound, or the smaller deleted-vertex value the "better" lower bound.
- 把环在度中算作 $1$(它使度加 $2$),或忘记"简单"不允许环和重边。
- 把 $(A^k)_{ij}$ 当成路径数:它数的是通路,顶点和边都可以重复。
- 把转移矩阵建成"行表示出发、列表示到达",却仍按列和为 $1$ 的方式计算 $T s_0$。
- 没检查连通就说图是欧拉图,或把欧拉(边)与哈密顿(顶点)混淆。
- 在中国邮递员问题中,两个奇顶点之间明明经过另一顶点的路线更短,却用了直接的边。
- 把较大的最近邻回路称为"更好的"上界,或把较小的删点值称为"更好的"下界。
The GDC raises matrices to powers, adds them, and finds $T^n s_0$ for large $n$; enter the matrix once and reuse it. The graph algorithms (Kruskal, Prim, pairings, nearest neighbour, deleted vertex) are written out by hand step by step, with the GDC used for the sums.
GDC 可以计算矩阵的幂、把它们相加,并对较大的 $n$ 求 $T^n s_0$;矩阵输入一次即可反复使用。图算法(Kruskal、Prim、配对、最近邻、删点)要手写、逐步写出,GDC 只用来求和。
For the 2021 syllabus (exams to November 2028), Paper 1 (compulsory short-response questions) and Paper 2 (compulsory extended-response questions) each last 2 hours, are each worth 110 marks and each count for 30%. Paper 3 is worth 55 marks and 20%, with two compulsory extended-response problems. Technology is required on Papers 1, 2 and 3. The internal assessment, a mathematical exploration, is the remaining 20%. Practise running each algorithm on paper with every step written, since the GDC does not do that part for you.
对 2021 版大纲(考试至 2028 年 11 月):Paper 1(必答短答题)与 Paper 2(必答长答题)各 2 小时,各 110 分,各占 30%。Paper 3 为 55 分,占 20%,有两道必答的长答题。Paper 1、2、3 都要求使用技术工具(technology)。其余 20% 是内部评估(internal assessment),即数学探究(mathematical exploration)。每个算法都要练到能在纸上逐步写出,因为这部分 GDC 替你做不了。
Flashcards (HL unit)闪卡(HL 单元)
Unit C5 Practice Quiz (HL unit)单元 C5 练习测验(HL 单元)
Readiness Checklist (HL unit)备考清单(HL 单元)
Tick each item when you can do it cold, without notes, on your first attempt. The entire unit is HL only, so every item below is HL content.
每一条都要"裸做"做对(不看笔记、一次过)才打勾。本单元为纯 HL,所以下面每一条都是 HL 内容。
- Find the degree of each vertex (a loop adds 2) and use the handshake lemma to show a graph cannot exist求每个顶点的度(环加 2),并用握手引理说明某个图不可能存在
- Recognise simple, complete ($K_n$ has $\tfrac{n(n-1)}{2}$ edges), weighted and directed graphs, and find in-degrees and out-degrees识别简单图、完全图($K_n$ 有 $\tfrac{n(n-1)}{2}$ 条边)、带权图与有向图,并求入度与出度
- Identify subgraphs, connected graphs, trees and spanning trees, and state that a tree on $n$ vertices has $n - 1$ edges识别子图、连通图、树与生成树,并写出 $n$ 个顶点的树有 $n - 1$ 条边
- Write the adjacency matrix of an undirected or directed graph in a stated vertex order按指定顶点顺序写出无向图或有向图的邻接矩阵
- Use $A^k$ (and $A + A^2 + \dots + A^k$) on a GDC to count walks of length $k$ (or at most $k$)在 GDC 上用 $A^k$(及 $A + A^2 + \dots + A^k$)计数长度为 $k$(或不超过 $k$)的通路
- Read and build a weighted adjacency table, and find the lightest route between two vertices读懂并建立带权邻接表,求两顶点之间最轻的路线
- Build the transition matrix of a random walk on a graph, find $T^n s_0$ and the steady state, and interpret them建立图上随机游走的转移矩阵,求 $T^n s_0$ 与稳态,并加以解读
- Classify a route as a walk, trail, path, circuit or cycle把一条路线归类为通路、迹、路径、回路或圈
- State the degree conditions for Eulerian circuits and trails, and write one down; give a reason a Hamiltonian cycle does or does not exist写出欧拉回路与欧拉迹的度条件并写出一条;给出哈密顿圈存在或不存在的理由
- Run Kruskal's and Prim's algorithms on a drawn graph, showing the order of edges在画好的图上运行 Kruskal 与 Prim 算法,写明边的顺序
- Run Prim's algorithm on a weighted adjacency table by crossing out rows and numbering columns在带权邻接表上通过划行、给列编号来运行 Prim 算法
- Solve a Chinese postman problem by pairing odd vertices, and find nearest-neighbour upper and deleted-vertex lower bounds for a travelling salesman problem通过奇顶点配对求解中国邮递员问题,并求旅行商问题的最近邻上界与删点下界
How to use this guide本指南使用说明
How to use this guide本指南使用说明
C5 is an HL-only unit of IB Mathematics: Applications and Interpretation, covering the 2021 sub-topics AHL 3.14 (graph theory basics), AHL 3.15 (adjacency matrices, walks, weighted tables and transition matrices) and AHL 3.16 (tree and cycle algorithms). The sections build on each other: the vocabulary of C5.1 and the degree counts are used in every later section, the same small graph G runs through C5.2 to C5.4, and the warehouse table of C5.5 returns in C5.6. A typical extended task chains several steps, such as a minimum spanning tree followed by travelling salesman bounds on the same table, so practise the whole chain as well as the single steps.C5 是 IB 数学:应用与解释中仅限 HL 的单元,涵盖 2021 版大纲的子主题 AHL 3.14(图论基础)、AHL 3.15(邻接矩阵、通路、带权表与转移矩阵)和 AHL 3.16(树与圈的算法)。各节层层递进:C5.1 的术语和度的计算在后面每一节都会用到,同一个小图 G 贯穿 C5.2 至 C5.4,C5.5 的仓库表在 C5.6 中再次出现。一道典型的长题会串起多个步骤,例如先求最小生成树,再在同一张表上求旅行商问题的上下界,所以既要练单个步骤,也要练完整链条。
Learn the four algorithms as recipes and run each once on the worked examples: Kruskal (cheapest edge without a cycle), Prim (grow one tree, also on a table), Chinese postman (pair the odd vertices) and the two travelling salesman bounds. Then memorise the Euler degree conditions and that $(A^k)_{ij}$ counts walks of length $k$.
把四个算法当作套路来记,并在例题上各跑一遍:Kruskal(不成圈的最便宜边)、Prim(让一棵树生长,也能在表上做)、中国邮递员(给奇顶点配对)以及旅行商问题的两个界。然后记住欧拉的度条件,以及 $(A^k)_{ij}$ 数的是长度为 $k$ 的通路。
Be able to explain why each method works: why the degree sum is even, why powers of $A$ count walks, why the steady state is proportional to degree, why the degrees decide Eulerian routes, and why the deleted-vertex total can never exceed the optimal tour. Watch for tables where a direct edge is longer than a two-step route.
要能解释每种方法为什么成立:为什么度数之和是偶数,为什么 $A$ 的幂能数通路,为什么稳态与度成正比,为什么度决定欧拉路线,以及为什么删点总和永远不会超过最优回路。留意表中直接的边比两步路线更长的情形。