Skip to content

Commit

Permalink
update: 240606 ver1
Browse files Browse the repository at this point in the history
  • Loading branch information
V1CeVersa authored and V1CeVersa committed Jun 5, 2024
1 parent 5c35b80 commit 6b8bc6f
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/Computer Science/Algorithm/04 Graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ void TopologicalSort(ALGraph G) {
求解方法:建立残差图,残差网络的边权如下,每在残差网络中寻找到一条增广路径,就更新一下残差图,知道找不到增广路径为止。

\[
c_f(u, v) = \begin{cases} c(u, v) - f(u, v) & \text{if } (u, v) \in E \\ f(v, u) & \text{if } (v, u) \in E \\ 0 & \text{otherwise } \end{cases}
c_f(u, v) = \begin{cases} c(u, v) - f(u, v) & \text{if } (u, v) \in E \\
f(v, u) & \text{if } (v, u) \in E \\
0 & \text{otherwise } \end{cases}
\]

增广路径:从源点到汇点的一条简单路径路径,流量是路径上的最短路径。
Expand Down
194 changes: 189 additions & 5 deletions docs/Math/Discrete Mathematics/10 Graph Theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ Some special simple graphs:

**Theorem 4**: 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 have the same color.

**Matching**: A matching $M$ in a simple graph $G = (V, E)$ is a subset of $E$ such that no two edges are incident with the sim
**Matching**: A matching $M$ in a simple graph $G = (V, E)$ is a subset of $E$ such that no two edges are incident with the same vertex.

A **Maximum matching** is a matching with the largest number of edges.

We say that a matching $M$ in a bipartite graph $G = (V, E)$ with bipartition $(V_1, V_2)$ is a **complete matching from** $V_1$ to $V_2$ if every vertex in $V_1$ is an endpoint of an edge of the matching.

**Hall's Marriage Theorem**: The bipartite graph $G = (V, E)$ with bipartition $(V_1, V_2)$ has a complete matching from $V_1$ to $V_2$ if and only if $\vert N(A)\vert \geqslant \vert A\vert$ for all subsets $A$ of $V_1$. A vertex that is the endpoint of an edge of a matching $M$ is said to be **matched** by $M$.
**Hall's Marriage Theorem**: The bipartite graph $G = (V, E)$ with bipartition $(V_1, V_2)$ has a complete matching from $V_1$ to $V_2$ if and only if $\vert N(A)\vert \geqslant \vert A\vert$ for all subsets $A$ of $V_1$. A vertex that is the endpoint of an edge of a matching $M$ is said to be **matched** by $M$.

A good but long proof.

**Proof**:

Expand All @@ -75,13 +77,195 @@ For $G = (V, E)$ and $H = (W, F)$.

## 10.3 Representing Graphs and Graph Isomorphism

**Adjacency Matrix**: A simple graph $G = (V, E)$ with $n$ vertices $(v_1,v_2,\cdots, v_n)$ can be represented by its adjacency matrix, A, with respect to this listing of the vertices, where
**Adjacency Matrix**: A simple graph $G = (V, E)$ with $n$ vertices $(v_1,v_2,\cdots, v_n)$ can be represented by its adjacency matrix, A, with respect to this listing of the vertices, where

\[
a_{ij} = \begin{cases} 1 & \text{if } \{v_i, v_j\} \text{ is an edge} \\
0 & \text{otherwise} \end{cases}
\]

For multigraphs and pseudographs, the adjacency matrix is defined similarly, but the entries can't be just $0$ or $1$ anymore.

**Incidence Martix**: Let $G = (V, E)$ be an undirected graph. Suppose that $v_1, v_2, \cdots, v_n$ are the vertices and $e_1, e_2, \cdots, e_m$ are the edges of $G$. Then the incidence matrix with respect to this ordering of $V$ and $E$ is $n\times m$ matrix $M = [m_{ij}]_{n\times m}$, where

\[
m_{ij} =
\begin{cases} 1 & \text{when edge } e_j \text{ is incident with } v_i \\
0 & \text{otherwise} \end{cases}
\]

**Isomorphism of Graphs**: Graphs with the same structure are said to be isomorphic. Formally, two simple graphs $G_1= (V_1, E_1)$ and $G_2= (V_2, E_2)$ are **isomorphic** if there is a $1-1$ and onto bijection $f$ from $V_1$ to $V_2$ such that for all $a$ and $b$ in $V_1$, $a$ and $b$ are adjacent in $G_1$ iff $f(a)$ and $f(b)$ are adjacent in $G_2$. Such a function $f$ is called an isomorphism.

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.

**Important Invariants**:

- The number of vertices;
- The number of edges;
- The degrees of the corresponding vertices;
- If one is bipartite, the other must be bipartite;
- If one is completed, the other must be complete;

## 10.4 Connectivity

A **path of length** $n$ in a simple path is a sequence of vertices $v_0, v_1, \cdots, v_n$ such that $\{v_0, v_1\}$, $\{v_1, v_2\}$, $\cdots$, $\{v_{n-1}, v_n\}$ are $n$ edges of the graph.

The path is a **circuit** if the beginning and ending vertices are the same and the length of the path is greater than $0$.

A path is simple if it doesn't contain the same edge more than once.

A **path of length** $n$ in a **directed graph** is a sequence of vertices $v_0, v_1, \cdots, v_n$ such that $(v_0, v_1)$, $(v_1, v_2)$, $\cdots$, $(v_{n-1}, v_n)$ are $n$ edges of the graph. Circuits, cycles and simple paths are defined as before.

**Theorem 5**: The number of different paths of length $r$ from $v_i$ to $v_j$ is equal to the $(i, j)$ entry in the matrix $A^r$, where $A$ is the adjacency matrix of the graph. Easy to prove.

**Connected Graph**: An undirected graph is **connected** if there is a path between every pair of distinct vertices of the graph.

**Theorem 6**: There is a simple path between every pair of distinct vertices in a connected undirected graph. Just the definition.

**Components**: The maximally connected subgraphs of $G$ are called the **connected components** or just the components.

**Cut Vertex/Articulation Point**: A vertex is a **cut vertex** or **articulation point** if removing it and all edges incident with is results in more connected compotents than the original graph.

Similarly, if removal of an edge results in more connected components, then the edge is a **cut edge** or a **bridge**.

**Strongly Connected**: A directed graph is **strongly connected** if there is a directed path from $u$ to $v$ and a directed path from $v$ to $u$ for every pair of vertices $u$ and $v$ in the graph.

**Weakly Connected**: A directed graph is **weakly connected** if the underlying undirected graph is connected. Every strongly connected graph is weakly connected.

**Strongly Connected Components**: For a directed graph, the maximal strongly connected subgraphs are called the **strongly connected components**.

Left issues: Kosaraju's algorithm and Tarjan's algorithm.

**Some Other Invariants**:

- The number and size of connected components;
- 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.

## 10.5 Euler and Hamilton Paths

## 10.6 Planar Graphs
**Euler Path**: An **Euler Path** is a simple path containing every edge in $G$.

**Euler Circuit**: An **Euler Circuit** is not only an Euler path but also a circuit.

**Euler Graph**: A graph that contains an Euler circuit is called an **Euler graph**.

**Theorem 7**: A connected multigraph has an Euler circuit if and only if each of its vertices has even degree.

**Proof**:

- **Necessary Condition**:
- **Sufficient Condition**:

**Build and Find a Euler Circuit and Path**:

- Start from a vertex that has even degree.
- Add paths that from a circuit until you can't add any more.
- Ommitting all the edges that have been used, find a vertex that has an odd degree and repeat the process.

This will produce an Euler circuit, since every path is included and no edge is included more than once.

**Theorem 8**: A connected multigraph has an Euler path but not an Euler circuit if and only if it has **exactly two vertices of odd degree**.

**Theorem 9**: A **directed** multigraph having no isolated vertices has an Euler circuit if and only if the graph is weakly connected **and** the in-degree and out-degree of each vertex are equal.

> 所有顶点的出度入度相等的弱联通有向多图有欧拉回路。
**Theorem 10**: 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.

> 没法翻译了,太抽象了。
**Hamilton Path**: A **Hamilton path** in a graph $G$ is a path which visits every vertex exactly once.

**Hamilton Circuit**: A **Hamilton circuit** is a circuit that visits every vertex exactly once except for the first vertex.

**Hamilton Graph**: A graph that contains a Hamilton circuit is called a **Hamilton graph**.

**Theorem 11** (DIRAC): If $G$ is a simple graph with $n$ vertices $(n \geqslant 3)$ and if the degree of each vertex is at least $n/2$, then $G$ has a Hamilton circuit.

**Theorem 12** (ORE): If $G$ is a simple graph with $n$ vertices $(n \geqslant 3)$ and if for every pair of nonadjacent vertices $u$ and $v$ of $G$, the sum of the degrees of $u$ and $v$ is at least $n$, i.e. $\deg(u) + \deg(v) \geqslant n$, then $G$ has a Hamilton circuit.

**Necessary Condition for Hamilton Path and Halmiton Circuit**: For undirected graph: The necessary condition for the existence of Hamilton path:

- $G$ is connected;
- There are at most two vertices which degree are less than $2$.

The necessary condition for the existence of Hamilton circuit:

1. The degree of each vertex is larger than $1$.

Some properties:

- 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.

2. $G$ is a Hamilton graph, for any nonempty subset $S$ of set $V$, the number of connected components in $G-S$ does not exceed $\vert S\vert$.

## 10.6 Shortest Path Problems

**Weighted Graph**: $G = (V, E, W)$, where $W$ is a function that assigns a real number $W(e)$ to each edge $e$ in $E$. The number $W(e)$ is called the **weight** of edge $e$.

**Length of a Path**: The **length** of a path in a weighted graph is the sum of the weights of the edges in the path.

**Shortest Path**: The **shortest path** between two vertices $u$ and $v$ in a weighted graph is a path of minimum length between $u$ and $v$.

1. For **undirected graphs with positive graphs**: **Dijkstra's Algorithm**.

**Theorem 13**: Dijkstra’s algorithm finds the length of a shortest path between two vertices in a connected simple undirected weighted graph.

**Theorem 14**: Dijkstra’s algorithm uses $O(n^2)$ operations (additions and comparisons) to find the length of the shortest path between two vertices in a connected simple undirected weighted graph.

2. **Floyd's Algorithm**: Allow negative weights but no negative cycles.

```plaintext
Procedure Floyd(G: weighted simple graph):
{G has vertices v_1, ..., v_n and weights w(v_i, v_j) with
w(v_i, v_j) = infty if {v_i, v_j} is not an edge}
for i := 1 to n:
for j := 1 to n:
d(v_i, v_j) := w(v_i, v_j)
for i := 1 to n:
for j := 1 to n:
for k := 1 to n:
if d(v_j, v_i) + d(v_i, v_k) < d(v_j, v_k):
then d(v_j, v_k) := d(v_j, v_i) + d(v_i, v_k)
{d(v_i, v_j) is the length of a shortest path between v_i and v_j}
```

## 10.7 Planar Graphs

**Planar Graphs**: 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.

**Region**: A **region** is a part of the plane completely disconnected off from other parts of the plane by the edges of the graph. We have **Bounded Region** and **Unbounded Region**.

There is one unbounded region in a planar graph.

**Theorem 15** (Euler's Formula): Let $G$ be a **connected planar simple graph** with $e$ edges and $v$ vertices. Let $r$ be the number of regions in a planar representation of $G$. Then $r=e-v+2$.

**Proof**:

**Degree of a Region**: Suppose $R$ is a region of a connected planar simple graph, the **number** of the edges on the boundary of $R$ is called the **Degree** of $R$, denoted by $\mathrm{Deg}(R)$.

**Corollary**: If $G$ is a connected planar simple graph with $e$ edges and $v$ vertices where $v\geqslant 3$, then $e\leqslant 3v-6$. The equality holds if and only if every region has exactly three edges.

**Corollary**: If $G$ is a connected planar simple graph, then $G$ has a vertex of degree not exceeding five.

**Corollary**: If a connected planar simple graph has $e$ edges and $v$ vertices with $v\geqslant 3$ and no circuits of length $3$, then $e \leqslant 2v-4$. Generally, if every region of a connected planar simple graph has at least $k$ edges, then

$$e \leqslant \frac{k(v - 2)}{k - 2}.$$

**Elementary Subdivision**: If a graph is planar, so will be any graph obtained by removing an edge $\{u, v\}$ and adding a new vertex $w$ together with edges $\{u, w\}$ and $\{w, v\}$. Such an operation is called an **elementary subdivision**.

> 移除度为 2 的顶点或者在边上加一个顶点。
**Homeomorphic**: The graph $G_1=(V_1,E_1)$ and $G_2=(V_2,E_2)$ are called **homeomorphic** if they can be obtained from the same graph by a sequence of elementary subdivision.

**Theorem 16** (KURATOWSKI): A graph is nonplanar if and only if it contains a subgraph homeomorphic to $K_{3,3}$ or $K_5$.

## 10.7 Graph Coloring
## 10.8 Graph Coloring

## 10.9 Netflow
2 changes: 1 addition & 1 deletion docs/Math/Discrete Mathematics/Discrete Mathematics.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- [x] [Counting](./06%20Counting.md)
- [ ] [Advanced Counting Techniques](./08%20Advanced%20Counting%20Techniques.md)
- [x] [Relations](./09%20Relations.md)
- [ ] [Graph Theory](./10%20Graph%20Theory.md)
- [ ] [Graph Theory](./10%20Graph%20Theory.md) (Omiting some proofs)
- [ ] [Trees](./11%20Trees.md)
- [ ] [Boolean Algebra](./12%20Boolean%20Algebra.md)
- [ ] [Modeling Computation](./13%20Modeling%20Computation.md)

0 comments on commit 6b8bc6f

Please sign in to comment.