10. Graph Theory

Graphs are mathematical abstracts of relations existing in some concrete things in the objective world.

10.1 Graphs and Graph Models

A **graph** 离散数学及其应用 第10、11章 图论 - 图1 consists of 离散数学及其应用 第10、11章 图论 - 图2, a nonempty set of **vertices** (or nodes), and 离散数学及其应用 第10、11章 图论 - 图3, a set of **edges**. Each edge has either one or two vertices associated with it, called its **endpoints**. An edge is said to connect its endpoints.
🌰 e.g.
image.png
离散数学及其应用 第10、11章 图论 - 图5, where 离散数学及其应用 第10、11章 图论 - 图6, 离散数学及其应用 第10、11章 图论 - 图7
**Infinite graph**: A graph with an infinite vertex set or an infinite number of edges.
**Finite graph**: A graph with a finite vertex set and a finite number of edges.
💡 We shall consider only finite graph in this course.
image.png
**Undirected graph**: A graph with undirected edges. Undirected graph can be classified into:

  • **Simple graph**: A graph in which each edge connects two different vertices and where no two edges connect the same pair of vertices.
  • **Multigraph**: Graphs that may have multiple edges connecting the same vertices.
  • **Pseudograph**: Graphs that may include loops, and possibly multiple edges connecting the same pair of vertices.

image.png
**Directed graph**: A graph with directed edges. A directed graph (or digraph) 离散数学及其应用 第10、11章 图论 - 图10 consists of a nonempty set of vertices 离散数学及其应用 第10、11章 图论 - 图11 and a set of directed edges (or arcs) 离散数学及其应用 第10、11章 图论 - 图12. Each directed edge is associated with an ordered pair of vertices. The directed edge associated with the ordered pair 离散数学及其应用 第10、11章 图论 - 图13 is said to start at 离散数学及其应用 第10、11章 图论 - 图14 and end at 离散数学及其应用 第10、11章 图论 - 图15. Digraph can be classified into:

  • **Simple directed graph**: A directed graph has no loops and has no multiple directed edges.
  • **Directed multigraph**: A directed graphs that may have multipledirected edges from a vertex to a second (possibly the same) vertex.

**Mixed graph**: A graph with both directed and directed edges.
image.png
⚙️ Problems in almost every conceivable discipline can be solved using **graph models**. For example:

  • Ramsey Problem: Each pair of individuals consists of two friends or two enemies, show that there are either three mutual friends or three mutual enemies in the group of six people.
  • Precedence Graph(前趋图)

离散数学及其应用 第10、11章 图论 - 图17
Precedence graphs represent the order of completing a series of tasks using directed graphs instead of Hasse graphs.

10.2 Graph Terminology and Special Types of Graphs

In Undirected Graphs 离散数学及其应用 第10、11章 图论 - 图18:

  • Two vertices 离散数学及其应用 第10、11章 图论 - 图19 and 离散数学及其应用 第10、11章 图论 - 图20 in an undirected graph 离散数学及其应用 第10、11章 图论 - 图21 are called **adjacent** (or **neighbors**) in 离散数学及其应用 第10、11章 图论 - 图22, if 离散数学及其应用 第10、11章 图论 - 图23 is an edge of 离散数学及其应用 第10、11章 图论 - 图24.
  • An edge 离散数学及其应用 第10、11章 图论 - 图25 connecting 离散数学及其应用 第10、11章 图论 - 图26 and 离散数学及其应用 第10、11章 图论 - 图27 is called **incident** with vertices 离散数学及其应用 第10、11章 图论 - 图28 and 离散数学及其应用 第10、11章 图论 - 图29, or is said to **connect** 离散数学及其应用 第10、11章 图论 - 图30 and 离散数学及其应用 第10、11章 图论 - 图31.
  • The vertices 离散数学及其应用 第10、11章 图论 - 图32 and 离散数学及其应用 第10、11章 图论 - 图33 are called **endpoints** of edge 离散数学及其应用 第10、11章 图论 - 图34.
  • An edge connects a vertex to itself is called a **loop**.
  • The **neighborhood** of 离散数学及其应用 第10、11章 图论 - 图35, denoted as 离散数学及其应用 第10、11章 图论 - 图36, is the set of all neighbors of a vertex 离散数学及其应用 第10、11章 图论 - 图37.
  • The **degree** of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex. Notation: 离散数学及其应用 第10、11章 图论 - 图38.
  • If 离散数学及其应用 第10、11章 图论 - 图39, 离散数学及其应用 第10、11章 图论 - 图40 is called **isolated**.
  • If 离散数学及其应用 第10、11章 图论 - 图41, 离散数学及其应用 第10、11章 图论 - 图42 is called **pendant**.

🌰 e.g.
Find the degree of all the vertices.
image.png
离散数学及其应用 第10、11章 图论 - 图44, 离散数学及其应用 第10、11章 图论 - 图45, 离散数学及其应用 第10、11章 图论 - 图46, 离散数学及其应用 第10、11章 图论 - 图47 because 离散数学及其应用 第10、11章 图论 - 图48 is connected by a loop, 离散数学及其应用 第10、11章 图论 - 图49, 离散数学及其应用 第10、11章 图论 - 图50.
Total of degrees = 3 + 3 + 4 + 5 + 1 + 0 = 16.
📋 The Handshaking Theorem
Let 离散数学及其应用 第10、11章 图论 - 图51 be an undirected graph with 离散数学及其应用 第10、11章 图论 - 图52 edges. Then 离散数学及其应用 第10、11章 图论 - 图53.
🌰 e.g.
If a graph has 5 vertices, can each vertex have degree 3? 4?
Solution:
If each vertex have degree 3, then the sum is 3×5 = 15, which is an odd number, so it is not possible. If each vertex have degree 4, then it may be possible.
📋 Corollary: An undirected graph has an even number of vertices of odd degree.
In Directed Graphs 离散数学及其应用 第10、11章 图论 - 图54:

  • Let 离散数学及其应用 第10、11章 图论 - 图55 be an edge in 离散数学及其应用 第10、11章 图论 - 图56. Then 离散数学及其应用 第10、11章 图论 - 图57 is an **initial vertex** and is **adjacent to** 离散数学及其应用 第10、11章 图论 - 图58, and 离散数学及其应用 第10、11章 图论 - 图59 is a **terminal vertex** and is **adjacent from** 离散数学及其应用 第10、11章 图论 - 图60.
  • The **in degree** of a vertex 离散数学及其应用 第10、11章 图论 - 图61, denoted by 离散数学及其应用 第10、11章 图论 - 图62, is the number of edges which terminate at 离散数学及其应用 第10、11章 图论 - 图63. Similarly, the **out degree** of 离散数学及其应用 第10、11章 图论 - 图64, denoted by 离散数学及其应用 第10、11章 图论 - 图65, is the number of edges which initiate at 离散数学及其应用 第10、11章 图论 - 图66.
  • The method of ignoring the directions in a digraph to find a path is called **underlying undirected graph**.

📋 Let 离散数学及其应用 第10、11章 图论 - 图67 be a graph with direct edges (not necessarily a digraph), then 离散数学及其应用 第10、11章 图论 - 图68. If it is a directed graph, then 离散数学及其应用 第10、11章 图论 - 图69.
📋 Some Special Simple Graphs

  • Complete Graphs — 离散数学及其应用 第10、11章 图论 - 图70: the simple graph with 离散数学及其应用 第10、11章 图论 - 图71 vertices and exactly one edge between every pair of distinct vertices.

image.png

  • Cycles —离散数学及其应用 第10、11章 图论 - 图73: 离散数学及其应用 第10、11章 图论 - 图74, where 离散数学及其应用 第10、11章 图论 - 图75, 离散数学及其应用 第10、11章 图论 - 图76, 离散数学及其应用 第10、11章 图论 - 图77.

image.png

  • Wheels 离散数学及其应用 第10、11章 图论 - 图79: Add one additional vertex to the cycle 离散数学及其应用 第10、11章 图论 - 图80 and add an edge from each vertex to the new vertex to produce 离散数学及其应用 第10、11章 图论 - 图81.

image.png
⚠️ Note that 离散数学及其应用 第10、11章 图论 - 图83 has 离散数学及其应用 第10、11章 图论 - 图84 vertices.

  • n-Cubes 离散数学及其应用 第10、11章 图论 - 图85: 离散数学及其应用 第10、11章 图论 - 图86 is the graph with 离散数学及其应用 第10、11章 图论 - 图87 vertices representing bit strings of length 离散数学及其应用 第10、11章 图论 - 图88, where 离散数学及其应用 第10、11章 图论 - 图89, 离散数学及其应用 第10、11章 图论 - 图90.

image.png
📋 Construct 离散数学及其应用 第10、11章 图论 - 图92 from 离散数学及其应用 第10、11章 图论 - 图93

  1. Making two copies of 离散数学及其应用 第10、11章 图论 - 图94, prefacing the labels on the vertices with a 0 in one copy and with a 1 in the other copy.
  2. Adding edges connecting two vertices that have labels differing only in the first bit.

image.png
A simple graph 离散数学及其应用 第10、11章 图论 - 图96 is **bipartite**(偶图) if 离散数学及其应用 第10、11章 图论 - 图97 can be partitioned into two disjoint subsets 离散数学及其应用 第10、11章 图论 - 图98 and 离散数学及其应用 第10、11章 图论 - 图99 such that every edge connects a vertex in 离散数学及其应用 第10、11章 图论 - 图100 and a vertex in 离散数学及其应用 第10、11章 图论 - 图101. The pair 离散数学及其应用 第10、11章 图论 - 图102 is called a **bipartition** of the vertex 离散数学及其应用 第10、11章 图论 - 图103 of 离散数学及其应用 第10、11章 图论 - 图104. The **complete bipartite graph** is the simple graph that has its vertex set partitioned into two subsets 离散数学及其应用 第10、11章 图论 - 图105 and 离散数学及其应用 第10、11章 图论 - 图106 with 离散数学及其应用 第10、11章 图论 - 图107 and 离散数学及其应用 第10、11章 图论 - 图108 vertices, respectively, and every vertex in 离散数学及其应用 第10、11章 图论 - 图109 is connected to every vertex in 离散数学及其应用 第10、11章 图论 - 图110, denoted by 离散数学及其应用 第10、11章 图论 - 图111, where 离散数学及其应用 第10、11章 图论 - 图112 and 离散数学及其应用 第10、11章 图论 - 图113.
📋 A simple graph is bipartite if and only if it is possible to assign one of two different colors to each vertex of the graph so that no two adjacent vertices are assigned the same color.
💡 如果简单图中存在一个由奇数个结点构成的回路,那么这个简单图不是偶图,因为必然会有两个相邻的结点被涂成相同的颜色。→ 奇数个齿轮啮合成一圈形成的结构不能转动,因为必然会有两个相邻的齿轮需要同向转动。
🌰
image.png
image.png
A simply graph is called **regular** if every vertex of this graph has the same degree. A regular graph is called **n-regular** if every vertex in this graph has degree 离散数学及其应用 第10、11章 图论 - 图116.
🌰 e.g.
离散数学及其应用 第10、11章 图论 - 图117 is a (n-1)-regular.
⚙️ Special types of graphs can be used to represent local area networks.
image.png
离散数学及其应用 第10、11章 图论 - 图119, 离散数学及其应用 第10、11章 图论 - 图120. 离散数学及其应用 第10、11章 图论 - 图121 is a **subgraph** of 离散数学及其应用 第10、11章 图论 - 图122 if 离散数学及其应用 第10、11章 图论 - 图123 and 离散数学及其应用 第10、11章 图论 - 图124. Subgraph 离散数学及其应用 第10、11章 图论 - 图125 is a **proper subgraph** of 离散数学及其应用 第10、11章 图论 - 图126 if 离散数学及其应用 第10、11章 图论 - 图127. 离散数学及其应用 第10、11章 图论 - 图128 is a **spanning subgraph** of 离散数学及其应用 第10、11章 图论 - 图129 if 离散数学及其应用 第10、11章 图论 - 图130, 离散数学及其应用 第10、11章 图论 - 图131.
🌰 e.g.
How many subgraphs with at least one vertex does 离散数学及其应用 第10、11章 图论 - 图132 have?
Solution:
Choose 1 to 4 vertices from the wheel each time, and decide whether there are vertices between each pair of the vertices. 离散数学及其应用 第10、11章 图论 - 图133.
⚠️ Note that here each vertex is considered to be different from others.
Let 离散数学及其应用 第10、11章 图论 - 图134 be a simple graph. The subgraph **induced** by a subset 离散数学及其应用 第10、11章 图论 - 图135 of the vertex set 离散数学及其应用 第10、11章 图论 - 图136 is the graph 离散数学及其应用 第10、11章 图论 - 图137, where the edge set 离散数学及其应用 第10、11章 图论 - 图138 contains an edge in 离散数学及其应用 第10、11章 图论 - 图139 iff both endpoints of this edge are in 离散数学及其应用 第10、11章 图论 - 图140.
📋 Graph Operation

  • Removing edges of a graph: 离散数学及其应用 第10、11章 图论 - 图141
  • Adding edges to a graph: 离散数学及其应用 第10、11章 图论 - 图142
  • **Edge contration**(边收缩): Remove an edge 离散数学及其应用 第10、11章 图论 - 图143 with endpoints 离散数学及其应用 第10、11章 图论 - 图144 and 离散数学及其应用 第10、11章 图论 - 图145, merge 离散数学及其应用 第10、11章 图论 - 图146 and 离散数学及其应用 第10、11章 图论 - 图147 into a new single vertex 离散数学及其应用 第10、11章 图论 - 图148, and for each edge with 离散数学及其应用 第10、11章 图论 - 图149 or 离散数学及其应用 第10、11章 图论 - 图150 as an endpoint, replace the edge with one with 离散数学及其应用 第10、11章 图论 - 图151 as endpoint in place of 离散数学及其应用 第10、11章 图论 - 图152 and 离散数学及其应用 第10、11章 图论 - 图153 and with the same second endpoint.

