离散数学 · 图论
1 Graphs and Basic Definitions
跳转到:1 Graphs and Basic Definitions1.1 Graph
跳转到:1.1 Graph- Graph: a graph is an ordered pair where is a set of vertices and is a set of edges.
- Every edge has two vertices associated with it, called its endpoints; these two vertices can be different or identical; an edge is said to connect its endpoints.
- Remark: and can be infinite, but the course focuses on finite cases.
1.2 Different kinds of graphs
跳转到:1.2 Different kinds of graphsGraphs are classified along three axes:
- Directed / Undirected;
- with or without multiple edges(重边,a.k.a. parallel edges,平行边);
- with or without loops(自环).
2 Degree
跳转到:2 Degree2.1 Adjacency, incidence, neighbourhood, degree (undirected)
跳转到:2.1 Adjacency, incidence, neighbourhood, degree (undirected)- Adjacency: if is an undirected graph, two vertices are adjacent (or neighbours) in if there is an edge such that the endpoints of are .
- Incidence: if the endpoints of an edge are , then is incident with .
- Neighbourhood: is the set of all neighbours of ; for a vertex set , .
- Degree(度): for an undirected graph , the degree of a vertex is the number of edges incident with it, where a loop associated with contributes twice to the degree of :
2.2 The Handshaking Theorem(握手定理)
跳转到:2.2 The Handshaking Theorem(握手定理)- Handshaking Theorem: if is a finite undirected graph, then .
- Proof idea (double counting by exchanging summation order — in the first two lines the inner sums run over edges , after the exchange the inner sums run over vertices ):
- Corollary: an undirected graph has an even number of vertices of odd degree.
2.3 Directed edges, in-degree and out-degree
跳转到:2.3 Directed edges, in-degree and out-degree- Directed edges: if is a directed graph and is from to , then: is adjacent to , and is adjacent from ; is the initial vertex of the edge, while is the terminal (or end) vertex of the edge.
- In-degree / out-degree: if is a directed graph and :
- (in-degree);
- (out-degree).
- Degree sum of directed graphs: if is a finite directed graph, then .
3 Paths and Circuits
跳转到:3 Paths and Circuits- Path (undirected): for an undirected graph and , a path of length () from to in is a finite sequence of edges in such that there exists a finite sequence of vertices such that the endpoints of each are .
- The path is simple if it does not contain duplicate edges. The path traverses these edges and passes through the vertices .
- Notation: we write the path as if is simple.
- Circuit (undirected): a path of positive length from to is a circuit. The circuit is simple if it does not contain duplicate edges.
- Path (directed): for a directed graph and , a path of length () from to is a finite sequence of edges in such that there exists a finite sequence of vertices such that each is from to ; simple, traverses and passes through are defined in the same way as in the undirected case.
- Notation: we write the path as if is a simple directed graph.
- Circuit (directed): a path of positive length from to is a circuit; it is simple if it does not contain duplicate edges.
4 Connectivity of Undirected Graphs
跳转到:4 Connectivity of Undirected Graphs4.1 Connected vertices and connected graphs
跳转到:4.1 Connected vertices and connected graphs- Connected vertices: in an undirected graph , two vertices are connected if there is a path from to in .
- Basic properties of connectivity in an undirected graph :
- for any , is connected to itself;
- for any , if is connected to , then is connected to ;
- for any , if is connected to and is connected to , then is connected to .
- Connected graph(连通图): an undirected graph is connected if every pair of vertices in is connected; otherwise it is disconnected.
4.2 Subgraphs and connected components
跳转到:4.2 Subgraphs and connected components- Subgraph(子图): a subgraph of a graph is a graph such that (i) and (ii) . A subgraph of is proper if .
- A path induces a connected subgraph: if is an undirected graph and is a path in from to that traverses , then with and is a connected subgraph of .
- Union of overlapping connected subgraphs: if is an undirected graph, and are two connected subgraphs of , and , then is also a connected subgraph of .
- Induced subgraph(导出子图): for , the subgraph induced by consists of all the vertices from and all the edges from whose endpoints both lie in .
- Connected component(连通块): a connected component of an undirected graph is a connected subgraph of that is not a proper subgraph of another connected subgraph of .
- Structure of connected components: if is a nonempty undirected graph, then 's connected components are induced subgraphs of 's subsets of the form for some .
- Proof structure (two directions, four obligations):
- 1) Suppose is a connected component of : (1a) prove that if , then ; (1b) prove that are all edges between two vertices in .
- 2) Suppose and are all edges between two vertices in : (2a) prove that is a connected graph; (2b) prove that is not a proper subgraph of another connected subgraph of .
5 Reachability of Directed Graphs
跳转到:5 Reachability of Directed Graphs- Strongly-connected directed graph(强连通图): a directed graph is strongly connected if for every pair of vertices , there is a path from to and a path from to .
- Strongly-connected component(强连通块): a strongly-connected component of a directed graph is a strongly-connected subgraph of that is not a proper subgraph of another strongly-connected subgraph of .
- Reachability: a vertex is reachable from if there is at least a path from to in .
- Mutual reachability: two vertices are mutually reachable if there are paths both from to and from to in .
- Basic properties of mutual reachability in a directed graph :
- for any , and itself are mutually reachable;
- for any , if and are mutually reachable, then and are mutually reachable;
- for any , if and are mutually reachable, and and are mutually reachable, then and are mutually reachable.
- Structure of strongly-connected components: given a nonempty directed graph , its strongly-connected components are induced subgraphs of 's subsets of the form for some .
- Reachability between components is uniform: if and are two strongly-connected components of , then for any and : is reachable from iff is reachable from .
- Circuits live inside one component: if is a circuit of a directed graph passing through , then and belong to the same strongly connected component.
6 Connectivity against Edge Addition / Removal
跳转到:6 Connectivity against Edge Addition / Removal- Setting: and are two undirected graphs, where is an additional edge connecting and . Then:
- For any : if and are connected in , then and are still connected in (adding an edge never destroys connectivity).
- If is connected to in , then: for any and , and are connected in iff and are connected in .
- If is not connected to in , then:
- for any : is connected to in , iff is connected to in , iff is connected to one of and in ;
- for any and : if and are not connected in but they are connected in , then , , and are all connected in .
7 Trees
跳转到:7 Trees7.1 Definition and basic properties
跳转到:7.1 Definition and basic properties- Tree: a tree is a connected (nonempty) undirected graph without simple circuits.
- Adding an edge: if adding an edge between vertices of a tree, the new graph will have a simple circuit.
- Removing an edge: if removing an edge from a tree, the new graph will be unconnected.
- Leaf (in an unrooted tree): a vertex is a leaf in a tree if its degree is .
- If a tree has at least two vertices, then it has at least one leaf; moreover it has at least two leaves.
- Edge count: a tree with vertices has edges.
- An undirected graph with no simple circuit is a tree if adding an arbitrary edge between vertices of the graph generates a simple circuit in the new graph.
- A connected undirected graph is a tree if removing any edge makes the new graph disconnected.
7.2 Equivalent characterizations of trees
跳转到:7.2 Equivalent characterizations of treesAll statements below about a finite undirected graph are equivalent:
- is a tree, i.e. is connected but contains no simple circuits.
- is connected and .
- contains no simple circuits and .
- is connected, but every edge in is a cut edge.
- contains no simple circuits, and adding any edge between vertices of generates a simple circuit.
- There is a unique simple path between any two of 's vertices.
8 Spanning Trees and Minimum Spanning Trees
跳转到:8 Spanning Trees and Minimum Spanning Trees8.1 Spanning trees
跳转到:8.1 Spanning trees- Spanning tree: a spanning tree of an undirected graph is a subgraph of that is a tree containing every vertex of .
- Existence: an undirected graph is connected if and only if it has a spanning tree.
- Proof:
- () If a spanning tree exists, then there is a path in the spanning tree between any two vertices, so the graph is connected.
- () Suppose is connected. If contains a simple circuit, remove one edge from the simple circuit, generating ; must still be connected. Repeat this process to construct ; the number of edges keeps decreasing, so there must be a natural number such that the number of vertices of is one more than its edges — that must be a tree.
8.2 Weighted graphs and minimum spanning trees
跳转到:8.2 Weighted graphs and minimum spanning trees- Weighted undirected graph: a graph with a function that assigns to each edge a (real) number.
- Minimum spanning tree: for a connected weighted graph , a minimum spanning tree of is a spanning tree whose sum of all weights in the tree is the minimum among all spanning trees.
8.3 Prim's Algorithm
跳转到:8.3 Prim's Algorithm- Construct a minimum spanning tree of a finite connected weighted graph according to the following steps:
- Choose the initial tree as an arbitrary singleton vertex with no edges.
- Construct from by adding an edge with minimum weight among all remaining edges satisfying that the graph added with is a tree.
- Finally is a minimum spanning tree.
- Key step — find such that:
- connects two vertices and , one of which (suppose it is ) is in and the other () is in ;
- if there are more than one minimum weighted edges, choose an arbitrary one;
- where and .
- Correctness proof: by induction on that there exists a minimum spanning tree such that is a subgraph of .
- When : choose an arbitrary minimum spanning tree as .
- When : if there exists a minimum spanning tree such that is a subgraph of , then must be itself — done.
- Induction step: assume there exists a minimum spanning tree such that is a subgraph of ; show there also exists a minimum spanning tree (maybe different from ) such that is a subgraph of it.
- Choose an arbitrary minimum spanning tree such that is a subgraph of . If is a subgraph of , we are done.
- Otherwise (edge exchange): is not an edge in . Because is a spanning tree, there is a path in between and . On this path, there must be an edge leaving ( connects a vertex in and a vertex in ) — otherwise there would be a path in between and , which contradicts the fact that is a tree.
- Because of the choice of : . On the other hand, is a tree; because is a minimum spanning tree: .
- Thus, changing to in gives another minimum spanning tree containing as a subgraph.
8.4 Kruskal's Algorithm
跳转到:8.4 Kruskal's Algorithm- Construct a minimum spanning tree of a finite connected weighted graph according to the following steps:
- Choose the initial graph where .
- Construct from by adding an edge with minimum weight among all remaining edges satisfying that the graph added with has no simple circuit. (If more than one edge has minimum weight, pick an arbitrary one.)
- Finally, is a minimum spanning tree.
- Here, where .
- Correctness proof's main idea: is "necessary" — assume it connects and ; all edges with less weight than are not enough to connect and , or else there will be a simple circuit in the new graph.
- Formal proof: by induction on that there exists a minimum spanning tree such that is a subgraph of .
9 Rooted Trees
跳转到:9 Rooted Trees9.1 Basic definitions
跳转到:9.1 Basic definitions- Rooted tree: a rooted tree is a tree with a designated vertex (as the root).
- Level and height: in a rooted tree with root : the level of a vertex is the length of the unique simple path from to ; the height of the tree is the maximal level of its vertices.
- Parent and child: the parent of a vertex is the unique vertex such that and this edge appears on the unique simple path between and ; is called a child of .
- Siblings: vertices are siblings if they have the same parent.
- Ancestors and descendants: the ancestors of a vertex are the vertices on the simple path from to , excluding but including ; the descendants of a vertex are all vertices that have as one of their ancestors.
9.2 Structural theorems
跳转到:9.2 Structural theorems- Ancestor transitivity: in a rooted tree , if is an ancestor of and is an ancestor of , then is also an ancestor of .
- Proof sketch: let the simple path from to the root be and the one from to the root be . By definition for some and for some . Then is also a simple path from to the root, so by uniqueness and . Hence with , i.e. is 's ancestor.
- Descendant transitivity: if is a descendant of and is a descendant of , then is also a descendant of .
- Path extension lemma: in a rooted tree , if is the parent of and is the simple path from to the root, then is the simple path from to the root.
- Proof sketch: let be the simple path from to the root; by definition , so is the simple path from to the root, i.e. and .
- Ancestors as parent-chains:
- if is 's ancestor in , then there exist s.t. , , and is 's parent, is 's parent, etc.;
- conversely, if satisfy , and is 's parent, is 's parent, etc., then is 's ancestor in .
- Paths inside a subtree: in a rooted tree , if is a descendant of , then the unique simple path from to only passes through 's descendants and .
- Proof sketch: the simple path from to the root is with for some , so the simple path from to is ; for any with , is a subpath and hence the unique simple path from to the root; since is on this path, is a descendant of .
- Corollary: in a rooted tree , if and are both 's descendants, the unique simple path from to only passes through 's descendants and .
9.3 Leaves, subtrees, m-ary trees
跳转到:9.3 Leaves, subtrees, m-ary trees- Leaf / internal vertex (rooted-tree context): in a rooted tree, a vertex is a leaf if it has no children; otherwise it is an internal vertex.
- Note the two different leaf notions in this course: in an unrooted tree a leaf is a vertex of degree ; in a rooted tree a leaf is a vertex with no children.
- Subtree: the subtree at a vertex is the induced subgraph of the vertex set consisting of the vertex (as its root) and all the descendants of .
- For any rooted tree and , the subtree at vertex is a tree.
- -ary trees( 叉树): a rooted tree is -ary if every internal vertex has at most children; is binary if it is -ary.
- Leaf bound: an -ary tree of height has at most leaves.
10 Depth-First Search(深度优先搜索)
跳转到:10 Depth-First Search(深度优先搜索)10.1 The DFS procedure (informal)
跳转到:10.1 The DFS procedure (informal)- DFS algorithm:
- Step 1: Fix an arbitrary starting vertex.
- Step 2: Continuously augment a simple path until no edge is augmentable.
- Step 3: Trace back to the deepest vertex from which some edge is augmentable and go back to Step 2.
- Example graph used to illustrate DFS (11 vertices ; edges read off the figure): .
10.2 Describing a DFS process; tree edges and back edges
跳转到:10.2 Describing a DFS process; tree edges and back edges- To describe a DFS process: we can say the -th move is from vertex to vertex through edge as a forward / backward step; we can also say the -th forward move.
- Tree edge / back edge: in one DFS process, if there is a forward move through , then is called a tree edge; otherwise is called a back edge.
10.3 Formal definition of a DFS process
跳转到:10.3 Formal definition of a DFS processGiven an undirected graph and a start point , a DFS process (with steps) must satisfy the following conditions (assuming that the -th step is from to vertex through edge ):
- .
- If there exists and s.t. and connects and , then the -th move must be forward (i.e. go forward whenever an unvisited neighbour exists).
- If the -th move is a forward step, then (forward steps only visit new vertices).
- If the -th move is a backward step and , where and the -th step is forward, then and (a backward step retraces the forward edge that first entered the current vertex).
10.4 Properties of DFS
跳转到:10.4 Properties of DFS- DFS yields a spanning tree: all tree edges of a DFS process of a connected undirected graph form a spanning tree of .
- Proof scratch: 1) all vertices appear — if did not, we could construct a counterexample from a path connecting and ; 2) this subgraph is a tree — by induction over the steps, the subgraph with and is a tree, proved by case analysis on whether the -th step is forward or backward.
- Usually, we treat this tree as a rooted tree (the starting vertex is the root).
- A forward step is from a vertex to one of its children (in the DFS tree).
- Every vertex appears as a forward step's terminal exactly once in a DFS process of a connected undirected graph starting from .
- Visited-vertices invariant: for a connected undirected graph and a DFS process of with steps (-th step from to through ) and every , the set of "visited vertices" can be divided into three categories:
- the starting vertex;
- the vertices which appear as exactly one forward step's termination and as no backward step's starting point in the first steps;
- the vertices which appear as exactly one forward step's termination and as exactly one backward step's starting point in the first steps.
- Moreover, one simple path from to satisfies the following properties (proof by induction over ):
- it contains only forward edges: , where ;
- it passes through vertices ;
- are exactly all vertices in the first two categories above.
- Every vertex appears as a backward step's starting point exactly once in a DFS process of a connected undirected graph starting from .
- A DFS process of a connected undirected graph with contains forward steps and backward steps.
- Between two visits of : if is a connected undirected graph and a DFS process of contains steps with the -th step from to through , and with , then is 's descendant or itself for every .
- Back edge theorem: a back edge is always from a vertex to one of its ancestors, one of its descendants, or itself.
- Proof: consider an edge from to . If one of them is the root, the statement is obviously true. Otherwise, consider the backward steps leaving and leaving ; suppose the backward step leaving is earlier. Then, right at the time of leaving , must be visited (or else a forward step should happen). Since a backward step from had not yet happened, must be 's ancestor.
10.5 Tarjan's Algorithm for Finding Bridges
跳转到:10.5 Tarjan's Algorithm for Finding BridgesTarjan_Bridge(u, e0): time = time + 1; dfn(u) = time; low(u) = time; for every e ≠ e0 which is incident with u and another vertex v: if dfn(v) is uninitialized, then recursively run Tarjan_Bridge(v, e); low(u) = min(low(u), low(v)); if (low(v) = dfn(v)) then the edge connecting u and v is a bridge; else low(u) = min(low(u), dfn(v));- The recursion excludes the entering edge itself when scanning the edges incident with ; records the visiting time of , and is updated by children's values (after recursive calls) and by of already-visited neighbours; the bridge test is .