image.png离散数学及其应用 第10、11章 图论 - 图155image.png

  • Removing vertices from a graph: 离散数学及其应用 第10、11章 图论 - 图157, where 离散数学及其应用 第10、11章 图论 - 图158 is the set of edges of 离散数学及其应用 第10、11章 图论 - 图159 not incident to 离散数学及其应用 第10、11章 图论 - 图160.
  • The **union** of two simple graphs 离散数学及其应用 第10、11章 图论 - 图161 and 离散数学及其应用 第10、11章 图论 - 图162 is the simple graph with vertex set 离散数学及其应用 第10、11章 图论 - 图163 and edge set 离散数学及其应用 第10、11章 图论 - 图164 , denoted as 离散数学及其应用 第10、11章 图论 - 图165.

image.png离散数学及其应用 第10、11章 图论 - 图167image.png离散数学及其应用 第10、11章 图论 - 图169image.png

10.3 Representing Graphs and Graph Isomorphism

10.3.1 Adjacency Lists

**Adjacency lists**(邻接表) are lists that specify the vertices that are adjacent to each vertex.
For simple graphs:

image.png Vertices Adjacent Vertices
a b, c, d
b a, d
c a, d
d a, b, c

For digraphs:

image.png Initial Vertex Terminal Vertices
a c
b a
c
d a, b, c

10.3.2 Adjacency Matrices

A simple graph 离散数学及其应用 第10、11章 图论 - 图173 with 离散数学及其应用 第10、11章 图论 - 图174 vertices 离散数学及其应用 第10、11章 图论 - 图175 can be represented by its **adjacency matrix**(邻接矩阵), 离散数学及其应用 第10、11章 图论 - 图176, where 离散数学及其应用 第10、11章 图论 - 图177.
⚠️ Note that an adjacency matrix of a graph is based on the ordering chosen for the vertices.

image.png Adjacency Matrix

a b c d
a 离散数学及其应用 第10、11章 图论 - 图179
b
c
d

To represent a multigraph or pseudograph using adjacency matrixes, just let the 离散数学及其应用 第10、11章 图论 - 图180-th entry of such a matrix equals the number of edges that are associated to 离散数学及其应用 第10、11章 图论 - 图181.
⚠️ Note that a loop only contribute 1 to the corresponding entry.

image.png Adjacency Matrix

a b c d
a 离散数学及其应用 第10、11章 图论 - 图183
b
c
d

📋 Adjacency matrices of undirected graphs are always symmetric.
For directed graph 离散数学及其应用 第10、11章 图论 - 图184 with 离散数学及其应用 第10、11章 图论 - 图185, suppose that the vertices of 离散数学及其应用 第10、11章 图论 - 图186 are listed in arbitrary order as 离散数学及其应用 第10、11章 图论 - 图187, the adjacency matrix 离散数学及其应用 第10、11章 图论 - 图188, where 离散数学及其应用 第10、11章 图论 - 图189.

image.png Adjacency Matrix

a b c d
a 离散数学及其应用 第10、11章 图论 - 图191
b
c
d

📋 The sum of the entries in a row / column of the adjacency matrix for an undirected graph is the number of edges incident to the vertex 离散数学及其应用 第10、11章 图论 - 图192, which is the same as 离散数学及其应用 第10、11章 图论 - 图193 minus the number of loops at 离散数学及其应用 第10、11章 图论 - 图194.
📋 The sum of the entries in a row of the adjacency matrix for an digraph is 离散数学及其应用 第10、11章 图论 - 图195. In a column it is 离散数学及其应用 第10、11章 图论 - 图196.
💡 计算机中,考虑到占用空间大小,邻接表比较适合表示稀疏矩阵,而邻接矩阵比较适合表示稠密矩阵。

10.3.3 Incidence Matrices

离散数学及其应用 第10、11章 图论 - 图197, 离散数学及其应用 第10、11章 图论 - 图198, 离散数学及其应用 第10、11章 图论 - 图199. Then the **incidence matrix** with respect to this ordering of 离散数学及其应用 第10、11章 图论 - 图200 and 离散数学及其应用 第10、11章 图论 - 图201 is 离散数学及其应用 第10、11章 图论 - 图202 matrix 离散数学及其应用 第10、11章 图论 - 图203, where 离散数学及其应用 第10、11章 图论 - 图204.

image.png Incidence Matrix

1 2 3 4 5 6
a 离散数学及其应用 第10、11章 图论 - 图206
b
c
d

📋 Incidence matrices of undirected graphs contain two 1s per column for edges connecting two vertices, and one 1 per column for loops.

10.3.4 Isomorphism of Graphs

Two simple graphs 离散数学及其应用 第10、11章 图论 - 图207 and 离散数学及其应用 第10、11章 图论 - 图208 are **isomorphic**(同构) if there is a one-to-one correspondence function 离散数学及其应用 第10、11章 图论 - 图209 (离散数学及其应用 第10、11章 图论 - 图210 is called an **isomorphism**) from 离散数学及其应用 第10、11章 图论 - 图211 to 离散数学及其应用 第10、11章 图论 - 图212 such that for all 离散数学及其应用 第10、11章 图论 - 图213 and 离散数学及其应用 第10、11章 图论 - 图214 in 离散数学及其应用 第10、11章 图论 - 图215, 离散数学及其应用 第10、11章 图论 - 图216 and 离散数学及其应用 第10、11章 图论 - 图217 are adjacent in 离散数学及其应用 第10、11章 图论 - 图218 iff 离散数学及其应用 第10、11章 图论 - 图219 and 离散数学及其应用 第10、11章 图论 - 图220 are adjacent in 离散数学及其应用 第10、11章 图论 - 图221.
In other words, when two simple graphs are isomorphic, there is a one-to-one correspondence between vertices of the two graphs that preserves the adjacency relationship.
🌰 e.g.
Show that the following two graphs are isomorphic.
image.png
Proof:

  1. Try to find an isomorphism 离散数学及其应用 第10、11章 图论 - 图223.
  2. Show that 离散数学及其应用 第10、11章 图论 - 图224 preserves adjacency relation- The adjacency matrix of a graph 离散数学及其应用 第10、11章 图论 - 图225 is the same as the adjacency matrix of another graph 离散数学及其应用 第10、11章 图论 - 图226, when rows and columns are labeled to correspond to the images under 离散数学及其应用 第10、11章 图论 - 图227 of the vertices in 离散数学及其应用 第10、11章 图论 - 图228.

Here 离散数学及其应用 第10、11章 图论 - 图229 and 离散数学及其应用 第10、11章 图论 - 图230 are the same. So 离散数学及其应用 第10、11章 图论 - 图231 where 离散数学及其应用 第10、11章 图论 - 图232, 离散数学及其应用 第10、11章 图论 - 图233, 离散数学及其应用 第10、11章 图论 - 图234, 离散数学及其应用 第10、11章 图论 - 图235, 离散数学及其应用 第10、11章 图论 - 图236 is a proper isomorphism.
It is usually difficult to find an isomorphism 离散数学及其应用 第10、11章 图论 - 图237 since there are 离散数学及其应用 第10、11章 图论 - 图238 possible 1-1 correspondence between the two vertex sets with 离散数学及其应用 第10、11章 图论 - 图239 vertices.
However, there are some properties called **invariants**(不变量) in the graphs that may be used to show that they are not isomorphic. Graph invariants are properties preserved by isomorphism of graphs.
📋 Important Invariants in Isomorphic Graphs:

  • the number of vertices
  • the number of edges
  • the degrees of corresponding vertices
  • if one is bipartite, the other must be.
  • if one is complete, the other must be.
  • if one is a wheel, the other must be.

etc.
🌰 e.g.
Draw all nonisomorphic undirected simple graph with four vertices and three edges.
Solution:
By the handshaking theorem, the sum of the degrees over four vertices is 6. The maximal degree is 3, and the number of vertices with odd degrees must even. So there are 3 possible sequence of degrees:
(1) 1, 1, 2, 2; (2) 1, 1, 1, 3; (3) 0, 2, 2, 2.
image.png

10.4 Connectivity

10.4.1 Paths

A **path** of **length** 离散数学及其应用 第10、11章 图论 - 图241 from 离散数学及其应用 第10、11章 图论 - 图242 to 离散数学及其应用 第10、11章 图论 - 图243 in an undirected graph is a sequence of 离散数学及其应用 第10、11章 图论 - 图244 edges 离散数学及其应用 第10、11章 图论 - 图245 for which there exists a sequence 离散数学及其应用 第10、11章 图论 - 图246 such that 离散数学及其应用 第10、11章 图论 - 图247 has endpoints 离散数学及其应用 第10、11章 图论 - 图248. When the graph is simple, we denote this path by its vertex sequence 离散数学及其应用 第10、11章 图论 - 图249. If the path begins and ends with the same vertex, we call it a **circuit**. The path or circuit is said to **pass through** the vertices 离散数学及其应用 第10、11章 图论 - 图250 or **traverse** the edges 离散数学及其应用 第10、11章 图论 - 图251. If a path or a circuit does not contain the same edge more than once, we call it a **simple** path / circuit.
A **path** of length 离散数学及其应用 第10、11章 图论 - 图252 from 离散数学及其应用 第10、11章 图论 - 图253 to 离散数学及其应用 第10、11章 图论 - 图254 in a directed graph is a sequence of edges 离散数学及其应用 第10、11章 图论 - 图255 such that 离散数学及其应用 第10、11章 图论 - 图256 is associated with 离散数学及其应用 第10、11章 图论 - 图257, … , 离散数学及其应用 第10、11章 图论 - 图258 is associated with 离散数学及其应用 第10、11章 图论 - 图259, … , 离散数学及其应用 第10、11章 图论 - 图260 is associated with 离散数学及其应用 第10、11章 图论 - 图261. When there are no multiple edges in the directed graph, this path is denote by its vertex sequence 离散数学及其应用 第10、11章 图论 - 图262. The definitions of circuit and simple path / circuit still holds in directed graphs.
An undirected graph is **connected** if there is a path between every pair of distinct vertices, and is **disconnected** if the graph is not connected. To **disconnect** a graph means to remove vertices or edges, or both, to produce a disconnected subgraph.
⚠️离散数学及其应用 第10、11章 图论 - 图263 is considered to be connected.
📋 There is a simple path between every pair of distinct vertices of a connected undirected graph.
Proof:
Since the graph is connected, there is a path between 离散数学及其应用 第10、11章 图论 - 图264 and 离散数学及其应用 第10、11章 图论 - 图265. Throw out all redundant circuits to make the path simple.
The maximally connected subgraphs of 离散数学及其应用 第10、11章 图论 - 图266 are called the **connected components** or simply “components”.
image.png
If removing a vertex and all edges incident with it results in more connected components than in the original graph, then it is called a **cut vertex** or an **articulation point**. If removing a edge creates more components, then it is called a **cut edge** or a **bridge**. Connected graphs without cut vertices are called **nonseparable graphs**.
Nonseparable graphs can be thought of as more connected than those with a cut vertex. We can measure graph connectivity based on the minimum number of vertices removed to disconnect a graph.

10.4.2 Connectivities in Undirected Graphs

Here 离散数学及其应用 第10、11章 图论 - 图268 is a undirected graph.
A **vertex cut**, or **separating set**, is a subset 离散数学及其应用 第10、11章 图论 - 图269 of the vertex set 离散数学及其应用 第10、11章 图论 - 图270 of 离散数学及其应用 第10、11章 图论 - 图271 such that 离散数学及其应用 第10、11章 图论 - 图272 is disconnected or 离散数学及其应用 第10、11章 图论 - 图273.
📋 Every connected graph except a complete graph has a vertex cut.
The **vertex connectivity**(点连通度) of 离散数学及其应用 第10、11章 图论 - 图274, denote as 离散数学及其应用 第10、11章 图论 - 图275, is the minimum number of vertices in a vertex cut, or equivalently, the minimum number of vertices that can be removed from 离散数学及其应用 第10、11章 图论 - 图276 to either disconnect 离散数学及其应用 第10、11章 图论 - 图277 or produce a graph with a single vertex. The larger 离散数学及其应用 第10、11章 图论 - 图278 is, the more connected we consider 离散数学及其应用 第10、11章 图论 - 图279 to be. A graph is said to be **k-connected** (or k-vertex-connected ), if 离散数学及其应用 第10、11章 图论 - 图280.

离散数学及其应用 第10、11章 图论 - 图281 is the 10th letter in Greek alphabet, called “kappa”.

📋 Properties of Vertex Connectivities

  • If 离散数学及其应用 第10、11章 图论 - 图282 has 离散数学及其应用 第10、11章 图论 - 图283 vertices, then 离散数学及其应用 第10、11章 图论 - 图284.
    • 离散数学及其应用 第10、11章 图论 - 图285 iff 离散数学及其应用 第10、11章 图论 - 图286 is disconnected or 离散数学及其应用 第10、11章 图论 - 图287.
    • 离散数学及其应用 第10、11章 图论 - 图288 if 离散数学及其应用 第10、11章 图论 - 图289 is connected with cut vertices or 离散数学及其应用 第10、11章 图论 - 图290.
    • 离散数学及其应用 第10、11章 图论 - 图291 iff 离散数学及其应用 第10、11章 图论 - 图292.

We can also measure graph connectivity based on the minimum number of edges removed to disconnect a graph.
A set of edges 离散数学及其应用 第10、11章 图论 - 图293 is called an **edge cut** of 离散数学及其应用 第10、11章 图论 - 图294 if the subgraph 离散数学及其应用 第10、11章 图论 - 图295 is disconnected.
The **edge connectivity**(边连通度) of 离散数学及其应用 第10、11章 图论 - 图296, denoted as 离散数学及其应用 第10、11章 图论 - 图297, is the minimum number of edges in an edge cut of 离散数学及其应用 第10、11章 图论 - 图298, or equivalently, the minimum number of edges removed from 离散数学及其应用 第10、11章 图论 - 图299 to disconnect 离散数学及其应用 第10、11章 图论 - 图300.
📋 Properties of Edge Connectivities

  • If G has n vertices, then 离散数学及其应用 第10、11章 图论 - 图301.
    • 离散数学及其应用 第10、11章 图论 - 图302 if 离散数学及其应用 第10、11章 图论 - 图303 is disconnected or 离散数学及其应用 第10、11章 图论 - 图304.
    • 离散数学及其应用 第10、11章 图论 - 图305 iff 离散数学及其应用 第10、11章 图论 - 图306.

📋 Whitney’s Inequality(惠特尼不等式)
When 离散数学及其应用 第10、11章 图论 - 图307 is a noncomplete connected graph with at least three vertices, 离散数学及其应用 第10、11章 图论 - 图308.
💡 去掉结点的时候会把连接到这个点的边一起去掉。去点的同时也在去边,所以去点对连通度的影响比单纯去边的影响大,所以点连通度比边连通度小。不需要会证,记得有这么个结论就行。
⚙️ Vertex and edge connectivity can be used to analysis the reliability of network. The vertex connectivity of the graph representing network equals the minimum number of routers that disconnect the network when they are out of service. The edge connectivity represents the minimum number of fiber optic links that can be down to disconnect the network.

10.4.3 Connectivities in Digraphs

Here 离散数学及其应用 第10、11章 图论 - 图309 is a digraph.
离散数学及其应用 第10、11章 图论 - 图310 is said to be **strongly connected** if there is a path from 离散数学及其应用 第10、11章 图论 - 图311 to 离散数学及其应用 第10、11章 图论 - 图312 and from 离散数学及其应用 第10、11章 图论 - 图313 to 离散数学及其应用 第10、11章 图论 - 图314 for all vertices 离散数学及其应用 第10、11章 图论 - 图315 and 离散数学及其应用 第10、11章 图论 - 图316. If the underlying undirected graph is connected, then we say it is **weakly connected**.
⚠️ By the definition, any strongly connected directed graph is also weakly connected.
For directed graph, the maximal strongly connected subgraphs are called the **strongly connected components** or just the **strong components**.
🌰 e.g.
image.png
There are 3 strong components in this digraph:

  1. 离散数学及其应用 第10、11章 图论 - 图318.
  2. 离散数学及其应用 第10、11章 图论 - 图319.
  3. The subgraph consisting of vertices 离散数学及其应用 第10、11章 图论 - 图320, 离散数学及其应用 第10、11章 图论 - 图321, and 离散数学及其应用 第10、11章 图论 - 图322 and edges 离散数学及其应用 第10、11章 图论 - 图323, 离散数学及其应用 第10、11章 图论 - 图324, 离散数学及其应用 第10、11章 图论 - 图325.

💡 定义可达性矩阵:离散数学及其应用 第10、11章 图论 - 图326,其中离散数学及其应用 第10、11章 图论 - 图327为 1 表示存在一条从结点 i 到 j 的路径,为 0 表示不存在。那么离散数学及其应用 第10、11章 图论 - 图328就是原有向图的邻接矩阵的传递闭包。

10.4.4 Applications of Paths

📋 Two graphs are isomorphic only if they have simple circuits of the same length.
📋 Two graphs are isomorphic only if they contain paths that go through vertices so that the corresponding vertices in the two graphs have the same degree.
🌰 e.g.
image.png
Are these two graphs isomorphic?
Solution:
They are not, because the right graph contains circuits of length 3, while the left graph does not.
📋 The number of different paths of length 离散数学及其应用 第10、11章 图论 - 图330 from 离散数学及其应用 第10、11章 图论 - 图331 to 离散数学及其应用 第10、11章 图论 - 图332 is equal to the 离散数学及其应用 第10、11章 图论 - 图333th entry of 离散数学及其应用 第10、11章 图论 - 图334(the standard power of 离散数学及其应用 第10、11章 图论 - 图335, not the Boolean product), where 离散数学及其应用 第10、11章 图论 - 图336 is the adjacency matrix representing the graph consisting of vertices 离散数学及其应用 第10、11章 图论 - 图337.
Proof:
The proof is based on MI. Let 离散数学及其应用 第10、11章 图论 - 图338.
Basic Step: 离散数学及其应用 第10、11章 图论 - 图339.
Inducive Case: Assuming that the 离散数学及其应用 第10、11章 图论 - 图340th entry of 离散数学及其应用 第10、11章 图论 - 图341 is the number of different paths of length 离散数学及其应用 第10、11章 图论 - 图342 from 离散数学及其应用 第10、11章 图论 - 图343 to 离散数学及其应用 第10、11章 图论 - 图344. Then for 离散数学及其应用 第10、11章 图论 - 图345, let 离散数学及其应用 第10、11章 图论 - 图346, then 离散数学及其应用 第10、11章 图论 - 图347, where 离散数学及其应用 第10、11章 图论 - 图348 is the number of paths of length 离散数学及其应用 第10、11章 图论 - 图349 passing the vertex 离散数学及其应用 第10、11章 图论 - 图350.
🌰 e.g.
image.png

  1. How many paths of length 2 are there from 离散数学及其应用 第10、11章 图论 - 图352 to 离散数学及其应用 第10、11章 图论 - 图353?

    Solution: 离散数学及其应用 第10、11章 图论 - 图354 in 离散数学及其应用 第10、11章 图论 - 图355 is 1.

  2. The number of paths not exceeding 6 are there from 离散数学及其应用 第10、11章 图论 - 图356 to 离散数学及其应用 第10、11章 图论 - 图357?

    Solution: 离散数学及其应用 第10、11章 图论 - 图358 in 离散数学及其应用 第10、11章 图论 - 图359 is 2.

  3. The number of circuits starting at vertex 离散数学及其应用 第10、11章 图论 - 图360 whose length is not exceeding 6?

    Solution: 离散数学及其应用 第10、11章 图论 - 图361 in 离散数学及其应用 第10、11章 图论 - 图362 is 2.

    10.5 Euler and Hamilton Paths

    10.5.1 Euler Path

    **Euler Path**: A simple path containing every edge of 离散数学及其应用 第10、11章 图论 - 图363. 这里 simple 的意思是同一条边不能走多次,也就是说 Euler path 解决的是一笔画问题。
    **Euler Circuit**: A simple circuit containing every edge of 离散数学及其应用 第10、11章 图论 - 图364.
    **Euler Graph**: A graph contains an Euler circuit.
    📋 Necessary and Sufficient Condition for Euler Circuits and Paths
    A connected multigraph has an Euler circuit ↔ each of its vertices has even degree.
    Proof:
    (1) 离散数学及其应用 第10、11章 图论 - 图365 has an Euler circuit ⇒ Every vertex in 离散数学及其应用 第10、11章 图论 - 图366 has even degree
    Consider the Euler circuit starting and ending at vertex 离散数学及其应用 第10、11章 图论 - 图367:

  • First edge of the Euler circuit contributes one to the degree of 离散数学及其应用 第10、11章 图论 - 图368.
  • Each time the circuit passes through a vertex it contributes two to the vertex’s degree
  • The circuit terminates where it started, contributing one to 离散数学及其应用 第10、11章 图论 - 图369.

(2) Every vertex in 离散数学及其应用 第10、11章 图论 - 图370 has even degree ⇒ We can form a Euler circuit that begins at an arbitrary vertex 离散数学及其应用 第10、11章 图论 - 图371 of 离散数学及其应用 第10、11章 图论 - 图372

  • Build a simple circuit 离散数学及其应用 第10、11章 图论 - 图373.
  • An Euler circuit has been constructed if all the edges have been used. Otherwise:
  • Construct a simple path in the subgraph 离散数学及其应用 第10、11章 图论 - 图374 obtained from 离散数学及其应用 第10、11章 图论 - 图375. Let 离散数学及其应用 第10、11章 图论 - 图376 be a vertex which is the common vertex of the circuit and 离散数学及其应用 第10、11章 图论 - 图377. Beginning at 离散数学及其应用 第10、11章 图论 - 图378, construct a simple path in 离散数学及其应用 第10、11章 图论 - 图379.
  • Form a circuit in 离散数学及其应用 第10、11章 图论 - 图380 by splicing the circuit in 离散数学及其应用 第10、11章 图论 - 图381 with the original circuit in 离散数学及其应用 第10、11章 图论 - 图382.
  • Continue this process until all edges have been used.
  • (Explained in detail later)

📋 A connected multigraph has an Euler path but not an Euler circuit ↔ It has exactly two vertices of odd degree.
Proof:
(1) Suppose the multigraph has an Euler path from 离散数学及其应用 第10、11章 图论 - 图383 to 离散数学及其应用 第10、11章 图论 - 图384.

  • The first edge of the Euler path contributes one to the degree of 离散数学及其应用 第10、11章 图论 - 图385.
  • The last edge in the Euler path contributes one to the degree of 离散数学及其应用 第10、11章 图论 - 图386.
  • The path contributes two to the degree of a vertex whenever it passes through it.

(2) Suppose that a graph has exactly two vertices of odd degree, say 离散数学及其应用 第10、11章 图论 - 图387 and 离散数学及其应用 第10、11章 图论 - 图388.

  • Add an edge 离散数学及其应用 第10、11章 图论 - 图389, then every vertex has even degree, so there is an Euler circuit.
  • The removal of the new edge produces an Euler path.

🌰 e.g.
Königsberg Seven Bridge Problem:
Is it possible to pass each of the 7 bridges(represented as edges in the graph) exactly once?
image.png
Solution:
The graph has four vertices of odd degree. Therefore, it does not have an Euler circuit. It does not have an Euler path either.
📋 An algorithm to find an Euler path or Euler circuit in a given graph

  1. PROCEDURE Euler (G: connected and all vertices of even degree)
  2. circuit := a circuit in G beginning at an arbitraryily chosen vertex with
  3. edges successively added to form a path that return to this vertex
  4. H := G with the edges of this circuit removed
  5. WHILE H has edges
  6. BEGIN
  7. subcircuit := a circuit in H beginning at a vertex in H that is also an
  8. endpoint of an edge of circuit
  9. H := H with edges of subcircuit and all isolated vertices removed
  10. circuit := circuit with subcircuit inserted at the appropriate vertex
  11. END {circuit is an Euler circuit}

To form an Euler path in a graph without an Euler circuit, we follow the procudure above as well, but start and end at the two vertices of odd degrees.
🌰 e.g.
Determine whether the following graph has an Euler path. Construct such a path if it exists.

1 2 3
image.png image.png image.png
ACEABCDEGJ ACEABCDEGJ+EFGIJE
=ACEFGIJEABCDEGJ
ACEFGIJEABCDEGHIGJ+GHIG
=ACEFGIJEABCDEGHIGJ

Solution:
The graph has exactly 2 vertices of odd degree, and all of the other vertices have even degree. Therefore, this graph has an Euler path.
The concept of Euler cuicuit can be extended to digraphs.
📋 A directed multigraph having no isolated vertices has an Euler circuit if and only if:

  • The graph is weakly connected.
  • The in-degree and out-degree of each vertex are equal.

📋 A directed multigraph having no isolated vertices has an Euler path but not an Euler circuit if and only if:

  • The graph is weakly connected.
  • The in-degree and out-degree of each vertex are equal for all but two vertices, one that has in-degree 1 larger than its out-degree and the other that has out-degree 1 larger than its in-degree.

⚙️ Application of Euler Paths

  • One-Stroke Problem

image.png
Draw a picture in a continuous motion without lifting the pencil so that no part of the picture is retraced. The problem is equivalent to deciding whether there is a Euler path and constructing the path if it exists.
Some route planning problems, where we need to avoid retracing a road, are equivalent to a one-stroke problem.

  • The Chinese Postman Problem (CPP)

中国邮递员问题是邮递员在某一地区的信件投递路程的问题。邮递员每天从邮局出发,走遍该地区所有街道再返回邮局,那么他应如何安排送信的路线可以使所走的总路程最短?这个问题由中国学者管梅谷在1960年首先提出,并给出了解法——“奇偶点图上作业法”。用图论的语言描述,就是给定一个连通图离散数学及其应用 第10、11章 图论 - 图395,每边离散数学及其应用 第10、11章 图论 - 图396有非负权,要求一条回路经过每条边至少一次,且满足总权最小。

10.5.2 Hamilton’s Paths

**Hamilton Path**: A path which visits every vertex in 离散数学及其应用 第10、11章 图论 - 图397 exactly once.
**Hamilton Circuit**: A cycle which visits every vertex exactly once, except for the first vertex, which is also visited at the end of the cycle.
**Hamilton Graph**: A connected graph 离散数学及其应用 第10、11章 图论 - 图398 with a Hamilton circuit
The definitions apply both to undirected as well as directed graphs of all types.
The idea of Hamilton path rose from Hamilton’s puzzle, where we try passing every vertex of a graph without passing any vertex twice.
image.png
Currently, there are no useful necessary and sufficient conditions for the existence of Hamilton circuit. A few sufficient conditions have been found.
📋 Dirac’s Theorem(迪拉克定理)
If 离散数学及其应用 第10、11章 图论 - 图400 is a simple graph with 离散数学及其应用 第10、11章 图论 - 图401 vertices with 离散数学及其应用 第10、11章 图论 - 图402 such that the degree of every vertex in 离散数学及其应用 第10、11章 图论 - 图403 is at least 离散数学及其应用 第10、11章 图论 - 图404, then 离散数学及其应用 第10、11章 图论 - 图405 has a Hamilton path.
📋 Ore’s Theorem(奥尔定理)
If 离散数学及其应用 第10、11章 图论 - 图406 is a simple graph with 离散数学及其应用 第10、11章 图论 - 图407 vertices with 离散数学及其应用 第10、11章 图论 - 图408 such that 离散数学及其应用 第10、11章 图论 - 图409 for every pair of nonadjacent vertices 离散数学及其应用 第10、11章 图论 - 图410 and 离散数学及其应用 第10、11章 图论 - 图411 in 离散数学及其应用 第10、11章 图论 - 图412, then 离散数学及其应用 第10、11章 图论 - 图413 has a Hamilton circuit.
💡 这两个定理的核心理念就是:有足够多的边的图中存在哈密顿道路/回路。
📋 Certain properties can be used to show that a graph has no Hamilton circuit:

  • A graph with a vertex of degree one cannot have a Hamilton circuit.
  • A graph with a cut vertex cannot have a Hamilton circuit.
  • If a vertex in the graph has degree two, then both edges that are incident with this vertex must be part of any Hamilton circuit.
  • When a Hamilton circuit is being constructed and this circuit has passed through a vertex, then all remaining edges incident with this vertex, other than the two used in the circuit , can be removed from consideration.

📋 Another Important Necessary Condition
If there is a Hamilton circuit in 离散数学及其应用 第10、11章 图论 - 图414, for any nonempty subset 离散数学及其应用 第10、11章 图论 - 图415 of set 离散数学及其应用 第10、11章 图论 - 图416, the number of connected components in 离散数学及其应用 第10、11章 图论 - 图417 is less than or equal to 离散数学及其应用 第10、11章 图论 - 图418. 可以这么记:有哈密顿回路说明这个图是连通的,每去掉一个结点就能产生一个新的连通分支已经是最极端的情况了。
🧷 Note:
Suppose that 离散数学及其应用 第10、11章 图论 - 图419 is a H circuit of 离散数学及其应用 第10、11章 图论 - 图420. For any nonempty subset 离散数学及其应用 第10、11章 图论 - 图421 of set 离散数学及其应用 第10、11章 图论 - 图422, the number of connected components in 离散数学及其应用 第10、11章 图论 - 图423 is less than or equal to 离散数学及其应用 第10、11章 图论 - 图424, and the number of connected components in 离散数学及其应用 第10、11章 图论 - 图425 is less than or equal to the number of connected components in 离散数学及其应用 第10、11章 图论 - 图426. 可以这么记:离散数学及其应用 第10、11章 图论 - 图427中可能去掉了一些离散数学及其应用 第10、11章 图论 - 图428中有的边,所以连通性只能比离散数学及其应用 第10、11章 图论 - 图429差,连通分支数量一定不少于离散数学及其应用 第10、11章 图论 - 图430
⚙️ Hamilton path or circuit can be used to solve many practical problems, including the famous TSP (Traveling Salesperson Problem), where the salesperson wants to reach every city exactly once.
🌰 e.g.
Seating Problem: There are seven people denoted by A, B, C, D, E, F, G. Suppose that the following facts are known.

  • A — English (A can speak English.)
  • B — English, Chinese
  • C — English, Italian, Russian
  • D — Japanese, Chinese
  • E — German, Italia
  • F — French, Japanese, Russian
  • G — French, German

    How to arrange seat for the round desk such that the seven people can talk each other?
    Solution:
    image.png image.png

  1. Construct a graph 离散数学及其应用 第10、11章 图论 - 图433, where 离散数学及其应用 第10、11章 图论 - 图434, 离散数学及其应用 第10、11章 图论 - 图435
  2. If there is a H circuit, then we can arrange seat for the round desk such that the seven people can talk each other. The H circuit is 离散数学及其应用 第10、11章 图论 - 图436.

🌰 e.g.
Seven examination must be arranged in a week. Each day has one examination. The examinations are in charged by the same teacher cannot be arranged in the adjacent two days. One teacher is in charge at most four examinations. Show that the arrangement is possible.
Proof:

  1. Construct graph, where 离散数学及其应用 第10、11章 图论 - 图437: seven examination, 离散数学及其应用 第10、11章 图论 - 图438
  2. If there is a Hamilton path, then the arrangement is possible. Since one teacher is in charge at most four examinations, then every vertex in the graph has at least three adjacent vertices. It follows that the sum of the degrees of a pair vertices is at least 6.
  3. According to Ore’s theorem, there is a H circuit connecting 6 of the vertices. By removing an edge and connect an endpoint to the 7th vertex, we get a H path.

    10.6 Shortest Path Problems

    In real life, we usually need to find a path to our destination with the lowest cost, but the graphs we have learned actually regard every edge as the same. So we need to introduce weight into graphs to represent the different cost of passing each edge.

    10.6.1 Basic Concepts

    **Weighted graph**: 离散数学及其应用 第10、11章 图论 - 图439, where 离散数学及其应用 第10、11章 图论 - 图440 is the set of the **weights**(权重) of all edges. The length of a path in a weighted graph is defined as the sum of the weights of the edges of this path.
    image.png
    **Shortest Path Problem**: 离散数学及其应用 第10、11章 图论 - 图442 is a is a weighted graph, where 离散数学及其应用 第10、11章 图论 - 图443 is the weight of edge associated vertices 离散数学及其应用 第10、11章 图论 - 图444 and 离散数学及其应用 第10、11章 图论 - 图445 (if 离散数学及其应用 第10、11章 图论 - 图446, then 离散数学及其应用 第10、11章 图论 - 图447), and 离散数学及其应用 第10、11章 图论 - 图448, find the path with the shortest length between 离散数学及其应用 第10、11章 图论 - 图449 and 离散数学及其应用 第10、11章 图论 - 图450.

    10.6.2 Dijkstra’s Algorithm

    It is a greedy algorithm discovered by the Dutch mathematician E. Dijkstra, to solve the problem in undirected weighted graphs where all the weights are positive. Its main idea is to find the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图451 to a first vertex, then the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图452 to a second vertex, and so on, until the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图453 to 离散数学及其应用 第10、11章 图论 - 图454.
    📋 Dijkstra’s Algorithm
    Let 离散数学及其应用 第10、11章 图论 - 图455 denote the set of vertices after 离散数学及其应用 第10、11章 图论 - 图456 iterations of labeling procedure.

  4. Initialization. Label 离散数学及其应用 第10、11章 图论 - 图457 with 0 and other with 离散数学及其应用 第10、11章 图论 - 图458, i.e. 离散数学及其应用 第10、11章 图论 - 图459, and 离散数学及其应用 第10、11章 图论 - 图460 and 离散数学及其应用 第10、11章 图论 - 图461.

  5. Form 离散数学及其应用 第10、11章 图论 - 图462. The set 离散数学及其应用 第10、11章 图论 - 图463 is formed from 离散数学及其应用 第10、11章 图论 - 图464 by adding a vertex 离散数学及其应用 第10、11章 图论 - 图465 not in 离散数学及其应用 第10、11章 图论 - 图466 with the smallest label.
  6. Update the labels of all vertices not in 离散数学及其应用 第10、11章 图论 - 图467 , so that 离散数学及其应用 第10、11章 图论 - 图468, the label of the vertex 离散数学及其应用 第10、11章 图论 - 图469 at the 离散数学及其应用 第10、11章 图论 - 图470th stage, is the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图471 to 离散数学及其应用 第10、11章 图论 - 图472 that containing vertices only in 离散数学及其应用 第10、11章 图论 - 图473. This shortest path is either the shortest path from 离散数学及其应用 第10、11章 图论 - 图474 to 离散数学及其应用 第10、11章 图论 - 图475 containing only elements of 离散数学及其应用 第10、11章 图论 - 图476 or it is the shortest path from 离散数学及其应用 第10、11章 图论 - 图477 to 离散数学及其应用 第10、11章 图论 - 图478 at the 离散数学及其应用 第10、11章 图论 - 图479st stage with the edge 离散数学及其应用 第10、11章 图论 - 图480 added. That is 离散数学及其应用 第10、11章 图论 - 图481.
  7. Step 2 and 3 is iterated by successively adding vertices to the distinguished set the until 离散数学及其应用 第10、11章 图论 - 图482 is added.
    1. Procedure Dijkstra(G: weighted connected simple graph, with all weights positive)
    2. {G has vertices a = v0, v1 , ··· ,vn = z and weights w(vi ,vj),
    3. where w(vi ,vj)=∞ if {vi ,vj}is not an edge in G}
    4. For i := 1 to n
    5. L(vi) :=
    6. L(a) := 0
    7. S := ø
    8. {the labels are now initialized so that the label of a is zero and all other labels
    9. are ∞,and S is the empty set}
    10. While z S
    11. Begin
    12. u := a vertex not in S with L(u) minimal
    13. S := S∪{u}
    14. for all vertices v not in S
    15. if L(u)+w(u,v) < L(v)
    16. L(v) :=L(u)+w(u,v)
    17. {this adds a vertex to S with minimal label and updates the labels of vertices not in S}
    18. End {L(z)=length of shortest path from a to z }
    🌰 e.g.
    Find the length of the shortest path between 离散数学及其应用 第10、11章 图论 - 图483 and 离散数学及其应用 第10、11章 图论 - 图484 in the given weighted graph.
    image.png
    Solution:
    In performing Dijkstra’s algorithm, it is sometimes more convenient to keep track of labels of vertices using a table. Mark the shortest path found in each iteration with red color.
Vertex Link 离散数学及其应用 第10、11章 图论 - 图486 离散数学及其应用 第10、11章 图论 - 图487 离散数学及其应用 第10、11章 图论 - 图488 离散数学及其应用 第10、11章 图论 - 图489 离散数学及其应用 第10、11章 图论 - 图490 离散数学及其应用 第10、11章 图论 - 图491
a 0
b a→c 4 3
c a 2
d a→c→b 10 8
e a→c→b→d 12 12 10
z a→c→b→d→e 14 13

💡 Such greedy algorithm can also be applied to digraphs.
📋 The Correctness of Dijkstra’s Algorithm
Dijkstra’s algorithm finds the length of a shortest path between two vertices in a connected simple undirected weighted graph.
Proof:
We use an inductive argument. Take as the induction hypothesis the following assertion: At the 离散数学及其应用 第10、11章 图论 - 图492th iteration, ① the label of every vertex 离散数学及其应用 第10、11章 图论 - 图493 in 离散数学及其应用 第10、11章 图论 - 图494 is the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图495 to this vertex, and ② the label of every vertex not in 离散数学及其应用 第10、11章 图论 - 图496 is the length of the shortest path from a to this vertex that contains only vertices in 离散数学及其应用 第10、11章 图论 - 图497.

  1. When 离散数学及其应用 第10、11章 图论 - 图498, 离散数学及其应用 第10、11章 图论 - 图499, 离散数学及其应用 第10、11章 图论 - 图500, 离散数学及其应用 第10、11章 图论 - 图501.
  2. Assume that the inductive hypothesis holds for the 离散数学及其应用 第10、11章 图论 - 图502th iteration. Let 离散数学及其应用 第10、11章 图论 - 图503 be the vertex added to 离散数学及其应用 第10、11章 图论 - 图504 at the 离散数学及其应用 第10、11章 图论 - 图505st iteration so that 离散数学及其应用 第10、11章 图论 - 图506 is a vertex not in 离散数学及其应用 第10、11章 图论 - 图507 at the end of the 离散数学及其应用 第10、11章 图论 - 图508th iteration with the smallest label.
    1. ① still holds holds at the end of the 离散数学及其应用 第10、11章 图论 - 图509st iteration. The vertices in 离散数学及其应用 第10、11章 图论 - 图510 before the 离散数学及其应用 第10、11章 图论 - 图511st iteration are labeled with the length of the shortest path from 离散数学及其应用 第10、11章 图论 - 图512, and 离散数学及其应用 第10、11章 图论 - 图513 must be labeled with the length of the shortest path to it from 离散数学及其应用 第10、11章 图论 - 图514.
    2. Let 离散数学及其应用 第10、11章 图论 - 图515 be a vertex not in 离散数学及其应用 第10、11章 图论 - 图516 after 离散数学及其应用 第10、11章 图论 - 图517 iteration. A shortest path from 离散数学及其应用 第10、11章 图论 - 图518 to 离散数学及其应用 第10、11章 图论 - 图519 containing only elements of 离散数学及其应用 第10、11章 图论 - 图520 either contains 离散数学及其应用 第10、11章 图论 - 图521 or it does not. If it does not contain 离散数学及其应用 第10、11章 图论 - 图522, then by the inductive hypothesis its length is 离散数学及其应用 第10、11章 图论 - 图523. If it does contain 离散数学及其应用 第10、11章 图论 - 图524, then it must be made up of a path from 离散数学及其应用 第10、11章 图论 - 图525 to 离散数学及其应用 第10、11章 图论 - 图526 of the shortest possible length containing elements of 离散数学及其应用 第10、11章 图论 - 图527 other than 离散数学及其应用 第10、11章 图论 - 图528, followed by the edge from 离散数学及其应用 第10、11章 图论 - 图529 to 离散数学及其应用 第10、11章 图论 - 图530. In this case its length would be 离散数学及其应用 第10、11章 图论 - 图531. This shows that ② is true, because 离散数学及其应用 第10、11章 图论 - 图532.

📋 The Computational Complexity of Dijkstra’s Algorithm
Dijkstra’s algorithm uses 离散数学及其应用 第10、11章 图论 - 图533 operations (additions and comparisons) to find the length of the shortest path between two vertices in a connected simple undirected weighted graph.
Proof:
The Dijkstra’s algorithm uses no more than 离散数学及其应用 第10、11章 图论 - 图534 iterations. In each iteration, it uses no more than 离散数学及其应用 第10、11章 图论 - 图535 comparisons to determine the vertex not in 离散数学及其应用 第10、11章 图论 - 图536 with the smallest label, and no more than 离散数学及其应用 第10、11章 图论 - 图537 operations are used to update no more than 离散数学及其应用 第10、11章 图论 - 图538 labels.

10.6.3 The Traveling Salesperson Problem (TSP)

A traveling salesperson wants to visit each of 离散数学及其应用 第10、11章 图论 - 图539 cities exactly once and return to his starting point with minimum total cost. The equivalent problem for TSP is to find a Hamilton circuit with minimum total weight in the weighted complete undirected graph.
The most straightforward method to solve TSP is to examine all possible Hamilton circuits and select one of minimum total length. There are 离散数学及其应用 第10、11章 图论 - 图540 H circuits in a complete graph with 离散数学及其应用 第10、11章 图论 - 图541 vertices, so the complexity of this algorithm grows extremely rapidly. So we usually use approximation algorithms that do not necessarily produce the exact solution, to produce a solution that is close to an exact solution of TSP.

10.7 Planar Graphs

10.7.1 Basic Concepts

A graph is called **planar** if it can be drawn in the plane without any edges crossing. Such a drawing is called a **planar representation** of the graph. We can prove that a graph is planar by displaying a planar representation.
⚠️ A graph may be planar even if it is usually drawn with crossings. For example, 离散数学及其应用 第10、11章 图论 - 图542 and 离散数学及其应用 第10、11章 图论 - 图543 are actually planar.
image.png
🌰 e.g.
Complete bipartite graphs 离散数学及其应用 第10、11章 图论 - 图545 and 离散数学及其应用 第10、11章 图论 - 图546 are planar.
⚙️ Planarity of graphs plays an important role in the design of electronic circuits and the design of road networks.
A part of the plane completely disconnected off from other parts of the plane by the edges of the graph is called a **region**. The edges that disconnect a region from other parts is called the **boundary** of the region. If the region has a finite area among several edges, then it is called a **bounded** region, and otherwise it is called an **unbounded** region.
Suppose 离散数学及其应用 第10、11章 图论 - 图547 is a region of a connected planar simple graph, the number of the edges which surround 离散数学及其应用 第10、11章 图论 - 图548, is called the **degree** of region 离散数学及其应用 第10、11章 图论 - 图549, denoted as 离散数学及其应用 第10、11章 图论 - 图550. Two regions with a common border are called **adjacent regions**.
🌰 e.g.
The following is a planar representation of a graph.
image.png
There are 5 regions. The boundaries of regions 离散数学及其应用 第10、11章 图论 - 图552, 离散数学及其应用 第10、11章 图论 - 图553, 离散数学及其应用 第10、11章 图论 - 图554 and 离散数学及其应用 第10、11章 图论 - 图555 are 离散数学及其应用 第10、11章 图论 - 图556, 离散数学及其应用 第10、11章 图论 - 图557, 离散数学及其应用 第10、11章 图论 - 图558, 离散数学及其应用 第10、11章 图论 - 图559. So 离散数学及其应用 第10、11章 图论 - 图560, 离散数学及其应用 第10、11章 图论 - 图561, 离散数学及其应用 第10、11章 图论 - 图562, 离散数学及其应用 第10、11章 图论 - 图563. The boundary of unbounded region 离散数学及其应用 第10、11章 图论 - 图564 is constructed by 离散数学及其应用 第10、11章 图论 - 图565 and 离散数学及其应用 第10、11章 图论 - 图566, so 离散数学及其应用 第10、11章 图论 - 图567.
⚠️ Note that 离散数学及其应用 第10、11章 图论 - 图568 is counted twice.
📋 If 离散数学及其应用 第10、11章 图论 - 图569 is not a cut edge, then it must be the common border of two regions.
分析:如果离散数学及其应用 第10、11章 图论 - 图570不是割边,那么一定存在一条包含了离散数学及其应用 第10、11章 图论 - 图571的回路,这条回路里面包着至少一个区域,而离散数学及其应用 第10、11章 图论 - 图572的两边分别是环路里外,必定分属不同的区域。感谢@Isshiki修(isshikixiu)的指导!
📋 The sum of the degrees of all regions is exactly twice the number of edges in the planar graph. That is 离散数学及其应用 第10、11章 图论 - 图573.
🌰 e.g.
Show that 离散数学及其应用 第10、11章 图论 - 图574 is not planar.
image.png
Proof:
In any planar representation of 离散数学及其应用 第10、11章 图论 - 图576, the vertices 离散数学及其应用 第10、11章 图论 - 图577 and 离散数学及其应用 第10、11章 图论 - 图578 must be connected to both 离散数学及其应用 第10、11章 图论 - 图579 and 离散数学及其应用 第10、11章 图论 - 图580. These four edges form a closed curve that splits the plane into two regions, 离散数学及其应用 第10、11章 图论 - 图581 and 离散数学及其应用 第10、11章 图论 - 图582. The vertex 离散数学及其应用 第10、11章 图论 - 图583 is in either 离散数学及其应用 第10、11章 图论 - 图584 or 离散数学及其应用 第10、11章 图论 - 图585.
image.png
When 离散数学及其应用 第10、11章 图论 - 图587 is in 离散数学及其应用 第10、11章 图论 - 图588, the inside of the closed curve, the edges between 离散数学及其应用 第10、11章 图论 - 图589 and 离散数学及其应用 第10、11章 图论 - 图590 and between 离散数学及其应用 第10、11章 图论 - 图591 and 离散数学及其应用 第10、11章 图论 - 图592 separate 离散数学及其应用 第10、11章 图论 - 图593 into two subregions, 离散数学及其应用 第10、11章 图论 - 图594 and 离散数学及其应用 第10、11章 图论 - 图595. There is no way to place the final vertex 离散数学及其应用 第10、11章 图论 - 图596 without forcing a crossing.
image.png
For if 离散数学及其应用 第10、11章 图论 - 图598 is in 离散数学及其应用 第10、11章 图论 - 图599, then the edge between 离散数学及其应用 第10、11章 图论 - 图600 and 离散数学及其应用 第10、11章 图论 - 图601 cannot be drawn without a crossing. If 离散数学及其应用 第10、11章 图论 - 图602 is in 离散数学及其应用 第10、11章 图论 - 图603, then the edge between 离散数学及其应用 第10、11章 图论 - 图604 and 离散数学及其应用 第10、11章 图论 - 图605 cannot be drawn without a crossing. If 离散数学及其应用 第10、11章 图论 - 图606 is in 离散数学及其应用 第10、11章 图论 - 图607, then the edge between 离散数学及其应用 第10、11章 图论 - 图608 and 离散数学及其应用 第10、11章 图论 - 图609 cannot be drawn without a crossing. And a similar argument can be used when 离散数学及其应用 第10、11章 图论 - 图610 is in 离散数学及其应用 第10、11章 图论 - 图611.

10.7.2 Euler’s Formula

📋 Euler’s formula
Let 离散数学及其应用 第10、11章 图论 - 图612 be a connected planar simple graph with 离散数学及其应用 第10、11章 图论 - 图613 edges and 离散数学及其应用 第10、11章 图论 - 图614 vertices. Let 离散数学及其应用 第10、11章 图论 - 图615 be the number of regions in a planar representation of 离散数学及其应用 第10、11章 图论 - 图616. Then 离散数学及其应用 第10、11章 图论 - 图617.
Proof:
First, we specify a planar representation of 离散数学及其应用 第10、11章 图论 - 图618. We will prove the theorem by constructing a sequence of subgraphs 离散数学及其应用 第10、11章 图论 - 图619, successively adding an edge at each stage.
The constructing method: Arbitrarily pick one edge of 离散数学及其应用 第10、11章 图论 - 图620 to obtain 离散数学及其应用 第10、11章 图论 - 图621. Obtain 离散数学及其应用 第10、11章 图论 - 图622 from 离散数学及其应用 第10、11章 图论 - 图623 by arbitrarily adding an edge that is incident with a vertex already in 离散数学及其应用 第10、11章 图论 - 图624. Let 离散数学及其应用 第10、11章 图论 - 图625, 离散数学及其应用 第10、11章 图论 - 图626, and 离散数学及其应用 第10、11章 图论 - 图627 represent the number of regions, edges, and vertices of the planar representation of 离散数学及其应用 第10、11章 图论 - 图628 induced by the planar representation of 离散数学及其应用 第10、11章 图论 - 图629, respectively.
The relationship 离散数学及其应用 第10、11章 图论 - 图630 is true, since 离散数学及其应用 第10、11章 图论 - 图631, 离散数学及其应用 第10、11章 图论 - 图632,and 离散数学及其应用 第10、11章 图论 - 图633. Now assume that 离散数学及其应用 第10、11章 图论 - 图634. Let 离散数学及其应用 第10、11章 图论 - 图635 be the edge that is added to 离散数学及其应用 第10、11章 图论 - 图636 to obtain 离散数学及其应用 第10、11章 图论 - 图637.
If both 离散数学及其应用 第10、11章 图论 - 图638 and 离散数学及其应用 第10、11章 图论 - 图639 are already in 离散数学及其应用 第10、11章 图论 - 图640, then these two vertices must be on the boundary of a common region R, or else it would be impossible to add the edge 离散数学及其应用 第10、11章 图论 - 图641 to 离散数学及其应用 第10、11章 图论 - 图642 without two edges crossing (and 离散数学及其应用 第10、11章 图论 - 图643 is planar). The addition of this new edge splits 离散数学及其应用 第10、11章 图论 - 图644 into two regions. Consequently, 离散数学及其应用 第10、11章 图论 - 图645, 离散数学及其应用 第10、11章 图论 - 图646, and 离散数学及其应用 第10、11章 图论 - 图647. Thus, 离散数学及其应用 第10、11章 图论 - 图648.
Otherwise, if one of the two vertices of the new edge is not already in 离散数学及其应用 第10、11章 图论 - 图649, suppose that 离散数学及其应用 第10、11章 图论 - 图650 is in 离散数学及其应用 第10、11章 图论 - 图651 but that 离散数学及其应用 第10、11章 图论 - 图652 is not. Adding this new edge does not produce any new regions, since 离散数学及其应用 第10、11章 图论 - 图653 must be in a region that has 离散数学及其应用 第10、11章 图论 - 图654 on its boundary. Consequently, 离散数学及其应用 第10、11章 图论 - 图655. Moreover, 离散数学及其应用 第10、11章 图论 - 图656 and 离散数学及其应用 第10、11章 图论 - 图657. Hence, 离散数学及其应用 第10、11章 图论 - 图658.
📋 Euler’s formula Extended to Unconnected Simple Planar Graph
Suppose that a planar graph 离散数学及其应用 第10、11章 图论 - 图659 has 离散数学及其应用 第10、11章 图论 - 图660 connected components, 离散数学及其应用 第10、11章 图论 - 图661 edges, and 离散数学及其应用 第10、11章 图论 - 图662 vertices. Let 离散数学及其应用 第10、11章 图论 - 图663 be the number of regions in a planar representation of 离散数学及其应用 第10、11章 图论 - 图664. Then 离散数学及其应用 第10、11章 图论 - 图665.
📋 Corollary 1
If 离散数学及其应用 第10、11章 图论 - 图666 is a planar simple graph with 离散数学及其应用 第10、11章 图论 - 图667 edges and 离散数学及其应用 第10、11章 图论 - 图668 vertices, where 离散数学及其应用 第10、11章 图论 - 图669, then 离散数学及其应用 第10、11章 图论 - 图670.
Proof:
Suppose that a connected planar simple graph divides the plane into 离散数学及其应用 第10、11章 图论 - 图671 regions, the degree of each region is at least 3 (Note that the degree of a region in a simple graph is at least 3, because 三个不共线的点确定一个平面). Since 离散数学及其应用 第10、11章 图论 - 图672, it implies 离散数学及其应用 第10、11章 图论 - 图673. Using Euler’s formula 离散数学及其应用 第10、11章 图论 - 图674, we obtain 离散数学及其应用 第10、11章 图论 - 图675, which shows that 离散数学及其应用 第10、11章 图论 - 图676.
The corollary also holds for unconnected planar simple graphs, because 离散数学及其应用 第10、11章 图论 - 图677 holds for each of the connected components.
📋 Corollary 2
If a connected planar simple graph has 离散数学及其应用 第10、11章 图论 - 图678 edges and 离散数学及其应用 第10、11章 图论 - 图679 vertices with 离散数学及其应用 第10、11章 图论 - 图680 and no circuits of length 3,then 离散数学及其应用 第10、11章 图论 - 图681.
Proof:
Similar to that of Corollary 1, except that in this case the fact that there are no circuits of length 3 implies that the degree of a region must be at least 4.
📋 Corollary 3
If 离散数学及其应用 第10、11章 图论 - 图682 is a connected planar simple graph, then 离散数学及其应用 第10、11章 图论 - 图683 has a vertex of degree not exceeding 5.
Proof:
If 离散数学及其应用 第10、11章 图论 - 图684 has 1 or 2 vertices, the result is true. If 离散数学及其应用 第10、11章 图论 - 图685 has at least three vertices, by Corollary 1 we know that 离散数学及其应用 第10、11章 图论 - 图686, so 离散数学及其应用 第10、11章 图论 - 图687. If the degree of every vertex were at least 6, then because 离散数学及其应用 第10、11章 图论 - 图688 by the handshaking theorem, we would have 离散数学及其应用 第10、11章 图论 - 图689. But this contradicts the inequality 离散数学及其应用 第10、11章 图论 - 图690.
🌰 e.g.
Show that 离散数学及其应用 第10、11章 图论 - 图691, 离散数学及其应用 第10、11章 图论 - 图692 are nonplanar.
Proof:
The graph 离散数学及其应用 第10、11章 图论 - 图693 has 5 vertices and 10 edges. The inequality 离散数学及其应用 第10、11章 图论 - 图694 is not satisfied for this graph. Therefore, 离散数学及其应用 第10、11章 图论 - 图695 is not planar.
离散数学及其应用 第10、11章 图论 - 图696 has 6 vertices and 9 edges. Since 离散数学及其应用 第10、11章 图论 - 图697 has no circuits of length 3 (this is easy to see since it is bipartite), Corollary 2 can be used. The inequality 离散数学及其应用 第10、11章 图论 - 图698 is not satisfied for this graph. Therefore, 离散数学及其应用 第10、11章 图论 - 图699 is nonplanar.
🌰 e.g.
The construction of Dodecahedron.
image.png
Solution:
Since the degree of every vertex is 3 and the degree of every region is 5. Then:离散数学及其应用 第10、11章 图论 - 图701

10.7.3 Kuratowski’s Theorem

If a graph is planar, so will be any graph obtained by removing an edge 离散数学及其应用 第10、11章 图论 - 图702 and adding a new vertex 离散数学及其应用 第10、11章 图论 - 图703 together with edges 离散数学及其应用 第10、11章 图论 - 图704 and 离散数学及其应用 第10、11章 图论 - 图705, and this operation is called an **elementary subdivision**(初等细分). The graph 离散数学及其应用 第10、11章 图论 - 图706 and 离散数学及其应用 第10、11章 图论 - 图707 are called **homeomorphic**(同胚) if they can be obtained from the same graph by a sequence of elementary subdivision.
image.png
📋 Kuratowski’s Theorem(库拉托夫斯基定理)
A graph is nonplanar ↔ it contains a subgraph homeomorphic to 离散数学及其应用 第10、11章 图论 - 图709 or 离散数学及其应用 第10、11章 图论 - 图710.
Proof:
Obviously a graph containing a subgraph homeomorphic to 离散数学及其应用 第10、11章 图论 - 图711 or 离散数学及其应用 第10、11章 图论 - 图712 is nonplanar. Then we need to show that every nonplanar graph contains a subgraph homeomorphic to 离散数学及其应用 第10、11章 图论 - 图713 or 离散数学及其应用 第10、11章 图论 - 图714. This part is so complicated that we don’t need to learn it in this course. QwQ

10.8 Graph Coloring

The map coloring problem is about determining the least number of colors that can be used to color a map so that adjacent regions never have the same color. This problem can be reduced to a graph-theoretic problem.
image.png
The **dual graph** of the map:

  • Each region of the map is represented by a vertex.
  • Edge connect two vertices iff the regions represented by these vertices have a common border.
  • Two regions that touch at only one point are not considered adjacent.

As a terminology, **coloring** means the assignment of a color to each vertex of the graph so that no two adjacent vertices are assigned the same color. Coloring a map is equivalent to coloring the vertices of the dual graph so that no two adjacent vertices in this graph have the same color.
image.png离散数学及其应用 第10、11章 图论 - 图717image.png
The **chromatic number**, denoted as 离散数学及其应用 第10、11章 图论 - 图719, is the least number of colors needed for a coloring of a graph.

  • If 离散数学及其应用 第10、11章 图论 - 图720, then 离散数学及其应用 第10、11章 图论 - 图721.
  • If 离散数学及其应用 第10、11章 图论 - 图722 is a path containing no circuits, then 离散数学及其应用 第10、11章 图论 - 图723.
  • 离散数学及其应用 第10、11章 图论 - 图724.
  • 离散数学及其应用 第10、11章 图论 - 图725, 离散数学及其应用 第10、11章 图论 - 图726.
  • 离散数学及其应用 第10、11章 图论 - 图727. A simple graph with a chromatic number of 2 is bipartite. A connected bipartite graph has a chromatic number of 2.

Two things are required to show that the chromatic number of a graph is 离散数学及其应用 第10、11章 图论 - 图728. First, we must show that the graph can be colored with 离散数学及其应用 第10、11章 图论 - 图729 colors. This can be done by constructing such a coloring. Second, we must show that the graph cannot be colored using fewer than 离散数学及其应用 第10、11章 图论 - 图730 colors.
🌰 e.g.
What are the chromatic numbers of the graphs 离散数学及其应用 第10、11章 图论 - 图731 and 离散数学及其应用 第10、11章 图论 - 图732?
image.pngimage.png
Solution:
The chromatic number of 离散数学及其应用 第10、11章 图论 - 图735 is at least 3, because the vertices 离散数学及其应用 第10、11章 图论 - 图736, 离散数学及其应用 第10、11章 图论 - 图737, and 离散数学及其应用 第10、11章 图论 - 图738 must be assigned different colors. To see if 离散数学及其应用 第10、11章 图论 - 图739 can be colored with 3 colors, assign red to 离散数学及其应用 第10、11章 图论 - 图740, blue
to 离散数学及其应用 第10、11章 图论 - 图741, and green to 离散数学及其应用 第10、11章 图论 - 图742. Then, 离散数学及其应用 第10、11章 图论 - 图743 can (and must) be colored red because it is adjacent to 离散数学及其应用 第10、11章 图论 - 图744 and 离散数学及其应用 第10、11章 图论 - 图745, and we have assumed that 离散数学及其应用 第10、11章 图论 - 图746 can be colored using only the 3 colors. Furthermore, 离散数学及其应用 第10、11章 图论 - 图747 can (and must) be colored green because it is adjacent only to vertices colored red and blue, and 离散数学及其应用 第10、11章 图论 - 图748 can (and must) be colored blue because it is adjacent only to vertices colored red and green. Finally, 离散数学及其应用 第10、11章 图论 - 图749 can (and must) be colored red because it is adjacent only to vertices colored blue and green. This produces a coloring of 离散数学及其应用 第10、11章 图论 - 图750 using exactly 3 colors.
The graph 离散数学及其应用 第10、11章 图论 - 图751 is made up of the graph 离散数学及其应用 第10、11章 图论 - 图752 with an edge connecting a and g. Any attempt to color 离散数学及其应用 第10、11章 图论 - 图753 using three colors must follow the same reasoning as that used to color 离散数学及其应用 第10、11章 图论 - 图754, except at the last stage, when all vertices other than 离散数学及其应用 第10、11章 图论 - 图755 have been colored. Then, because 离散数学及其应用 第10、11章 图论 - 图756 is adjacent (in 离散数学及其应用 第10、11章 图论 - 图757) to vertices colored red, blue, and green, a fourth color, say brown, needs to be used. Hence, 离散数学及其应用 第10、11章 图论 - 图758 has a chromatic number equal to 4.
💡 This solution shows a direct algorithm to find a coloring of a graph by trying to use color that has already been used at each step. Actually, the best algorithms known today for finding the chromatic number of a graph have exponential worst-case time complexity (in the number of vertices of the graph).
📋 The Four Color Theorem
The chromatic number of a planar graph is no greater than four. Or equivalently, any planar map of regions can be depicted using 4 colors so that no two regions that share a positive-length border have the same color.
The four color theorem was originally proposed as a conjecture in 1852. Many fallacious proof with hard-to-find errors were published. It was proved by Haken and Appel used exhaustive computer search in 1976. No proof not relying on computers has yet been found yet until today.
⚠️ The four color theorem applies only to planar graphs. Nonplanar graphs can have arbitrarily large chromatic numbers.
⚙️ Applications of Graph Coloring

  1. Scheduling Exams: How can the exams at a university be scheduled so that no student has two exams at the same time?

Solution:
This scheduling problem can be solved using a graph model, with vertices representing courses and with an edge between two vertices if there is a common student in the courses they represent. Each time slot for a final exam is represented by a different color. A scheduling of the exams corresponds to a coloring of the associated graph.

  1. Set up natural habitats of animal in a zoo.

Solution:
Let the vertices of a graph be the animals. Draw an edge between two vertices if the animals they represent cannot be in the same habitat because of their eating habits. A coloring of this graph gives an assignment of habitats.

11. Trees

11.1 Introduction to Trees

A **tree** is a connected simple graph with no simple circuits. A **forest** is a graph that has no simple circuit, but is not connected. Each of the connected components in a forest is a tree.
📋 An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.
Proof:

  1. 离散数学及其应用 第10、11章 图论 - 图759
  • There is a simple path between any two of its vertices because a tree is connected.
  • The path is unique because there is no circuit.
  1. 离散数学及其应用 第10、11章 图论 - 图760
  • The graph is connected because there are paths between each pair of the vertices.
  • The path is unique, so there is no circuit.

A **rooted tree** is a tree in which one vertex has been designated as the **root** and every edge is directed away from the root. An unrooted tree is converted into different rooted trees when different vertices are chosen as the root.
image.png
The **parent** of a non-root vertex 离散数学及其应用 第10、11章 图论 - 图762 is the unique vertex 离散数学及其应用 第10、11章 图论 - 图763 with a directed edge from 离散数学及其应用 第10、11章 图论 - 图764 to 离散数学及其应用 第10、11章 图论 - 图765. When 离散数学及其应用 第10、11章 图论 - 图766 is the parent of 离散数学及其应用 第10、11章 图论 - 图767, 离散数学及其应用 第10、11章 图论 - 图768 is called a **child** of 离散数学及其应用 第10、11章 图论 - 图769. Vertices with the same parent are called **siblings**.
The **ancestors** of a non-root vertex are all the vertices in the path from root to this vertex. The **descendants** of vertex 离散数学及其应用 第10、11章 图论 - 图770 are all the vertices that have 离散数学及其应用 第10、11章 图论 - 图771 as an ancestor. The **subtree** at vertex 离散数学及其应用 第10、11章 图论 - 图772 is the subgraph of the tree consisting of vertex 离散数学及其应用 第10、11章 图论 - 图773 and its descendants and all edges incident to those descendants. An **ordered rooted tree** is a rooted tree where the children of each internal vertex are ordered. In an ordered binary tree, the two possible children of a vertex are called the **left child** and the **right child**, if they exist. The tree rooted at the left child is called the **left subtree**, and that rooted at the right child is called the **right subtree**.
A vertex is called a **leaf** if it has no children. A vertex that have children is called an **internal vertex**.
The **level** of vertex 离散数学及其应用 第10、11章 图论 - 图774 in a rooted tree is the length of the unique path from the root to 离散数学及其应用 第10、11章 图论 - 图775, and the level of the root is defined to be 0. The **height** of a rooted tree is the maximum of the levels of its vertices.
A rooted tree is called a **m-ary tree** if every internal vertex has no more than 离散数学及其应用 第10、11章 图论 - 图776 children. It is a **binary tree** if 离散数学及其应用 第10、11章 图论 - 图777. The tree is called a **full m-ary tree** if every internal vertex has exactly 离散数学及其应用 第10、11章 图论 - 图778 children. A rooted m-ary tree of height 离散数学及其应用 第10、11章 图论 - 图779 is called **balanced** if all its leaves are at levels 离散数学及其应用 第10、11章 图论 - 图780 or 离散数学及其应用 第10、11章 图论 - 图781.
📋 A tree with 离散数学及其应用 第10、11章 图论 - 图782 vertices has 离散数学及其应用 第10、11章 图论 - 图783 edges.
Proof:
离散数学及其应用 第10、11章 图论 - 图784, 离散数学及其应用 第10、11章 图论 - 图785, 离散数学及其应用 第10、11章 图论 - 图786. Any tree must be planar and connected, so 离散数学及其应用 第10、11章 图论 - 图787. Since any tree have no circuits, so 离散数学及其应用 第10、11章 图论 - 图788, so 离散数学及其应用 第10、11章 图论 - 图789.
🌰 e.g.
A tree has two vertices of degree 2, one vertex of degree 3, three vertices of degree 4. How many leafs does this tree has?
Solution:
Suppose that there are 离散数学及其应用 第10、11章 图论 - 图790 leaves.
离散数学及其应用 第10、11章 图论 - 图791
📋 Every tree is a bipartite.
Proof:
Every tree can be colored using two colors. We can choose a root and color it red. Then we color all the vertices at odd levels blue, and all the vertices at even levels red.
image.png
📋 A full m-ary tree with 离散数学及其应用 第10、11章 图论 - 图793 internal vertices contains 离散数学及其应用 第10、11章 图论 - 图794 vertices and 离散数学及其应用 第10、11章 图论 - 图795 leaves.
Proof:
Every vertex, except the root, is the child of an internal vertex. Since each of the 离散数学及其应用 第10、11章 图论 - 图796 internal vertices has 离散数学及其应用 第10、11章 图论 - 图797 children, there are 离散数学及其应用 第10、11章 图论 - 图798 vertices in the tree other than the root. Therefore, the tree contains 离散数学及其应用 第10、11章 图论 - 图799 vertices.
📋 A full m-ary tree with 离散数学及其应用 第10、11章 图论 - 图800 vertices has 离散数学及其应用 第10、11章 图论 - 图801 internal vertices and 离散数学及其应用 第10、11章 图论 - 图802 leaves.
📋 A full m-ary tree with 离散数学及其应用 第10、11章 图论 - 图803 leaves has 离散数学及其应用 第10、11章 图论 - 图804 vertices and 离散数学及其应用 第10、11章 图论 - 图805 internal vertices
📋 For a full binary tree, 离散数学及其应用 第10、11章 图论 - 图806.
📋 There are at most 离散数学及其应用 第10、11章 图论 - 图807 leaves in an m-ary tree of height 离散数学及其应用 第10、11章 图论 - 图808. This is proved using MI, from 离散数学及其应用 第10、11章 图论 - 图809 to any height with respect to any 离散数学及其应用 第10、11章 图论 - 图810.
📋 Corallary
If an m-ary tree of height 离散数学及其应用 第10、11章 图论 - 图811 has 离散数学及其应用 第10、11章 图论 - 图812 leaves, then 离散数学及其应用 第10、11章 图论 - 图813. If the m-ary tree is full and balanced, then 离散数学及其应用 第10、11章 图论 - 图814.
Proof:

  1. 离散数学及其应用 第10、11章 图论 - 图815
  2. Since the tree is balanced. Then each leaf is at level 离散数学及其应用 第10、11章 图论 - 图816 or 离散数学及其应用 第10、11章 图论 - 图817, and since the height is 离散数学及其应用 第10、11章 图论 - 图818, there is at least one leaf at level 离散数学及其应用 第10、11章 图论 - 图819. It follows that 离散数学及其应用 第10、11章 图论 - 图820

    11.2 Applications of Trees

    A **binary search tree (BST)** is an ordered rooted binary tree, each vertex of whom contains a distinct **key value**. The key values in the tree can be compared using “greater than” and “less than”. The key value of each vertex is less than every key value in its right subtree, and greater than every key value in its left subtree.
    📋 Construction of BSTs

  3. The first value to be inserted is put into the root.

  4. Thereafter, each value to be inserted begins by comparing itself to the value in the root, moving left it is less, or moving right if it is greater. This continues at each level, until it can be inserted as a new leaf.

    1. Procedure insertion (T: binary search tree, x: item)
    2. v:=root of T
    3. While vnull and label(v)≠x
    4. Begin
    5. if x<label(v) then
    6. if left child of v null then
    7. v:=left child of v
    8. else
    9. add new vertex as a left child of v and set v:=null
    10. else
    11. if right child of v null then
    12. v:=right child of v
    13. else
    14. add new vertex as a right child of v and set v:=null
    15. end
    16. if root of T = null then
    17. add a vertex r to the tree and label it with x
    18. else if v is null or label(v)≠x then
    19. label new vertex with x and let v be this new vertex
    20. {v = location of x}

    🌰 e.g.
    Insert the elements ‘J’, ‘E’, ‘F’, ‘T’, ‘A’ in that order alphabetically.
    Solution:
    image.png

  5. ‘J’ is the first value, so it should be put at the root.

  6. ‘E’ is less than ‘J’, so it should be the left child of the root.
  7. ‘F’ is less than ‘J’, so move left; then compare ‘F’ to ‘E’ to find ‘F’ is greater than ‘E’, so ‘F’ should be the right child of ‘E’.
  8. ‘T’ is greater than ‘J’, so it should be the right child of ‘J’.
  9. ‘A’ is less than ‘J’ and ‘E’, so it moves left twice and should be the left child of ‘E’.

A rooted tree in which each internal vertex corresponds to a decision, with a subtree at these vertices for each possible outcome of the decision, is called a **decision tree**.
When using bit strings to encode the letters of the English alphabet, using bit strings of different lengths to encode letters can improve coding efficiency. But some method must be used to determine where the bits for each character start and end.
🌰 e.g.
e — 0, a — 1, t — 01. Then 0101 can be “eat”, “tea”, “eaea” or “tt”.
To ensure that no bit string corresponds to more than one sequence of letters, the bit string for a letter must never occur as the first part of the bit string for another letter. Codes with this property are called **prefix codes**.
A system of prefix codes can be constructed using a binary tree. The left edge at each internal vertex is labeled by 0, and the right edge at each internal vertex is labeled by 1. The leaves are labeled by characters which are encoded with the bit string constructed using the labels of the edges in the unique path from the root to the leaves
image.png
How to produce efficient codes based on the frequencies of occurrences of characters?
General problem:
Tree 离散数学及其应用 第10、11章 图论 - 图823 has 离散数学及其应用 第10、11章 图论 - 图824 leaves, 离散数学及其应用 第10、11章 图论 - 图825, 离散数学及其应用 第10、11章 图论 - 图826,…, 离散数学及其应用 第10、11章 图论 - 图827 are weights representing the frequency of each leaf being used, 离散数学及其应用 第10、11章 图论 - 图828 is the length of the code. Let the weight of tree 离散数学及其应用 第10、11章 图论 - 图829 be 离散数学及其应用 第10、11章 图论 - 图830, then 离散数学及其应用 第10、11章 图论 - 图831.
For example,

Letter a b c d e
Frequency 82 14 28 38 131

Let 离散数学及其应用 第10、11章 图论 - 图832 be the length of prefix codes for letter 离散数学及其应用 第10、11章 图论 - 图833, then 离散数学及其应用 第10、11章 图论 - 图834
Solution:
📋 Huffman Coding

  1. Procedure Huffman (C: symbols ai with frequencies wi, i=1, ... , n)
  2. F:=forest of n rooted trees,
  3. each consisting of the single vertex ai and assigned weight wi
  4. While F is not a tree
  5. begin
  6. Replace the rooted trees T and T of least weights from F with w(T) w(T’)
  7. with a tree having a new root that has T as its left subtree and T as its
  8. right subtree. Label the new edge to T with 0 and the new edge to T with 1.
  9. Assign w(T) + w(T’) as the weight of the new tree.
  10. end
  11. {The Huffman coding for the symbol ai is the concatenation of the labels of
  12. the edges in the unique path from the root to the vertex ai}

🌰 e.g.
Use Huffman coding to encode the following symbols with the frequencies listed: A — 0.08, B — 0.10, C — 0.12, D — 0.15, E — 0.20, F — 0.35. What is the average number of bits used to encode a character?
Solution:
image.png
image.png
At first, we have a forest of 6 single vertices, and list them in the order of increasing weight. The two vertices with the least weights are A and B, so construct a tree of weight 0.18 using them. List the forest in the order of increasing weight. Then the two vertices with the least weights are C and D, so construct a tree using them. List the forest in the order of increasing weight. Repeat this procedure until the forest become a tree.

11.3 Tree Traversal

A **traversal algorithm** is a procedure for systematically visiting every vertex of an ordered rooted tree. Tree traversals are defined recursively.
Three traversals are named: **preorder**, **inorder**, **postorder**.
📋 Preorder Traversal
Let 离散数学及其应用 第10、11章 图论 - 图837 be an ordered tree with root 离散数学及其应用 第10、11章 图论 - 图838. If 离散数学及其应用 第10、11章 图论 - 图839 has only 离散数学及其应用 第10、11章 图论 - 图840, then 离散数学及其应用 第10、11章 图论 - 图841 is the preorder traversal of 离散数学及其应用 第10、11章 图论 - 图842. Otherwise, suppose 离散数学及其应用 第10、11章 图论 - 图843, 离散数学及其应用 第10、11章 图论 - 图844, … , 离散数学及其应用 第10、11章 图论 - 图845 are the left to right subtrees at 离散数学及其应用 第10、11章 图论 - 图846. The preorder traversal begins by visiting 离散数学及其应用 第10、11章 图论 - 图847. Then traverses 离散数学及其应用 第10、11章 图论 - 图848 in preorder, then traverses 离散数学及其应用 第10、11章 图论 - 图849 in preorder, and so on, until 离散数学及其应用 第10、11章 图论 - 图850 is traversed in preorder.
image.png

  1. procedure preorder (T: ordered rooted tree)
  2. r := root of T
  3. list r
  4. for each child c of r from left to right
  5. T(c) := subtree with c as root
  6. preorder(T(c))

Preorder traversal of an binary ordered tree:

  • Visit the root.
  • Visit the left subtree, using preorder.
  • Visit the right subtree, using preorder.

🌰 e.g.
image.png
📋 Inorder Traversal
Let 离散数学及其应用 第10、11章 图论 - 图853 be an ordered tree with root 离散数学及其应用 第10、11章 图论 - 图854. If 离散数学及其应用 第10、11章 图论 - 图855 has only 离散数学及其应用 第10、11章 图论 - 图856, then 离散数学及其应用 第10、11章 图论 - 图857 is the inorder traversal of 离散数学及其应用 第10、11章 图论 - 图858. Otherwise, suppose 离散数学及其应用 第10、11章 图论 - 图859, 离散数学及其应用 第10、11章 图论 - 图860, … , 离散数学及其应用 第10、11章 图论 - 图861 are the left to right subtrees at 离散数学及其应用 第10、11章 图论 - 图862. The inorder traversal begins by traversing 离散数学及其应用 第10、11章 图论 - 图863 in inorder. Then visits 离散数学及其应用 第10、11章 图论 - 图864, then traverses 离散数学及其应用 第10、11章 图论 - 图865 in inorder, and so on, until 离散数学及其应用 第10、11章 图论 - 图866 is traversed in inorder.
image.png

  1. procedure inorder (T: ordered rooted tree)
  2. r := root of T
  3. if r is a leaf then
  4. list r
  5. else
  6. l := first child of r from left to right
  7. T(l) := subtree with l as its root
  8. inorder(T(l))
  9. list(r)
  10. for each child c of r from left to right
  11. T(c) := subtree with c as root
  12. inorder(T(c))

Inorder traversal of an binary ordered tree:

  • Visit the left subtree, using inorder.
  • Visit the root.
  • Visit the right subtree, using inorder.

🌰 e.g.
image.png
📋 Postorder Traversal
Let 离散数学及其应用 第10、11章 图论 - 图869 be an ordered tree with root 离散数学及其应用 第10、11章 图论 - 图870. If 离散数学及其应用 第10、11章 图论 - 图871 has only 离散数学及其应用 第10、11章 图论 - 图872, then 离散数学及其应用 第10、11章 图论 - 图873 is the postorder traversal of 离散数学及其应用 第10、11章 图论 - 图874. Otherwise, suppose 离散数学及其应用 第10、11章 图论 - 图875, 离散数学及其应用 第10、11章 图论 - 图876, … , 离散数学及其应用 第10、11章 图论 - 图877 are the left to right subtrees at 离散数学及其应用 第10、11章 图论 - 图878. The postorder traversal begins by traversing 离散数学及其应用 第10、11章 图论 - 图879 in postorder. Then traverses 离散数学及其应用 第10、11章 图论 - 图880 in postorder, until 离散数学及其应用 第10、11章 图论 - 图881 is traversed in postorder, finally ends by visiting 离散数学及其应用 第10、11章 图论 - 图882.
image.png

  1. procedure postordered (T: ordered rooted tree)
  2. r := root of T
  3. for each child c of r from left to right
  4. T(c) := subtree with c as root
  5. postorder(T(c))
  6. list r

Postorder traversal of an binary ordered tree:

  • Visit the left subtree, using postorder.
  • Visit the right subtree, using postorder.
  • Visit the root.

🌰 e.g.
image.png
Complicated expressions, such as compound propositions, combinations of sets and arithmetic expressions, can be represented using ordered rooted trees called **expression trees**. A **binary expression tree** is a special kind of binary tree in which each leaf node contains a single operand, each nonleaf node contains a single operator, and the left and right subtrees of an operator node represent subexpressions that must be evaluated before applying the operator at the root of the subtree.
🌰 e.g.
What is the ordered tree that represents the expression 离散数学及其应用 第10、11章 图论 - 图885?
Solution:
A binary tree for the expression can be built from the bottom up, as is illustrated here. The higher the priority is, the nearer it should be to the leaves in the expression tree.
image.png
An inorder traversal of the expression tree produces the original expression, called the **infix form**(中缀形式), when parentheses are included except for unary operations, which now immediately follow their operands. For example, the infix form we get from the expression tree above is 离散数学及其应用 第10、11章 图论 - 图887.
The expression obtained by an preorder traversal of the binary tree is said to be in **prefix form**(前缀形式) (Polish notation). For example, the prefix form of the expression tree above is 离散数学及其应用 第10、11章 图论 - 图888. In a prefix form, operators precede their operands , parentheses are not needed, as the representation is unambiguous. Prefix expressions are evaluated by working from right to left.
The expression obtained by an postorder traversal of the binary tree is said to be in **postfix form**(后缀形式)(reverse Polish notation 逆波兰记号). For example, the prefix form of the expression tree above is 离散数学及其应用 第10、11章 图论 - 图889. Parentheses are not needed as the postfix form is unambiguous, and it evaluate an expression by working from left to right.

11.4-11.5 Spanning Trees & Minimum Spanning Trees

Let 离散数学及其应用 第10、11章 图论 - 图890 be a simple graph. A **spanning tree**(生成树) of 离散数学及其应用 第10、11章 图论 - 图891 is a subgraph of 离散数学及其应用 第10、11章 图论 - 图892 that is a tree containing every vertex of 离散数学及其应用 第10、11章 图论 - 图893. We can find spanning trees of a graph by removing edges from simple circuits(破圈法).
🌰 e.g.
image.png
📋 A simple graph is connected if and only if it has a spanning tree.
Proof:
First, suppose that a simple graph 离散数学及其应用 第10、11章 图论 - 图895 has a spanning tree tree 离散数学及其应用 第10、11章 图论 - 图896. 离散数学及其应用 第10、11章 图论 - 图897 contains every vertex of 离散数学及其应用 第10、11章 图论 - 图898. There is a path in 离散数学及其应用 第10、11章 图论 - 图899 between any two of its vertices. Since 离散数学及其应用 第10、11章 图论 - 图900 is a subgraph of 离散数学及其应用 第10、11章 图论 - 图901, there is a path in 离散数学及其应用 第10、11章 图论 - 图902 between any two of its vertices. Hence 离散数学及其应用 第10、11章 图论 - 图903 is connected.
Second, suppose that 离散数学及其应用 第10、11章 图论 - 图904 is connected. We can find a spanning trees by removing edges from simple circuits of 离散数学及其应用 第10、11章 图论 - 图905.
Apart form constructing spanning trees by removing edges, spanning trees can also be built up by successively adding edges. There are two algorithms: depth-first search and breadth-first search.
📋 Depth-First Search(深度优先搜寻)/ Backtracking(回溯)
This procedure forms a rooted tree, and the underlying undirected graph is a spanning tree.

  1. Arbitrarily choose a vertex of the graph as root.
  2. From a path starting at this vertex by successively adding edges, where each new edge is incident with the last vertex in the path and a vertex not already in the path.
  3. Continue adding edges to this path as long as possible.
  4. If the path goes through all vertices of the graph, the tree consisting of this path is a spanning tree.
  5. If the path does not go through all vertices, more edges must be added. Move back to the next to last vertex in the path, if possible, form a new path starting at this vertex passing through vertices that were not already visited. If this cannot be done, move back another vertex in the path.
  6. Repeat this process. ``` procedure DFS(G: connected graph with vertices v1, v2, …, vn) T := tree consisting only of the vertex v1 visit(v1)

procedure visit(v: vertex of G) for each vertex w adjacent to v and not yet in T add vertex w and edge {v,w} to T visit(w)

  1. 🌰 e.g.<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/25775350/1654563792678-d6c17e86-d51f-4341-8d4a-8e0eaa52503b.png#clientId=u9541381d-e05f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=159&id=u80164741&margin=%5Bobject%20Object%5D&name=image.png&originHeight=269&originWidth=338&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21097&status=done&style=none&taskId=u82a43459-321e-49d7-b29b-93eb5bd85d1&title=&width=200)<br />What is the output of depth-first search given the graph above as input?<br />Solution:<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/25775350/1654563843278-4ddbbed9-d213-49aa-8514-2c212067e142.png#clientId=u9541381d-e05f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=281&id=uf70eb279&margin=%5Bobject%20Object%5D&name=image.png&originHeight=449&originWidth=480&originalType=binary&ratio=1&rotation=0&showTitle=false&size=22509&status=done&style=none&taskId=u06cac18f-575a-499b-bc70-99d3af2756e&title=&width=300)<br />📋 Breadth-First Search(广度优先搜寻)
  2. 1. Arbitrarily choose a vertex of the graph as a root, and add all edges incident to this vertex.
  3. 2. The new vertices added at this stage become the vertices at level 1 in the spanning tree. Arbitrarily order them.
  4. 3. For each vertex at level 1, visited in order, add each edge incident to this vertex to the tree as long as it does not produce a simple circuit. Arbitrarily order the children of each vertex at level 1. This produces the vertices at level 2 in the tree.
  5. 4. Follow the same procedure until all the vertices in the tree have been added.

procedure BFS(G: connected graph with vertices v1, v2, …, vn) T := tree consisting only of the vertex v1 L := empty list visit(v1) put v1 in the list L of unprocessed vertices while L is not empty remove the first vertex, v, from L for each neighbor w of v if w is not in L and not in T then add w to the end of the list L add w and edge {v,w} to T

  1. 🌰 e.g.<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/25775350/1654564097436-43f0792a-f530-4e91-9e66-9890146311bf.png#clientId=u9541381d-e05f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=206&id=u79035b19&margin=%5Bobject%20Object%5D&name=image.png&originHeight=359&originWidth=349&originalType=binary&ratio=1&rotation=0&showTitle=false&size=19145&status=done&style=none&taskId=u2143ec7f-53ab-4f34-a4d5-5afc9344859&title=&width=200)<br />Use a breadth-first search to find a spanning tree for the graph above.<br />Solution:<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/25775350/1654564212842-5f8436f2-f93f-4457-9ccc-af7784e5c8bc.png#clientId=u9541381d-e05f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=214&id=uff0da8bd&margin=%5Bobject%20Object%5D&name=image.png&originHeight=391&originWidth=366&originalType=binary&ratio=1&rotation=0&showTitle=false&size=23095&status=done&style=none&taskId=u3f987113-f270-4d4e-b8b5-993404a7ed7&title=&width=200)<br />There are problems that can be solved only by performing an exhaustive search of all possible solutions. One way to search systematically for a solution is to build a decision tree using `**backtracking scheme**`(回溯法), where each internal vertex represents a decision and each leaf a possible solution.<br />A `**minimum spanning tree**` in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges.<br />Two algorithms for constructing minimum spanning trees: Prim's algorithm and Kruskal's algorithm. These two algorithms are examples of greedy algorithms, both proceed by successively adding edges of smallest weight from those edges with a specified property that have not already been used.<br />📋 Prim's Algorithm

Procedure Prim (G: weighted connected undirected graph with n vertices) T:= a minimum-weight edge for i:= 1 to n-2 begin e:= an edge of minimum weight incident to a vertex in T and not forming a simple circuit in T if added to T. T:= T with e added end {T is a minimum spanning tree of G}

  1. 📋 Kruskal's Algorithm(最简单)

Procedure Kruskal (G: weighted connected undirected graph with n vertices) T:= empty graph for i:= 1 to n-1 begin e:= any edge in G with smallest weight that does not form a simple circuit when added to T T:= T with e added end {T is a minimum spanning tree of G} ``` 🌰 e.g.
image.png
Find a minimum spanning tree in the weighted graph.
Solution:
image.png

Prim’s algorithm
Choice Edge Cost
1 BE 700
2 EC 800
3 BA 1200
4 AD 900
Total 3600
Kruskal’s algorithm
Choice Edge Cost
1 BE 700
2 EC 800
3 AD 900
4 AB 1200
Total 3600